package scipy

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type tag = [
  1. | `MatrixPowerOperator
]
type t = [ `MatrixPowerOperator | `Object ] Obj.t
val of_pyobject : Py.Object.t -> t
val to_pyobject : [> tag ] Obj.t -> Py.Object.t
val create : ?kwargs:(string * Py.Object.t) list -> Py.Object.t list -> t

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 ``_matvec`` and ``_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 ``_matvec`` automatically implements ``_matmat`` (using a naive algorithm) and vice-versa.

Optionally, a subclass may implement ``_rmatvec`` or ``_adjoint`` to implement the Hermitian adjoint (conjugate transpose). As with ``_matvec`` and ``_matmat``, implementing either ``_rmatvec`` or ``_adjoint`` implements the other automatically. Implementing ``_adjoint`` is preferable; ``_rmatvec`` is mostly there for backwards compatibility.

Parameters ---------- shape : tuple Matrix dimensions (M, N). matvec : callable f(v) Returns returns A * v. rmatvec : callable f(v) Returns A^H * v, where A^H is the conjugate transpose of A. matmat : callable f(V) Returns A * V, where V is a dense matrix with dimensions (N, K). dtype : dtype Data type of the matrix. rmatmat : callable f(V) Returns A^H * V, where V is a dense matrix with dimensions (M, K).

Attributes ---------- args : tuple For linear operators describing products etc. of other linear operators, the operands of the binary operation. ndim : int Number of dimensions (this is always 2)

See Also -------- aslinearoperator : Construct LinearOperators

Notes ----- 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 <https://pylops.readthedocs.io>`_.

Examples -------- >>> import numpy as np >>> from scipy.sparse.linalg import LinearOperator >>> def mv(v): ... return np.array(2*v[0], 3*v[1]) ... >>> 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.)

val adjoint : [> tag ] Obj.t -> Py.Object.t

Hermitian adjoint.

Returns the Hermitian adjoint of self, aka the Hermitian conjugate or Hermitian transpose. For a complex matrix, the Hermitian adjoint is equal to the conjugate transpose.

Can be abbreviated self.H instead of self.adjoint().

Returns ------- A_H : LinearOperator Hermitian adjoint of self.

val dot : x:[> `Ndarray ] Np.Obj.t -> [> tag ] Obj.t -> [ `ArrayLike | `Ndarray | `Object ] Np.Obj.t

Matrix-matrix or matrix-vector multiplication.

Parameters ---------- x : array_like 1-d or 2-d array, representing a vector or matrix.

Returns ------- Ax : array 1-d or 2-d array (depending on the shape of x) that represents the result of applying this linear operator on x.

val matmat : x:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

Matrix-matrix multiplication.

Performs the operation y=A*X where A is an MxN linear operator and X dense N*K matrix or ndarray.

Parameters ---------- X : matrix, ndarray An array with shape (N,K).

Returns ------- Y : matrix, ndarray A matrix or ndarray with shape (M,K) depending on the type of the X argument.

Notes ----- This matmat wraps any user-specified matmat routine or overridden _matmat method to ensure that y has the correct type.

val matvec : x:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

Matrix-vector multiplication.

Performs the operation y=A*x where A is an MxN linear operator and x is a column vector or 1-d array.

Parameters ---------- x : matrix, ndarray An array with shape (N,) or (N,1).

Returns ------- y : matrix, ndarray A matrix or ndarray with shape (M,) or (M,1) depending on the type and shape of the x argument.

Notes ----- This matvec wraps the user-specified matvec routine or overridden _matvec method to ensure that y has the correct shape and type.

val rmatmat : x:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

Adjoint matrix-matrix multiplication.

Performs the operation y = A^H * x where A is an MxN linear operator and x is a column vector or 1-d array, or 2-d array. The default implementation defers to the adjoint.

Parameters ---------- X : matrix, ndarray A matrix or 2D array.

Returns ------- Y : matrix, ndarray A matrix or 2D array depending on the type of the input.

Notes ----- This rmatmat wraps the user-specified rmatmat routine.

val rmatvec : x:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

Adjoint matrix-vector multiplication.

Performs the operation y = A^H * x where A is an MxN linear operator and x is a column vector or 1-d array.

Parameters ---------- x : matrix, ndarray An array with shape (M,) or (M,1).

Returns ------- y : matrix, ndarray A matrix or ndarray with shape (N,) or (N,1) depending on the type and shape of the x argument.

Notes ----- This rmatvec wraps the user-specified rmatvec routine or overridden _rmatvec method to ensure that y has the correct shape and type.

val transpose : [> tag ] Obj.t -> Py.Object.t

Transpose this linear operator.

Returns a LinearOperator that represents the transpose of this one. Can be abbreviated self.T instead of self.transpose().

val to_string : t -> string

Print the object to a human-readable representation.

val show : t -> string

Print the object to a human-readable representation.

val pp : Stdlib.Format.formatter -> t -> unit

Pretty-print the object to a formatter.