Common interface for performing matrix vector products
Many iterative methods (e.g. cg, gmres) do not need to know the individual entries of a matrix to solve a linear system A*x=b. Such solvers only require the computation of matrix vector products, A*v where v is a dense vector. This class serves as an abstract interface between iterative solvers and matrix-like objects.
To construct a concrete LinearOperator, either pass appropriate callables to the constructor of this class, or subclass it.
A subclass must implement either one of the methods
_matmat, and the attributes/properties
shape(pair of integers) and
dtype(may be None). It may call the
__init__on this class to have these attributes validated. Implementing
_matmat(using a naive algorithm) and vice-versa.
Optionally, a subclass may implement
_adjointto implement the Hermitian adjoint (conjugate transpose). As with
_matmat, implementing either
_adjointimplements the other automatically. Implementing
_rmatvecis mostly there for backwards compatibility.
Matrix dimensions (M, N).
- matveccallable f(v)
Returns returns A * v.
- rmatveccallable f(v)
Returns A^H * v, where A^H is the conjugate transpose of A.
- matmatcallable f(V)
Returns A * V, where V is a dense matrix with dimensions (N, K).
Data type of the matrix.
- rmatmatcallable f(V)
Returns A^H * V, where V is a dense matrix with dimensions (M, K).
The user-defined matvec() function must properly handle the case where v has shape (N,) as well as the (N,1) case. The shape of the return type is handled internally by LinearOperator.
LinearOperator instances can also be multiplied, added with each other and exponentiated, all lazily: the result of these operations is always a new, composite LinearOperator, that defers linear operations to the original operators and combines the results.
More details regarding how to subclass a LinearOperator and several examples of concrete LinearOperator instances can be found in the external project PyLops.
>>> import numpy as np >>> from scipy.sparse.linalg import LinearOperator >>> def mv(v): ... return np.array([2*v, 3*v]) ... >>> A = LinearOperator((2,2), matvec=mv) >>> A <2x2 _CustomLinearOperator with dtype=float64> >>> A.matvec(np.ones(2)) array([ 2., 3.]) >>> A * np.ones(2) array([ 2., 3.])
For linear operators describing products etc. of other linear operators, the operands of the binary operation.
Number of dimensions (this is always 2)
Call self as a function.
Matrix-matrix or matrix-vector multiplication.
Adjoint matrix-matrix multiplication.
Adjoint matrix-vector multiplication.
Transpose this linear operator.