fips.linalg.as_linear_operator#
- fips.linalg.as_linear_operator(x)[source]#
Return x as the form that fits how it is stored.
- Parameters:
x (
LinearOperator|spmatrix|sparray|ArrayLike) – What to wrap. A form comes back as it is; an array or a sparse matrix is copied, and the form’s copy is read-only.- Returns:
A
DiagonalOperatorfor a square sparse matrix that stores entries on its diagonal only, aSparseOperatorfor any other sparse matrix, and aDenseOperatorfor an array.- Return type:
- Raises:
ValueError – If x is not 2D. A diagonal given as its values is a
DiagonalOperator.
Examples
>>> import numpy as np >>> import scipy.sparse as sp >>> from fips.linalg import as_linear_operator >>> type(as_linear_operator(np.eye(3))).__name__ 'DenseOperator' >>> type(as_linear_operator(sp.eye(3))).__name__ 'DiagonalOperator'