Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Mise en oeuvre d'IHM
avec Qt et PySide6
Voir le programme détaillé
Module « scipy.sparse.linalg »

Classe « LinearOperator »

Informations générales

Héritage

builtins.object
    LinearOperator

Définition

class LinearOperator(builtins.object):

help(LinearOperator)

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.

It is highly recommended to explicitly specify the `dtype`, otherwise
it is determined automatically at the cost of a single matvec application
on `int8` zero vector using the promoted `dtype` of the output.
Python `int` could be difficult to automatically cast to numpy integers
in the definition of the `matvec` so the determination may be inaccurate.
It is assumed that `matmat`, `rmatvec`, and `rmatmat` would result in
the same dtype of the output given an `int8` input as `matvec`.

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=int8>
>>> A.matvec(np.ones(2))
array([ 2.,  3.])
>>> A @ np.ones(2)
array([ 2.,  3.])

Constructeur(s)

Signature du constructeur Description
__new__(cls, *args, **kwargs)
__init__(self, dtype, shape) Initialize this LinearOperator. [extrait de __init__.__doc__]

Liste des attributs statiques

Nom de l'attribut Valeur
ndim2

Liste des propriétés

Nom de la propriétéDescription
HHermitian adjoint. [extrait de H.__doc__]
TTranspose this linear operator. [extrait de T.__doc__]

Liste des opérateurs

Signature de l'opérateur Description
__add__(self, x)
__matmul__(self, other)
__mul__(self, x)
__neg__(self)
__pow__(self, p)
__rmul__(self, x)
__sub__(self, x)
__truediv__(self, other)

Opérateurs hérités de la classe object

__eq__, __ge__, __gt__, __le__, __lt__, __ne__

Liste des méthodes

Toutes les méthodes Méthodes d'instance Méthodes statiques Méthodes dépréciées
Signature de la méthodeDescription
__call__(self, x)
__repr__(self)
__rmatmul__(self, other)
adjoint(self) Hermitian adjoint. [extrait de adjoint.__doc__]
dot(self, x) Matrix-matrix or matrix-vector multiplication. [extrait de dot.__doc__]
matmat(self, X) Matrix-matrix multiplication. [extrait de matmat.__doc__]
matvec(self, x) Matrix-vector multiplication. [extrait de matvec.__doc__]
rmatmat(self, X) Adjoint matrix-matrix multiplication. [extrait de rmatmat.__doc__]
rmatvec(self, x) Adjoint matrix-vector multiplication. [extrait de rmatvec.__doc__]
transpose(self) Transpose this linear operator. [extrait de transpose.__doc__]

Méthodes héritées de la classe object

__delattr__, __dir__, __format__, __getattribute__, __getstate__, __hash__, __init_subclass__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Vous êtes un professionnel et vous avez besoin d'une formation ? Coder avec une
Intelligence Artificielle
Voir le programme détaillé