fips.linalg.SparseOperator#
- class fips.linalg.SparseOperator(matrix)[source]#
Bases:
LinearOperatorA matrix held as a SciPy sparse matrix.
- Parameters:
matrix (
spmatrix|sparray) – The matrix. It is copied, as a CSR array (CSC for a CSC input), and the copy is read-only: changing matrix afterwards leaves the form as it was.- Raises:
TypeError – If matrix is not a SciPy sparse matrix.
Examples
A product of sparse forms stays sparse while at most a quarter of its entries are stored, and is dense past that:
>>> import scipy.sparse as sp >>> from fips.linalg import SparseOperator >>> A = SparseOperator(sp.diags([4.0, 3.0, 2.0, 2.0, 1.0, 1.0], format="csr")) >>> A.diagonal() array([4., 3., 2., 2., 1., 1.]) >>> type(A @ A).__name__ 'SparseOperator' >>> B = SparseOperator(sp.csr_matrix([[4.0, 1.0], [1.0, 3.0]])) >>> type(B @ B).__name__ 'DenseOperator'
Attributes
The matrix, as a SciPy sparse array whose arrays are read-only. |
Methods
|
Return the form as a dense NumPy array. |
|
Return the main diagonal, read from the stored entries. |
|
Return the log-determinant from a symmetric sparse LU factorization. |
|
Solve |
Inherited
From LinearOperator: dot, sqrt, trace