Package linear_operators :: Module interface :: Class LinearOperator
[hide private]
[frames] | no frames]

Class LinearOperator

source code

object --+
         |
        LinearOperator
Known Subclasses:

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.

Parameters
----------
shape : tuple
    Matrix dimensions (M,N)
matvec : callable f(v)
    Returns returns A * v.

Optional Parameters
-------------------
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).
rmatmat : callable f(V)
    Returns A^H * V, where V is a dense matrix with dimensions (N,K).
dtype : dtype
    Data type of the matrix.

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.

Examples
--------
>>> from scipy.sparse.linalg import LinearOperator
>>> from scipy import *
>>> def mv(v):
...     return array([ 2*v[0], 3*v[1]])
...
>>> A = LinearOperator( (2,2), matvec=mv, rmatvec=mv)
>>> A
<2x2 LinearOperator with unspecified dtype>
>>> A.matvec( ones(2) )
array([ 2.,  3.])
>>> A * ones(2)
array([ 2.,  3.])
>>> A.dense()
array([[ 2.,  0.],
       [ 0.,  3.]])
>>> (2 * A.T * A + 1) * ones(2)
array([  9.,  19.])

Instance Methods [hide private]
 
__init__(self, shape, matvec, rmatvec=None, matmat=None, rmatmat=None, dtypein=None, dtypeout=None, dtype=<type 'numpy.float64'>)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
_matmat(self, X)
Default matrix-matrix multiplication handler.
source code
 
matvec(self, x)
Matrix-vector multiplication
source code
 
matmat(self, X)
Matrix-matrix multiplication
source code
 
__mul__(self, x) source code
 
__add__(self, A) source code
 
__neg__(self) source code
 
__sub__(self, x) source code
 
__rmul__(self, x) source code
 
__radd__(self, x) source code
 
__rsub__(self, x) source code
 
__imul__(self, x) source code
 
__iadd__(self, x) source code
 
__isub__(self, x) source code
 
__pow__(self, k) source code
 
__repr__(self)
repr(x)
source code
 
todense(self) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]
  T

Inherited from object: __class__

Method Details [hide private]

__init__(self, shape, matvec, rmatvec=None, matmat=None, rmatmat=None, dtypein=None, dtypeout=None, dtype=<type 'numpy.float64'>)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

_matmat(self, X)

source code 

Default matrix-matrix multiplication handler. Falls back on the user-defined matvec() routine, which is always provided.

matvec(self, x)

source code 
Matrix-vector multiplication

Performs the operation y=A*x where A is an MxN linear
operator and x is a column vector or rank-1 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 to ensure that
y has the correct shape and type.

matmat(self, X)

source code 
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 to ensure that
y has the correct type.

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

Property Details [hide private]

T

Get Method:
unreachable.T(self)