Apply dense matrix along any axis of an array.
(matrix, array, axis, out=None)
| 102 | |
| 103 | |
| 104 | def 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 | |
| 132 | def splu_inverse(matrix, permc_spec="NATURAL", **kw): |
no test coverage detected