ND matrix tensor multiplication

Former-commit-id: b24a08cb61ccac2464bfe9d904fa973cab7596b1
This commit is contained in:
Marek Nečada 2016-08-09 15:40:36 +03:00
parent 8fb938961f
commit bd0e7e7257
1 changed files with 10 additions and 0 deletions

View File

@ -1050,6 +1050,16 @@ def apply_matrix_left(matrix, tensor, axis):
tmp = np.tensordot(matrix, tensor, axes=(-1,axis)) tmp = np.tensordot(matrix, tensor, axes=(-1,axis))
return np.moveaxis(tmp, 0, axis) return np.moveaxis(tmp, 0, axis)
def apply_ndmatrix_left(matrix,tensor,axes):
"""
Generalized apply_matrix_left, the matrix can have more (2N) abstract dimensions,
like M[i,j,k,...z,i,j,k,...,z]. N axes have to be specified in a tuple, corresponding
to the axes 0,1,...N-1 of the matrix
"""
N = len(axes)
matrix = np.tensordot(matrix, tensor, axes=([-N+axn for axn in range(N)],axes))
matrix = np.moveaxis(matrix, range(N), axes)
return matrix
#################### ####################
# Array simulations # Array simulations