MCPcopy Create free account
hub / github.com/DedalusProject/dedalus / apply_dense

Function apply_dense

dedalus/tools/array.py:104–129  ·  view source on GitHub ↗

Apply dense matrix along any axis of an array.

(matrix, array, axis, out=None)

Source from the content-addressed store, hash-verified

102
103
104def apply_dense(matrix, array, axis, out=None):
105 """Apply dense matrix along any axis of an array."""
106 dim = array.ndim
107 # Resolve wraparound axis
108 axis = axis % dim
109 # Move axis to 0
110 if axis != 0:
111 array = move_single_axis(array, axis, 0) # May allocate copy
112 # Flatten later axes
113 if dim > 2:
114 array_shape = array.shape
115 array = array.reshape((array_shape[0], -1)) # May allocate copy
116 # Apply matmul
117 temp = np.matmul(matrix, array) # Allocates temp
118 # Unflatten later axes
119 if dim > 2:
120 temp = temp.reshape((temp.shape[0],) + array_shape[1:]) # View
121 # Move axis back from 0
122 if axis != 0:
123 temp = move_single_axis(temp, 0, axis) # View
124 # Return
125 if out is None:
126 return temp
127 else:
128 out[:] = temp # Copy
129 return out
130
131
132def splu_inverse(matrix, permc_spec="NATURAL", **kw):

Callers 3

apply_matrixFunction · 0.85
forwardMethod · 0.85
backwardMethod · 0.85

Calls 1

move_single_axisFunction · 0.85

Tested by

no test coverage detected