Solve upper triangular sparse matrix along any axis of an array. Matrix assumed to be nonzero on the diagonals.
(matrix, rhs, axis, out=None, check_shapes=False, num_threads=1)
| 204 | |
| 205 | |
| 206 | def solve_upper_sparse(matrix, rhs, axis, out=None, check_shapes=False, num_threads=1): |
| 207 | """ |
| 208 | Solve upper triangular sparse matrix along any axis of an array. |
| 209 | Matrix assumed to be nonzero on the diagonals. |
| 210 | """ |
| 211 | # Check matrix |
| 212 | if not isinstance(matrix, sparse.csr_matrix): |
| 213 | raise ValueError("Matrix must be in CSR format.") |
| 214 | if not matrix._has_canonical_format: # avoid property hook (without underscore) |
| 215 | matrix.sum_duplicates() |
| 216 | # Setup output = rhs |
| 217 | if out is None: |
| 218 | out = np.copy(rhs) |
| 219 | elif out is not rhs: |
| 220 | np.copyto(out, rhs) |
| 221 | # Promote datatypes |
| 222 | matrix_data = matrix.data |
| 223 | if matrix_data.dtype != rhs.dtype: |
| 224 | matrix_data = matrix_data.astype(rhs.dtype) |
| 225 | # Check shapes |
| 226 | if check_shapes: |
| 227 | if not (0 <= axis < rhs.ndim): |
| 228 | raise ValueError("Axis out of bounds.") |
| 229 | if not (matrix.shape[0] == matrix.shape[1] == rhs.shape[axis]): |
| 230 | raise ValueError("Matrix shape mismatch.") |
| 231 | # Call cython routine |
| 232 | cython_linalg.solve_upper_csr(matrix.indptr, matrix.indices, matrix_data, out, axis, num_threads) |
| 233 | |
| 234 | |
| 235 | def csr_matvec(A_csr, x_vec, out_vec): |
no test coverage detected