
    Cpj                        S r SSKrSSKrSSKrSSKrSSKJr  SSKJ	r
  SSKJrJrJrJrJrJrJrJrJrJr  SSKJr  SSKJrJrJrJr  SS	/r\" 5        " S
 S5      5       r " S S\5      r " S S\5      r  " S S\5      r!S!S jr" " S S\5      r# " S S\5      r$ " S S\5      r% " S S\5      r& " S S\5      r' " S S\'5      r( " S S\5      r)\" 5       S  5       r*g)"aU  Abstract linear algebra library.

This module defines a class hierarchy that implements a kind of "lazy"
matrix representation, called the ``LinearOperator``. It can be used to do
linear algebra with extremely large sparse or structured matrices, without
representing those explicitly in memory. Such matrices can be added,
multiplied, transposed, etc.

As a motivating example, suppose you want have a matrix where almost all of
the elements have the value one. The standard sparse matrix representation
skips the storage of zeros, but not ones. By contrast, a LinearOperator is
able to represent such matrices efficiently. First, we need a compact way to
represent an all-ones matrix::

    >>> import numpy as np
    >>> from scipy.sparse.linalg._interface import LinearOperator
    >>> class Ones(LinearOperator):
    ...     def __init__(self, shape):
    ...         super().__init__(dtype=None, shape=shape)
    ...     def _matvec(self, x):
    ...         return np.repeat(x.sum(), self.shape[0])

Instances of this class emulate ``np.ones(shape)``, but using a constant
amount of storage, independent of ``shape``. The ``_matvec`` method specifies
how this linear operator multiplies with (operates on) a vector. We can now
add this operator to a sparse matrix that stores only offsets from one::

    >>> from scipy.sparse.linalg._interface import aslinearoperator
    >>> from scipy.sparse import csr_array
    >>> offsets = csr_array([[1, 0, 2], [0, -1, 0], [0, 0, 3]])
    >>> A = aslinearoperator(offsets) + Ones(offsets.shape)
    >>> A.dot([1, 2, 3])
    array([13,  4, 15])

The result is the same as that given by its dense, explicitly-stored
counterpart::

    >>> (np.ones(A.shape, A.dtype) + offsets.toarray()).dot([1, 2, 3])
    array([13,  4, 15])

Several algorithms in the ``scipy.sparse`` library are able to operate on
``LinearOperator`` instances.
    N)sparse)array_api_extra)
SCIPY_ARRAY_API_asarrayarray_namespaceis_array_api_objis_pydata_sparse_array	np_compatxp_capabilitiesxp_copyxp_isscalarxp_result_type)issparse)asmatrixis_pydata_spmatrix	isintlikeisshapeLinearOperatoraslinearoperatorc                   f  ^  \ rS rSr% SrSr\" \R                  5      r	\\
S'   \\
S'   U 4S jrS+S jrS rS	 rS
 rS rS rS,S\4S jjrS rS rS rS,S\4S jjrS rS rS rS rS rS rS rS r S r!S r"S r#S r$S r%S  r&S! r'S" r(S# r)S$ r*\+S% 5       r,S& r-\+S' 5       r.S( r/S) r0S*r1U =r2$ )-r   G   a  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, optionally with additional batch dimensions at the front)
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.

The defined operator may have additional "batch" dimensions
prepended to the core shape, to represent a batch of 2-D operators;
see :ref:`linalg_batch` for details.

Parameters
----------
shape : tuple
    Matrix dimensions ``(..., M, N)``,
    where ``...`` represents any additional batch dimensions.
matvec : callable f(v)
    Applies ``A`` to ``v``, where ``v`` is a dense vector
    with shape ``(..., N)``.
rmatvec : callable f(v)
    Applies ``A^H`` to ``v``, where ``A^H`` is the conjugate transpose of ``A``,
    and ``v`` is a dense vector of shape ``(..., M)``.
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 ``A^H`` is the conjugate transpose of ``A``,
    and where ``V`` is a dense matrix with dimensions ``(..., M, K)``.
dtype : dtype
    Data type of the matrix or matrices.
xp : array_namespace, optional
    A namespace compatible with the array API standard for use in array operations.
    Default: ``numpy``.

Attributes
----------
args : tuple
    For linear operators describing products etc. of other linear
    operators, the operands of the binary operation.
ndim : int
    Number of dimensions (greater than 2 in the case of batch dimensions).
T : LinearOperator
    Transpose.
H : LinearOperator
    Hermitian adjoint.

Methods
-------
matvec
matmat
adjoint
transpose
rmatvec
rmatmat
dot
rdot
__mul__
__matmul__
__call__
__add__
__truediv__
__rmul__
__rmatmul__

See Also
--------
aslinearoperator : Construct a `LinearOperator`.

Notes
-----
The user-defined `matvec` function must properly handle the case
where ``v`` has shape ``(..., N)``.

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.
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 raised to integral powers, 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.])

N__class_getitem__ndimc                 .  > U [         L a  [        TU ]	  [        5      $ [        TU ]	  U 5      n[	        U5      R
                  [         R
                  :X  aA  [	        U5      R                  [         R                  :X  a  [        R                  " S[        SS9  U$ )NzMLinearOperator subclass should implement at least one of _matvec and _matmat.   )category
stacklevel)
r   super__new___CustomLinearOperatortype_matvec_matmatwarningswarnRuntimeWarning)clsargskwargsobj	__class__s       Z/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/scipy/sparse/linalg/_interface.pyr   LinearOperator.__new__   sy    . 7?#899'/#&C S	!!^%;%;;I%%)?)??<+ 	 J    c                 (   Uc  [         OUnUb  UR                  SUS9R                  n[        U5      n[	        U5      S:  a  [        SU< S35      e[        USS9(       d  [        SU< 35      eXl        X l        [	        U5      U l        X0l	        g)	zInitialize this LinearOperator.

To be called by subclasses. ``dtype`` may be None; ``shape`` should
be convertible to a length >=2 tuple.
Nr   dtyper   zinvalid shape z (must be at least 2-d)F)check_nd)
r
   emptyr1   tuplelen
ValueErrorr   shaper   _xp)selfr1   r7   xps       r,   __init__LinearOperator.__init__   s     *Y"HHQeH,22Eeu:>~eY6MNOOuu-~eY788

J	r.   c                 h    U R                   R                  5       nUS   R                  S5      US'   U$ )Nr8   r   )__dict__copyr3   r9   states     r,   __getstate__LinearOperator.__getstate__   s1    ""$U|))!,er.   c                 x    [        UR                  S5      5      U l        U R                  R	                  U5        g )Nr8   )r   popr8   r>   updater@   s     r,   __setstate__LinearOperator.__setstate__   s)    "599U#34U#r.   c                 T   U R                   cf  U R                  nUR                  U R                  S   UR                  S9n UR                  U R                  U5      5      nUR                   U l         gg! [        [        [        4 a    [        R                  " USS9U l          gf = f)a  Determine the dtype by executing `matvec` on an `int8` test vector.

In `np.promote_types` hierarchy, the type `int8` is the smallest,
so we call `matvec` on `int8` and use the promoted dtype of the output
to set the default `dtype` of the `LinearOperator`.
We assume that `matmat`, `rmatvec`, and `rmatmat` would result in
the same dtype of the output given an `int8` input as `matvec`.

Called from subclasses at the end of the __init__ routine.
Nr0   integral)r:   kind)r1   r8   zerosr7   int8asarraymatvecOverflowError	TypeErrorRuntimeErrorxpxdefault_dtype)r9   r:   vmatvec_vs       r,   _init_dtypeLinearOperator._init_dtype  s     ::BBrww7A,::dkk!n5 &^^
 
 "9l; G ..":F
Gs    A5 5/B'&B'c                    U R                   nUR                  [        UR                  S   5       Vs/ s H  o0R	                  USSS2U4   5      PM     snSS9$ s  snf )aQ  Default matrix-matrix multiplication handler.

If ``self`` is a linear operator of shape ``(..., M, N)``,
then this method will be called on a shape ``(..., N, K)`` array,
and should return a shape ``(..., M, K)`` array.

Falls back to `_matvec`, so defining that will
define matrix multiplication too (though in a very suboptimal way).
rJ   .Naxis)r8   stackranger7   r"   r9   Xr:   is       r,   r#   LinearOperator._matmat  s\     XX xx16qwwr{1CD1CA\\!CAI,'1CD2  
 	
Ds   "Ac                 `    U R                   nU R                  USUR                  4   5      S   $ )a4  Default matrix-vector multiplication handler.

If ``self`` is a linear operator of shape ``(..., M, N)``,
then this method will be called on a shape
``(..., N)`` array,
and should return a shape ``(..., M)`` array.

Falls back to `_matmat`, so defining that
will define matrix-vector multiplication as well.
..r   )r8   r#   newaxisr9   xr:   s      r,   r"   LinearOperator._matvec*  s.     XX||Ac2::o./77r.   adjointc                 B   U R                   n[        USUS9nU R                  Gt pEnU(       a  XV4OXe4u  px[        U[        R
                  5      (       aX  U(       a  U R                  U5      OU R                  U5      n	UR                  US4:X  a  U	R                  US5      n	[        U	5      $ Sn
SnUR                  US4:H  =n(       aq  U(       a  SOSnU(       a  SOS	nS
U SU SU S3n[        R                  " U[        [        R                  R                  [         5      4S9  UR                  X45      nO8UR"                  S:  a(  UR                  S   U:H  =n(       a  UR                  S S n
U(       d'  U(       d   SU SU SUR                   3n[%        U5      eU(       a  U R                  U5      OU R                  U5      n	[&        R(                  " XJ5      nU(       a  UR                  U	/ UQUP75      n	U	$ U(       a  UR                  U	/ UQUPSP75      n	U	$ )NTsubokr:       Fz	`rmatvec`z`matvec`z	`rmatmat`z`matmat`zCalling z  on 'column vectors' of shape `(za, 1)` was deprecated in SciPy 1.18.0 and will no longer be possible in SciPy 1.20.0. Please call z! instead for identical behaviour.)skip_file_prefixesrJ   z6Dimension mismatch: `x` must have a shape ending in `(z,)`, or shape `(z, 1)`. Given shape: )r8   r   r7   
isinstancenpmatrix_rmatvecr"   reshaper   r$   r%   FutureWarningospathdirname__file__r   r6   rT   broadcast_shapes)r9   rg   ri   r:   self_broadcast_dimsMN	inner_dim	outer_dimyx_broadcast_dims
row_vectorcolumn_vector	func_namematmat_func_namemsgbroadcasted_dimss                    r,   _shared_matvecLinearOperator._shared_matvec8  s   XXQdr*%)ZZ"	)0vqf	 a##$+a aAww9a.(IIi+A;,. 
GG	1~55=5'.JI.5{:9+ &K  /00QS  MM]8Q7S 

1l+AVVq[AGGBK9,DDjD wws|mK/	{ ;  !y* 
 S/! 'DMM!T\\!_//0CV

1< 0<)<=A  

1? 0?)?Q?@Ar.   c                 $    U R                  U5      $ )a'  Matrix-vector multiplication.

Applies ``A`` to `x`, where ``A`` is an ``M`` x ``N``
linear operator (or batch of linear operators)
and `x` is a row vector (or batch of such vectors).

Parameters
----------
x : {matrix, ndarray}
    An array with shape ``(..., N)`` representing a row vector
    (or batch of row vectors).

    .. versionadded:: 1.18.0
        A ``FutureWarning`` is emitted for column vector input of shape
        ``(N, 1)``, for which an array with shape ``(M, 1)`` is returned.
        `matmat` can be called instead for identical behaviour on such input.

Returns
-------
y : {matrix, ndarray}
    An array with shape ``(..., M)``.

Notes
-----
This method wraps the user-specified ``matvec`` routine or overridden
``_matvec`` method to ensure that `y` has the correct shape and type.
r   r9   rg   s     r,   rP   LinearOperator.matveck  s    8 ""1%%r.   c                 "    U R                  USS9$ )a|  Adjoint matrix-vector multiplication.

Applies ``A^H`` to `x`, where ``A`` is an
``M`` x ``N`` linear operator (or batch of linear operators)
and `x` is a row vector (or batch of such vectors).

Parameters
----------
x : {matrix, ndarray}
    An array with shape ``(..., M)`` representing a row vector
    (or batch of row vectors),
    or an array with shape ``(M, 1)`` representing a column vector.

    .. versionadded:: 1.18.0
        A ``FutureWarning`` is now emitted for column vector input of shape
        ``(M, 1)``, for which an array with shape ``(N, 1)`` is returned.
        `rmatmat` can be called instead for identical behaviour on such input.

Returns
-------
y : {matrix, ndarray}
    An array with shape ``(..., N)``.

Notes
-----
This method wraps the user-specified ``rmatvec`` routine or overridden
``_rmatvec`` method to ensure that `y` has the correct shape and type.
Tri   r   r   s     r,   rmatvecLinearOperator.rmatvec  s    : ""1d"33r.   c                 `   [        U 5      R                  [        R                  :X  am  [        U S5      (       aV  [        U 5      R                  [        R                  :w  a/  U R
                  nU R	                  USUR                  4   5      S   $ [        eU R                  R                  U5      $ )zHDefault implementation of `_rmatvec`.
Defers to `_rmatmat` or `adjoint`._rmatmat.rd   )
r!   _adjointr   hasattrr   r8   re   NotImplementedErrorHr"   rf   s      r,   rs   LinearOperator._rmatvec  s     :."9"99 j))J''>+B+BBXX}}QsBJJ%78@@%%66>>!$$r.   c                    [        U5      (       d%  [        U5      (       d  [        USU R                  S9nUR                  S:  a  [        SUR                   S35      eUR                  S   U(       a  U R                  S   OU R                  S   :w  a%  [        SU R                   S	UR                   35      e U(       a  U R                  U5      OU R                  U5      n[        U[        R                  5      (       a  [        U5      nU$ ! [         a2  n[        U5      (       d  [        U5      (       a  [        S
5      Uee S nAff = f)NTrk   r   z-Expected at least 2-d ndarray or matrix, not z-drJ   zDimension mismatch: z, zMultipliying LinearOperator with a sparse matrix failed. Try wrapping the matrix with `aslinearoperator` first, or ensuring the operator's `matmat` function supports sparse input.)r   r   r   r8   r   r6   r7   r   r#   	ExceptionrR   rp   rq   rr   r   )r9   r`   ri   Yes        r,   _shared_matmatLinearOperator._shared_matmat  s   1!44$4884A66A:LQVVHTVWXX772;W4::b>$**R.I3DJJ<r!''KLL
	$+a aA a##A  	{{033.
  	s   ;)D 
E-EEc                 $    U R                  U5      $ )aI  Matrix-matrix multiplication.

Performs the operation ``A @ X`` where ``A`` is an ``M`` x ``N``
linear operator (or batch of linear operators)
and `X` is a dense ``N`` x ``K`` matrix
(or batch of dense matrices).

Parameters
----------
X : {matrix, ndarray}
    An array with shape ``(..., N, K)`` representing the dense matrix
    (or batch of dense matrices).

Returns
-------
Y : {matrix, ndarray}
    An array with shape ``(..., M, K)``.

Notes
-----
This method wraps any user-specified ``matmat`` routine or overridden
``_matmat`` method to ensure that `Y` has the correct type.
r   r9   r`   s     r,   matmatLinearOperator.matmat  s    0 ""1%%r.   c                 "    U R                  USS9$ )a  Adjoint matrix-matrix multiplication.

Performs the operation ``A^H @ X`` where ``A`` is an ``M`` x ``N``
linear operator (or batch of linear operators)
and `X` is a dense ``M`` x ``K`` matrix
(or batch of dense matrices).
The default implementation defers to the adjoint.

Parameters
----------
X : {matrix, ndarray}
    An array with shape ``(..., M, K)`` representing the dense matrix
    (or batch of dense matrices).

Returns
-------
Y : {matrix, ndarray}
    An array with shape ``(..., N, K)``.

Notes
-----
This method wraps any user-specified ``rmatmat`` routine or overridden
``_rmatmat`` method to ensure that `Y` has the correct type.

Tr   r   r   s     r,   rmatmatLinearOperator.rmatmat  s    4 ""1d"33r.   c                B   [        U 5      R                  [        R                  :X  aY  U R                  nUR	                  [        UR                  S   5       Vs/ s H  o0R                  USSS2U4   5      PM     snSS9$ U R                  R                  U5      $ s  snf )zGDefault implementation of `_rmatmat`; defers to `rmatvec` or `adjoint`.rJ   .Nr[   )
r!   r   r   r8   r]   r^   r7   rs   r   r#   r_   s       r,   r   LinearOperator._rmatmat	  s    :."9"99B 886;AGGBK6HI6Hqa|,6HIPR    66>>!$$ Js   "Bc                 
    X-  $ )z9Apply this linear operator.

Equivalent to `__matmul__`.
rn   r   s     r,   __call__LinearOperator.__call__  s    
 xr.   c                 $    U R                  U5      $ )zBMultiplication.

Used by the ``*`` operator. Equivalent to `dot`.
)dotr   s     r,   __mul__LinearOperator.__mul__  s    
 xx{r.   c                 h    [        U5      (       d  [        S5      e[        U SU-  U R                  S9$ )z;Scalar Division.

Returns a lazily scaled linear operator.
z.Can only divide a linear operator by a scalar.g      ?r:   )r   r6   _ScaledLinearOperatorr8   r9   others     r,   __truediv__LinearOperator.__truediv__$  s2    
 5!!MNN$T3;488DDr.   c                     [        USS 5      nUc#  [        XR                  R                  S5      SS9nX R                  :w  a  SU R                   SU 3n[	        U5      eg )Nr8   r   T)	sparse_okz2Mismatched array namespaces.Namespace for self is z, namespace for x is )getattrr   r8   r3   rR   )r9   rg   xp_xr   s       r,   _check_matching_namespace(LinearOperator._check_matching_namespace.  si    q%&<"1hhnnQ&74HD88))-
2GvO  C.  r.   c                    U R                  U5        [        U[        5      (       a  [        XU R                  S9$ [        U5      (       a  [        XU R                  S9$ [        U5      (       d+  [        U5      (       d  U R                  R                  U5      nU R                  S   nUR                  U4:H  nUR                  S:  =(       a    UR                  S   U:H  nU(       d'  U(       d   SU SU SUR                   3n[        U5      eU(       a  U R                  U5      $ U(       a  U R                  U5      $ g)	ax  Multi-purpose multiplication method.

Parameters
----------
x : array_like or `LinearOperator` or scalar
    Array-like input will be interpreted as a 1-D row vector or
    2-D matrix (or batch of matrices)
    depending on its shape. See the Returns section for details.

Returns
-------
Ax : array or `LinearOperator`
    - For `LinearOperator` input, operator composition is performed.

    - For scalar input, a lazily scaled operator is returned.

    - Otherwise, the input is expected to take the form of a dense
      1-D vector or 2-D matrix (or batch of matrices),
      interpreted as follows
      (where ``self`` is an ``M`` by ``N`` linear operator):

      - If `x` has shape ``(N,)``
        it is interpreted as a row vector
        and `matvec` is called.
      - If `x` has shape ``(..., N, K)`` for some
        integer ``K``, it is interpreted as a matrix
        (or batch of matrices if there are batch dimensions)
        and `matmat` is called.

See Also
--------
__mul__ : Equivalent method used by the ``*`` operator.
__matmul__ :
    Method used by the ``@`` operator which rejects scalar
    input before calling this method.

Notes
-----
To perform matrix-vector multiplication on batches of vectors,
use `matvec`.

For clarity, it is recommended to use the `matvec` or
`matmat` methods directly instead of this method
when interacting with dense vectors and matrices.

r   rJ   r   r   z6Dimension mismatch: array input `x` must have shape `(z,)` or a shape ending in `(z), K)` for some integer `K`. Given shape: N)r   rp   r   _ProductLinearOperatorr8   r   r   r   r   rO   r7   r   r6   rP   r   )r9   rg   r}   vectorrr   r   s         r,   r   LinearOperator.dot9  s   ^ 	&&q)a(()$dhh??^^(TXX>>A;;'9!'<'< HH$$Q'

2A WW_FVVq[5QWWR[A%5FfLQC P../S 1$$%GG9. 
 !o%{{1~%{{1~% r.   c                 Z    [        U5      (       a  [        S5      eU R                  U5      $ )zjMatrix Multiplication.

Used by the ``@`` operator.
Rejects scalar input.
Otherwise, equivalent to `dot`.
0Scalar operands are not allowed, use '*' instead)r   r6   r   r   s     r,   
__matmul__LinearOperator.__matmul__  s*     uOPP||E""r.   c                 Z    [        U5      (       a  [        S5      eU R                  U5      $ )zMatrix Multiplication from the right.

Used by the ``@`` operator from the right.
Rejects scalar input.
Otherwise, equivalent to `rdot`.
r   )r   r6   __rmul__r   s     r,   __rmatmul__LinearOperator.__rmatmul__  s*     uOPP}}U##r.   c                 $    U R                  U5      $ )zaMultiplication from the right.

Used by the ``*`` operator from the right. Equivalent to `rdot`.
)rdotr   s     r,   r   LinearOperator.__rmul__  s    
 yy|r.   c                   ^  T R                  U5        [        U[        5      (       a  [        UT T R                  S9$ [        U5      (       a  [        T UT R                  S9$ [        U5      (       d+  [        U5      (       d  T R                  R                  U5      nT R                  S   nUR                  U4:H  nUR                  S:  =(       a    UR                  S   U:H  nU(       d(  U(       d!  SU SU SUR                   S3n[        U5      eU 4S	 jnU(       a!  T R                  R                  U" U5      5      $ U(       a'  U" T R                  R                  U" U5      5      5      $ g
)a  Multi-purpose multiplication method from the right.

.. note ::

    This method returns ``x A``.
    To perform adjoint multiplication instead, use one of
    `rmatvec` or `rmatmat`, or take the adjoint first,
    like ``self.H.rdot(x)`` or ``x * self.H``.

Parameters
----------
x : array_like or `LinearOperator` or scalar
    Array-like input will be interpreted as a 1-D row vector or
    2-D matrix (or batch of matrices)
    depending on its shape. See the Returns section for details.

Returns
-------
xA : array or `LinearOperator`
    - For `LinearOperator` input, operator composition is performed.

    - For scalar input, a lazily scaled operator is returned.

    - Otherwise, the input is expected to take the form of a dense
      1-D vector or 2-D matrix (or batch of matrices),
      interpreted as follows
      (where ``self`` is an ``M`` by ``N`` linear operator):

      - If `x` has shape ``(M,)``
        it is interpreted as a row vector.
      - If `x` has shape ``(..., K, M)`` for some
        integer ``K``, it is interpreted as a matrix
        (or batch of matrices if there are batch dimensions).

See Also
--------
dot : Multi-purpose multiplication method from the left.
__rmul__ :
    Equivalent method, used by the ``*`` operator from the right.
__rmatmul__ :
    Method used by the ``@`` operator from the right
    which rejects scalar input before calling this method.
r   r   r   rJ   z*Dimension mismatch: `x` must have shape `(z,)` or a shape ending in `(K, z&)` for some integer `K`. Given shape: .c                    > U R                   ==S:X  a      U $ =S:X  a      U $   S:X  a  U R                  $  TR                  R                  U SS5      $ )Nr   rm   r   r   rJ   )r   Tr8   moveaxis)rg   r9   s    r,   mTLinearOperator.rdot.<locals>.mT  sO    ff     ss
#xx00B;;r.   N)r   rp   r   r   r8   r   r   r   r   rO   r7   r   r6   r   rP   r   )r9   rg   r|   r   rr   r   r   s   `      r,   r   LinearOperator.rdot  s9   X 	&&q)a(()!Tdhh??^^(qTXX>>A;;'9!'<'< HH$$Q'

2A WW_FVVq[5QWWR[A%5Ff@ D112 4$$%GG9A/ 
 !o%
< vv}}RU++$&&--1.// r.   c                 x    U R                  U5        [        U5      (       a  [        XU R                  S9$ [        $ Nr   )r   r   _PowerLinearOperatorr8   NotImplemented)r9   ps     r,   __pow__LinearOperator.__pow__  s0    &&q)q>>'DHH==!!r.   c                     U R                  U5        [        U[        5      (       a  [        XU R                  S9$ [
        $ )znLinear operator addition.

The input must be a `LinearOperator`.
A lazily summed linear operator is returned.
r   )r   rp   r   _SumLinearOperatorr8   r   r   s     r,   __add__LinearOperator.__add__  s6     	&&q)a((%d$((;;!!r.   c                 ,    [        U SU R                  S9$ )NrJ   r   )r   r8   r9   s    r,   __neg__LinearOperator.__neg__  s    $T2$((;;r.   c                 &    U R                  U* 5      $ N)r   r   s     r,   __sub__LinearOperator.__sub__  s    ||QBr.   c                     U R                   c  SnOS[        U R                   5      -   nSR                  S U R                   5       5      nSU SU R                  R
                   SU S3$ )	Nzunspecified dtypezdtype=rg   c              3   8   #    U  H  n[        U5      v   M     g 7fr   )str).0dims     r,   	<genexpr>*LinearOperator.__repr__.<locals>.<genexpr>  s     8ZcSZs   < z with >)r1   r   joinr7   r+   __name__)r9   dtr7   s      r,   __repr__LinearOperator.__repr__  sa    ::$BC

O+B8TZZ885'4>>2236"Q??r.   c                 "    U R                  5       $ )at  Hermitian adjoint.

Returns the Hermitian adjoint of this linear operator,
also known as the Hermitian
conjugate or Hermitian transpose. For a complex matrix, the
Hermitian adjoint is equal to the conjugate transpose.

Returns
-------
`LinearOperator`
    Hermitian adjoint of self.

See Also
--------
:attr:`~scipy.sparse.linalg.LinearOperator.H` : Equivalent attribute.
)r   r   s    r,   ri   LinearOperator.adjoint  s    " }}r.   c                 "    U R                  5       $ )zfHermitian adjoint.

See Also
--------
scipy.sparse.linalg.LinearOperator.adjoint : Equivalent method.
r   r   s    r,   r   LinearOperator.H/  s     ||~r.   c                 "    U R                  5       $ )zTranspose.

Returns
-------
`LinearOperator`
    Transpose of the linear operator.

See Also
--------
:attr:`~scipy.sparse.linalg.LinearOperator.T` : Equivalent attribute.
)
_transposer   s    r,   	transposeLinearOperator.transpose9  s       r.   c                 "    U R                  5       $ )z`Transpose.

See Also
--------
scipy.sparse.linalg.LinearOperator.transpose : Equivalent method.
)r   r   s    r,   r   LinearOperator.TG  s     ~~r.   c                 (    [        X R                  S9$ )zaDefault implementation of `_adjoint`.
Defers to adjoint functions, e.g. `_rmatvec` for `_matvec`.r   )_AdjointLinearOperatorr8   r   s    r,   r   LinearOperator._adjointQ  s     &dxx88r.   c                 (    [        X R                  S9$ )zXDefault implementation of `_transpose`.
For `_matvec`, defers to `_rmatvec` + `np.conj`.r   )_TransposedLinearOperatorr8   r   s    r,   r   LinearOperator._transposeV  s     )((;;r.   )r8   r1   r   r7   r   )F)3r   
__module____qualname____firstlineno____doc____array_ufunc__classmethodtypesGenericAliasr   __annotations__intr   r;   rB   rG   rX   r#   r"   boolr   rP   r   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ri   propertyr   r   r   r   r   __static_attributes____classcell__r+   s   @r,   r   r   G   s   |~ O &11C1C%D{D
I(*
$,*
(81 1f&<4>%  6&448%E	!L&\	#	$T0l"
"< @&  !    9
< <r.   c                   d   ^  \ rS rSrSr     S
U 4S jjrU 4S jrS rS rU 4S jr	S r
S	rU =r$ )r    i\  z>Linear operator defined in terms of user-specified operations.c                    > [         TU ]  XQU5        SU l        X l        X0l        X`l        X@l        U R                  5         g )Nrn   )r   r;   r(   "_CustomLinearOperator__matvec_impl#_CustomLinearOperator__rmatvec_impl#_CustomLinearOperator__rmatmat_impl"_CustomLinearOperator__matmat_implrX   )	r9   r7   rP   r   r   r1   r   r:   r+   s	           r,   r;   _CustomLinearOperator.__init___  s?     	r*	#%%#r.   c                 ^   > U R                   b  U R                  U5      $ [        TU ]	  U5      $ r   )r  r   r#   r9   r`   r+   s     r,   r#   _CustomLinearOperator._matmatt  s/    )%%a((7?1%%r.   c                 $    U R                  U5      $ r   )r  r   s     r,   r"   _CustomLinearOperator._matvecz  s    !!!$$r.   c                 X    U R                   nUc  [        S5      eU R                  U5      $ )Nzrmatvec is not defined)r  r   )r9   rg   funcs      r,   rs   _CustomLinearOperator._rmatvec}  s/    ""<%&>??""1%%r.   c                 ^   > U R                   b  U R                  U5      $ [        TU ]	  U5      $ r   )r  r   r   r  s     r,   r   _CustomLinearOperator._rmatmat  s0    *&&q))7#A&&r.   c           
          [        / U R                  S S QU R                  S   PU R                  S   P7U R                  U R                  U R                  U R
                  U R                  U R                  S9$ )Nr   rJ   )r7   rP   r   r   r   r1   r:   )r    r7   r  r  r  r  r1   r8   r   s    r,   r   _CustomLinearOperator._adjoint  sm    $DDJJsODTZZ^DTZZ^D&&&&&&&&**xx
 	
r.   )__matmat_impl__matvec_impl__rmatmat_impl__rmatvec_implr(   )NNNNN)r   r  r  r	  r
  r;   r#   r"   rs   r   r   r  r  r  s   @r,   r    r    \  s:    H *&%&'	
 	
r.   r    c                   H   ^  \ rS rSrSrS	U 4S jjrS rS rS rS r	Sr
U =r$ )
r  i  z$Adjoint of arbitrary Linear Operatorc                    > / UR                   S S QUR                   S   PUR                   S   P7n[        TU ]	  UR                  X25        Xl        U4U l        g Nr   rJ   r7   r   r;   r1   Ar(   r9   r1  r:   r7   r+   s       r,   r;   _AdjointLinearOperator.__init__  R    9!''#2,99QWWR[9%,D	r.   c                 8    U R                   R                  U5      $ r   )r1  rs   r   s     r,   r"   _AdjointLinearOperator._matvec      vvq!!r.   c                 8    U R                   R                  U5      $ r   )r1  r"   r   s     r,   rs   _AdjointLinearOperator._rmatvec      vv~~a  r.   c                 8    U R                   R                  U5      $ r   )r1  r   r   s     r,   r#   _AdjointLinearOperator._matmat  r7  r.   c                 8    U R                   R                  U5      $ r   )r1  r#   r   s     r,   r   _AdjointLinearOperator._rmatmat  r:  r.   r1  r(   r   r   r  r  r	  r
  r;   r"   rs   r#   r   r  r  r  s   @r,   r  r    s$    ."!"! !r.   r  c                   H   ^  \ rS rSrSrS	U 4S jjrS rS rS rS r	Sr
U =r$ )
r  i  z*Transposition of arbitrary Linear Operatorc                    > / UR                   S S QUR                   S   PUR                   S   P7n[        TU ]	  UR                  X25        Xl        U4U l        g r/  r0  r2  s       r,   r;   "_TransposedLinearOperator.__init__  r4  r.   c                     U R                   R                  U R                  R                  U R                   R                  U5      5      5      $ r   )r8   conjr1  rs   r   s     r,   r"   !_TransposedLinearOperator._matvec  /    xx}}TVV__TXX]]1-=>??r.   c                     U R                   R                  U R                  R                  U R                   R                  U5      5      5      $ r   )r8   rE  r1  r"   r   s     r,   rs   "_TransposedLinearOperator._rmatvec  /    xx}}TVV^^DHHMM!,<=>>r.   c                     U R                   R                  U R                  R                  U R                   R                  U5      5      5      $ r   )r8   rE  r1  r   r   s     r,   r#   !_TransposedLinearOperator._matmat  rG  r.   c                     U R                   R                  U R                  R                  U R                   R                  U5      5      5      $ r   )r8   rE  r1  r#   r   s     r,   r   "_TransposedLinearOperator._rmatmat  rJ  r.   r?  r   r@  r  s   @r,   r  r    s&    4@?@? ?r.   r  c                     Uc  [         OUnUc  / nU  H6  nUc  M  [        US5      (       d  M  UR                  UR                  5        M8     [	        USU06$ )z;Returns the promoted dtype from input dtypes and operators.r1   r:   )r
   r   appendr1   r   )	operatorsdtypesr:   r*   s       r,   
_get_dtyperS    sT    jbB~?wsG44MM#))$  6)b))r.   c                   N   ^  \ rS rSrSrS
U 4S jjrS rS rS rS r	S r
S	rU =r$ )r   i  zRepresenting ``A + B``c                 ^  > [        U[        5      (       a  [        U[        5      (       d  [        S5      eUR                  Gt pEnUR                  Gt pxn	XV4X4:w  a  [        SU SU S35      e[        R
                  " XG5      n
X4U l        [        TU ]!  [        X/US9/ U
QUPUP7U5        g )N)both operands have to be a LinearOperatorzcannot add  and : shape mismatchr   )
rp   r   r6   r7   rT   rz   r(   r   r;   rS  r9   r1  Br:   A_broadcast_dimsA_MA_NB_broadcast_dimsB_MB_Nr   r+   s              r,   r;   _SumLinearOperator.__init__  s    !^,,Jq.4Q4QHII&'gg#	&'gg#	:##{1#U1#5EFGG//0@SF	QFr24Q6F4Q4QS4QSUVr.   c                 |    U R                   S   R                  U5      U R                   S   R                  U5      -   $ Nr   rm   r(   rP   r   s     r,   r"   _SumLinearOperator._matvec  3    yy|""1%		!(;(;A(>>>r.   c                 |    U R                   S   R                  U5      U R                   S   R                  U5      -   $ rc  r(   r   r   s     r,   rs   _SumLinearOperator._rmatvec  3    yy|##A&1)=)=a)@@@r.   c                 |    U R                   S   R                  U5      U R                   S   R                  U5      -   $ rc  r(   r   r   s     r,   r   _SumLinearOperator._rmatmat  rj  r.   c                 |    U R                   S   R                  U5      U R                   S   R                  U5      -   $ rc  r(   r   r   s     r,   r#   _SumLinearOperator._matmat  rf  r.   c                 P    U R                   u  pUR                  UR                  -   $ r   r(   r   r9   r1  rZ  s      r,   r   _SumLinearOperator._adjoint      yyssQSSyr.   r(   r   r   r  r  r	  r
  r;   r"   rs   r   r#   r   r  r  r  s   @r,   r   r     s,     	W?AA? r.   r   c                   N   ^  \ rS rSrSrS
U 4S jjrS rS rS rS r	S r
S	rU =r$ )r   i  zRepresenting ``A @ B``c                 X  > [        U[        5      (       a  [        U[        5      (       d  [        S5      eUR                  Gt pEnUR                  Gt pxn	Xh:w  a  [        SU SU S35      e[        R
                  " XG5      n
[        TU ]  [        X/US9/ U
QUPU	P7U5        X4U l	        g )NrV  zcannot multiply rW  rX  r   )
rp   r   r6   r7   rq   rz   r   r;   rS  r(   rY  s              r,   r;   _ProductLinearOperator.__init__  s    !^,,Jq.4Q4QHII&'gg#	&'gg#	:/s%s:JKLL../?RQFr24Q6F4Q4QS4QSUVF	r.   c                 v    U R                   S   R                  U R                   S   R                  U5      5      $ rc  rd  r   s     r,   r"   _ProductLinearOperator._matvec  .    yy|""499Q<#6#6q#9::r.   c                 v    U R                   S   R                  U R                   S   R                  U5      5      $ Nrm   r   rh  r   s     r,   rs   _ProductLinearOperator._rmatvec  .    yy|##DIIaL$8$8$;<<r.   c                 v    U R                   S   R                  U R                   S   R                  U5      5      $ r  rl  r   s     r,   r   _ProductLinearOperator._rmatmat  r  r.   c                 v    U R                   S   R                  U R                   S   R                  U5      5      $ rc  ro  r   s     r,   r#   _ProductLinearOperator._matmat  r}  r.   c                 P    U R                   u  pUR                  UR                  -  $ r   rr  rs  s      r,   r   _ProductLinearOperator._adjoint  ru  r.   rv  r   rw  r  s   @r,   r   r     s)     	;==; r.   r   c                   N   ^  \ rS rSrSrS
U 4S jjrS rS rS rS r	S r
S	rU =r$ )r   i
  zRepresenting ``alpha * A``c                 >  > [        U[        5      (       d  [        S5      e[        R                  " U5      (       d  [        S5      e[        U[
        5      (       a  UR                  u  pX$-  n[        U/U/US9n[        TU ]%  XQR                  U5        X4U l        g )NLinearOperator expected as Azscalar expected as alphar   )rp   r   r6   rq   isscalarr   r(   rS  r   r;   r7   )r9   r1  alphar:   alpha_originalr1   r+   s         r,   r;   _ScaledLinearOperator.__init__  s    !^,,;<<{{5!!788a.// !A *EA3B/,J	r.   c                 ^    U R                   S   U R                   S   R                  U5      -  $ r  rd  r   s     r,   r"   _ScaledLinearOperator._matvec  (    yy|diil11!444r.   c                 z    U R                   S   R                  5       U R                   S   R                  U5      -  $ r  )r(   	conjugater   r   s     r,   rs   _ScaledLinearOperator._rmatvec   1    yy|%%'$))A,*>*>q*AAAr.   c                 z    U R                   S   R                  5       U R                   S   R                  U5      -  $ r  )r(   r  r   r   s     r,   r   _ScaledLinearOperator._rmatmat#  r  r.   c                 ^    U R                   S   U R                   S   R                  U5      -  $ r  ro  r   s     r,   r#   _ScaledLinearOperator._matmat&  r  r.   c                 X    U R                   u  pUR                  UR                  5       -  $ r   )r(   r   r  )r9   r1  r  s      r,   r   _ScaledLinearOperator._adjoint)  s#    99ssU__&&&r.   rv  r   rw  r  s   @r,   r   r   
  s+    $ 5BB5' 'r.   r   c                   T   ^  \ rS rSrSrSU 4S jjrS rS rS rS r	S r
S	 rS
rU =r$ )r   i.  zRepresenting ``A ** p``c                 B  > [        U[        5      (       d  [        S5      eUR                  S   UR                  S   :w  a  SU< 3n[        U5      e[	        U5      (       a  US:  a  [        S5      e[
        TU ]  [        U/US9UR                  U5        X4U l        g )Nr  r   rJ   z7square core-dimensions of LinearOperator expected, got r   z"non-negative integer expected as pr   )	rp   r   r6   r7   r   r   r;   rS  r(   )r9   r1  r   r:   r   r+   s        r,   r;   _PowerLinearOperator.__init__1  s    !^,,;<<772;!''"+%KA5QCS/!||q1uABBQCB/"=F	r.   c                 j    [        U5      n[        U R                  S   5       H  nU" U5      nM     U$ )Nrm   )r   r^   r(   )r9   funrg   resra   s        r,   _power_PowerLinearOperator._power=  s0    ajtyy|$Ac(C %
r.   c                 T    U R                  U R                  S   R                  U5      $ Nr   )r  r(   rP   r   s     r,   r"   _PowerLinearOperator._matvecC  !    {{499Q<..22r.   c                 T    U R                  U R                  S   R                  U5      $ r  )r  r(   r   r   s     r,   rs   _PowerLinearOperator._rmatvecF  !    {{499Q<//33r.   c                 T    U R                  U R                  S   R                  U5      $ r  )r  r(   r   r   s     r,   r   _PowerLinearOperator._rmatmatI  r  r.   c                 T    U R                  U R                  S   R                  U5      $ r  )r  r(   r   r   s     r,   r#   _PowerLinearOperator._matmatL  r  r.   c                 <    U R                   u  pUR                  U-  $ r   rr  )r9   r1  r   s      r,   r   _PowerLinearOperator._adjointO  s    yyssAvr.   rv  r   )r   r  r  r	  r
  r;   r  r"   rs   r   r#   r   r  r  r  s   @r,   r   r   .  s.    !
3443 r.   r   c                   <   ^  \ rS rSrSrSU 4S jjrS rS rSrU =r	$ )MatrixLinearOperatoriT  z8Operator defined by a matrix `A` which implements ``@``.c                 z   > [         TU ]  UR                  UR                  U5        Xl        S U l        U4U l        g r   )r   r;   r1   r7   r1  _MatrixLinearOperator__adjr(   )r9   r1  r:   r+   s      r,   r;   MatrixLinearOperator.__init__W  s1    !''2.
D	r.   c                      U R                   U-  $ r   )r1  r   s     r,   r#   MatrixLinearOperator._matmat]  s    vvzr.   c                 z    U R                   c#  [        U R                  U R                  S9U l         U R                   $ r   )r  _AdjointMatrixOperatorr1  r8   r   s    r,   r   MatrixLinearOperator._adjoint`  s,    ::/488DDJzzr.   )r1  __adjr(   r   )
r   r  r  r	  r
  r;   r#   r   r  r  r  s   @r,   r  r  T  s    B r.   r  c                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )r  if  z5Representing ``A.H``, for `MatrixLinearOperator` `A`.c                 
  > Uc  [         OUnUR                  S:  a6  [        U5      (       a  [        R                  " USS5      nOUR
                  nOUR                  n[        TU ]!  UR                  U5      US9  U4U l
        g )Nr   rJ   r   r   )r
   r   r   r   swapaxesr   r   r   r;   rE  r(   )r9   r1  r:   A_Tr+   s       r,   r;   _AdjointMatrixOperator.__init__i  si    *Y"66A:{{ooaR0dd##C"-D	r.   c                 D    [        U R                  S   U R                  S9$ )Nr   r   )r  r(   r8   r   s    r,   r   _AdjointMatrixOperator._adjointu  s    #DIIaLTXX>>r.   rv  r   )	r   r  r  r	  r
  r;   r   r  r  r  s   @r,   r  r  f  s    ?
? ?r.   r  c                   J   ^  \ rS rSrS	U 4S jjrS rS rS rS rS r	Sr
U =r$ )
IdentityOperatoriy  c                 &   > [         TU ]  X!U5        g r   )r   r;   )r9   r7   r1   r:   r+   s       r,   r;   IdentityOperator.__init__z  s    r*r.   c                     U$ r   rn   r   s     r,   r"   IdentityOperator._matvec}      r.   c                     U$ r   rn   r   s     r,   rs   IdentityOperator._rmatvec  r  r.   c                     U$ r   rn   r   s     r,   r   IdentityOperator._rmatmat  r  r.   c                     U$ r   rn   r   s     r,   r#   IdentityOperator._matmat  r  r.   c                     U $ r   rn   r   s    r,   r   IdentityOperator._adjoint  s    r.   rn   NN)r   r  r  r	  r;   r"   rs   r   r#   r   r  r  r  s   @r,   r  r  y  s&    + r.   r  c                 L   [        U [        5      (       a  U $ [        U 5      (       ae  [        U [        R                  5      (       dF  [        U 5      n[        U 5      (       a  [        (       d  O[        R                  " U SUS9n [        XS9$ [        U 5      (       a  [        U 5      $ [        U [        R                  5      (       a5  [        R                  " [        R                  " U 5      5      n [        U 5      $ [        U S5      (       a  [        U S5      (       a}  SnSnSn[        U S5      (       a  U R                  n[        U S5      (       a  U R                   n[        U S	5      (       a  U R"                  n[        U R$                  U R&                  X#US
9$ [)        S5      e)a  Return `A` as a `LinearOperator`.

See the `LinearOperator` documentation for additional information.

Parameters
----------
A : object
    Object to convert to a `LinearOperator`. May be any one of the following types:

    - `numpy.ndarray`
    - `numpy.matrix`
    - `scipy.sparse` array
      (e.g. `~scipy.sparse.csr_array`, `~scipy.sparse.lil_array`, etc.)
    - `LinearOperator`
    - An object with ``.shape`` and ``.matvec`` attributes

Returns
-------
B : LinearOperator
    A `LinearOperator` corresponding with `A`

Notes
-----
If `A` has no ``.dtype`` attribute, the data type is determined by calling
:func:`LinearOperator.matvec()` - set the ``.dtype`` attribute to prevent this
call upon the linear operator creation.

Examples
--------
>>> import numpy as np
>>> from scipy.sparse.linalg import aslinearoperator
>>> M = np.array([[1,2,3],[4,5,6]], dtype=np.int32)
>>> aslinearoperator(M)
<2x3 MatrixLinearOperator with dtype=int32>
r   )r   r:   r   r7   rP   Nr   r   r1   )r   r   r1   ztype not understood)rp   r   r   rq   rr   r   r	   r   rT   
atleast_ndr  r   
atleast_2drO   r   r   r   r1   r7   rP   rR   )r1  r:   r   r   r1   s        r,   r   r     sI   J !^$$ :a#;#;Q!!$$__qqR0A#A--{{#A&&!RYYMM"**Q-(#A&&q'wq(331i  iiG1i  iiG1gGGEGGQXXwu
 	
 )
**r.   r  )+r
  rv   r  r$   numpyrq   scipyr   scipy._externalr   rT   scipy._lib._array_apir   r   r   r   r	   r
   r   r   r   r   scipy.sparser   scipy.sparse._sputilsr   r   r   r   __all__r   r    r  r  rS  r   r   r   r   r  r  r  r   rn   r.   r,   <module>r     s   *X 
     2   " R R/
0 Q< Q< Q<h6
N 6
r!^ !,? ?,* >^ >!'N !'H#> #L> $?1 ?&~ ( F+ F+r.   