
    (ph                     N   S r SSKrSSKJrJrJrJrJrJ	r	J
r
JrJr  SSKJr  / SQr " S S\5      r " S	 S
\5      r " S S\5      r0 SSS/_SSS/_SSS/_SSS/_SSS/_SSS/_SSS/_S S!S"/_S#S$S%/_S&S'S(/_S)S*S+/_S,S-S./_S/S0S1/_S2S3S4/_S5S6S7/_S8S9S:/_S;S<S=/_S>S?/S@SA/SBSC/SD.Er\" \R,                  \R.                  \R0                  \R2                  \R4                  \R6                  \R8                  \R:                  \R<                  \R>                  \R@                  \RB                  \RD                  \RF                  \RH                  \RJ                  \RL                  \RN                  /5      r(SEr) " SF SG5      r* " SH SI5      r+\*R                   \+l         SJ r,SK r-g)LzBase class for sparse matrices    N   )	asmatrixcheck_reshape_kwargscheck_shapeget_sum_dtypeisdenseisscalarlikematrixvalidateaxisgetdtype)spmatrix)
isspmatrixissparsesparraySparseWarningSparseEfficiencyWarningc                       \ rS rSrSrg)r       N__name__
__module____qualname____firstlineno____static_attributes__r       E/var/www/html/venv/lib/python3.13/site-packages/scipy/sparse/_base.pyr   r          r   r   c                       \ rS rSrSrg)SparseFormatWarning   r   Nr   r   r   r   r    r       r   r   r    c                       \ rS rSrSrg)r      r   Nr   r   r   r   r   r      r   r   r   csczCompressed Sparse ColumncsrzCompressed Sparse Rowdok   zDictionary Of Keyslil   zList of Listsdod   zDictionary of Dictionariessss   zSymmetric Sparse Skylinecoo   
COOrdinatelba   zLinpack BAndedegd   z#Ellpack-itpack Generalized Diagonaldia	   DIAgonalbsr
   zBlock Sparse Rowmsr   zModified compressed Sparse Rowbsc   zBlock Sparse Columnmsc   z!Modified compressed Sparse Columnssk   zSymmetric SKylinenskr   zNonsymmetric SKylinejad   zJAgged Diagonal   zUnsymmetric Sparse Skyline   zVariable Block Rowr!   	Undefined)ussvbrund2   c                      \ rS rSrSrSrSrSr\S\	4S j5       r
\S 5       r\S	 5       r\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rSS.S jr\S 5       rS rS rSqS jr\S 5       r\S 5       rS rS rS rSrS jrSrS jr\S\	4S j5       r \S\	4S j5       r!\S\"4S  j5       r#\S! 5       r$\S" 5       r%\S# 5       r&S$ r'S% r(S& r)\)r*S' r+SsS( jr,S) r-S* r.S+ r/S, r0SrS- jr1SsS. jr2S/ r3S0 r4S1 r5S2 r6S3 r7S4 r8S5 r9StS6 jr:S7 r;S8 r<S9 r=S: r>S; r?S< r@S= rAS> rBS? rCS@ rDSA rESB rFSC rGSD rHSE rISF rJSG rKSH rLSI rMSuSJ jrNSK rOSL rPSM rQSN rRSO rSSP rTSQ rUSR rVSS rWST rXSU rYSvSV jrZSwSW jr[SwSX jr\\[R                  \\l        SY r]SZ r^S[ r_S\ r`S] raSxS^ jrbSxS_ jrcSsS` jrdSsSa jreSsSb jrfSsSc jrgSsSd jrhSvSe jriSsSf jrjSg rkSySh jrlSySi jrmStSj jrnStSk jroStSl jrpSm rqSn rrSzSo jrsSprtg){_spbase=   zThis class provides a base class for all sparse arrays.  It
cannot be instantiated.  Most of the work is provided by subclasses.
g333333$@rJ   )r'   returnc                 ,    [        U R                  5      $ N)len_shapeselfs    r   ndim_spbase.ndimF   s    4;;r   c                 J    U R                   n[        U5      S:X  a  SUS   4$ U$ )Nr   )rS   rR   )rU   ss     r   _shape_as_2d_spbase._shape_as_2dJ   s(    KK Vq[1R5z/a/r   c                     SSK Jn  U$ )Nr   )	bsr_array)_bsrr^   )rU   r^   s     r   _bsr_container_spbase._bsr_containerO       #r   c                     SSK Jn  U$ )Nr   )	coo_array)_coord   )rU   rd   s     r   _coo_container_spbase._coo_containerT   rb   r   c                     SSK Jn  U$ )Nr   )	csc_array)_cscri   )rU   ri   s     r   _csc_container_spbase._csc_containerY   rb   r   c                     SSK Jn  U$ )Nr   )	csr_array)_csrrn   )rU   rn   s     r   _csr_container_spbase._csr_container^   rb   r   c                     SSK Jn  U$ )Nr   )	dia_array)_diars   )rU   rs   s     r   _dia_container_spbase._dia_containerc   rb   r   c                     SSK Jn  U$ )Nr   )	dok_array)_dokrx   )rU   rx   s     r   _dok_container_spbase._dok_containerh   rb   r   c                     SSK Jn  U$ )Nr   )	lil_array)_lilr}   )rU   r}   s     r   _lil_container_spbase._lil_containerm   rb   r   Nmaxprintc                    S U l         U R                  R                  S:X  a  [        S5      e[	        U [
        5      (       a&  [        R                  " U5      (       a  [        S5      eUc  [        U l	        g UU l	        g )NrM   z7This class is not intended to be instantiated directly.zEscipy sparse array classes do not support instantiation from a scalar)
rS   	__class__r   
ValueError
isinstancer   npisscalarMAXPRINTr   )rU   arg1r   s      r   __init___spbase.__init__r   sl    >>""i/ = > >dG$$T):):W  %-$4(r   c                     U R                   $ rQ   )rS   rT   s    r   shape_spbase.shape}   s    {{r   c                     [        XR                  [        SS5      S9n[        U5      u  pEX0R                  :X  a  U(       a  U R	                  5       $ U $ U R                  US9R                  X4SS9$ )a  reshape(self, shape, order='C', copy=False)

Gives a new shape to a sparse array/matrix without changing its data.

Parameters
----------
shape : length-2 tuple of ints
    The new shape should be compatible with the original shape.
order : {'C', 'F'}, optional
    Read the elements using this index order. 'C' means to read and
    write the elements using C-like index order; e.g., read entire first
    row, then second row, etc. 'F' means to read and write the elements
    using Fortran-like index order; e.g., read entire first column, then
    second column, etc.
copy : bool, optional
    Indicates whether or not attributes of self should be copied
    whenever possible. The degree to which attributes are copied varies
    depending on the type of sparse array being used.

Returns
-------
reshaped : sparse array/matrix
    A sparse array/matrix with the given `shape`, not necessarily of the same
    format as the current object.

See Also
--------
numpy.reshape : NumPy's implementation of 'reshape' for ndarrays
r   A   )allow_ndcopyF)orderr   )r   r   ranger   r   tocooreshape)rU   argskwargsr   r   r   s         r   r   _spbase.reshape   sf    B D**uQ|D*62JJyy{"zztz$,,Ue,LLr   c                 D    [        [        U 5      R                   S35      e)a  Resize the array/matrix in-place to dimensions given by ``shape``

Any elements that lie within the new shape will remain at the same
indices, while non-zero elements lying outside the new shape are
removed.

Parameters
----------
shape : (int, int)
    number of rows and columns in the new array/matrix

Notes
-----
The semantics are not identical to `numpy.ndarray.resize` or
`numpy.resize`. Here, the same data will be maintained at each index
before and after reshape, if that index is within the new bounds. In
numpy, resizing maintains contiguity of the array, moving elements
around in the logical array but not within a flattened representation.

We give no guarantees about whether the underlying data attributes
(arrays, etc.) will be modified in place or replaced with new objects.
z.resize is not implemented)NotImplementedErrortyper   )rU   r   s     r   resize_spbase.resize   s)    0 "Dz""##=>@ 	@r   c                     [        U5      nU R                  U:w  a7  U R                  5       R                  XUS9R	                  U R
                  5      $ U(       a  U R                  5       $ U $ )aq  Cast the array/matrix elements to a specified type.

Parameters
----------
dtype : string or numpy dtype
    Typecode or data-type to which to cast the data.
casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
    Controls what kind of data casting may occur.
    Defaults to 'unsafe' for backwards compatibility.
    'no' means the data types should not be cast at all.
    'equiv' means only byte-order changes are allowed.
    'safe' means only casts which can preserve values are allowed.
    'same_kind' means only safe casts or casts within a kind,
    like float64 to float32, are allowed.
    'unsafe' means any data conversions may be done.
copy : bool, optional
    If `copy` is `False`, the result might share some memory with this
    array/matrix. If `copy` is `True`, it is guaranteed that the result and
    this array/matrix do not share any memory.
)castingr   )r   dtypetocsrastypeasformatformatr   )rU   r   r   r   s       r   r   _spbase.astype   s_    , ::::<&&T ' 33;8DKK3HI99;Kr   c                 r    [        U [        5      (       a  [        R                  " U40 UD6$ [	        U40 UD6$ rQ   )
issubclassr   r   asarrayr   clsXr   s      r   _ascontainer_spbase._ascontainer   s3    c7##::a*6**A(((r   c                 r    [        U [        5      (       a  [        R                  " U40 UD6$ [	        U40 UD6$ rQ   )r   r   r   arrayr
   r   s      r   
_container_spbase._container   s3    c7##88A(((!&v&&r   c                    / SQnU R                   R                  U;   a  U $ U H:  nU R                   [        R                   " U5      ::  d  M)  U R                  U5      s  $    [	        SU R                   R
                   S35      e)z6Upcast array to a floating point format (if necessary))fdFDzcannot upcast [z] to a floating point format)r   charr   r   	TypeErrorname)rU   fp_typesfp_types      r   	_asfptype_spbase._asfptype   sq     (::??h&K#::'!22;;w// $ !$**//!22NO r   c              #   V   #    [        U R                  S   5       H	  nX   v   M     g 7f)Nr   )r   r   )rU   rs     r   __iter___spbase.__iter__  s#     tzz!}%A'M &s   ')c                     U R                   $ )z3Maximum number of elements to display when printed.r   rT   s    r   _getmaxprint_spbase._getmaxprint  s    }}r   c                 L    U R                   R                  n[        SU S35      e)aj  Number of non-zero entries, equivalent to

np.count_nonzero(a.toarray(), axis=axis)

Unlike the nnz property, which return the number of stored
entries (the length of the data attribute), this method counts the
actual number of non-zero entries in data.

Duplicate entries are summed before counting.

Parameters
----------
axis : {-2, -1, 0, 1, None} optional
    Count nonzeros for the whole array, or along a specified axis.

    .. versionadded:: 1.15.0

Returns
-------
numpy array
    A reduced array (no axis `axis`) holding the number of nonzero values
    for each of the indices of the nonaxis dimensions.

Notes
-----
If you want to count nonzero and explicit zero stored values (e.g. nnz)
along an axis, two fast idioms are provided by `numpy` functions for the
common CSR, CSC, COO formats.

For the major axis in CSR (rows) and CSC (cols) use `np.diff`:

    >>> import numpy as np
    >>> import scipy as sp
    >>> A = sp.sparse.csr_array([[4, 5, 0], [7, 0, 0]])
    >>> major_axis_stored_values = np.diff(A.indptr)  # -> np.array([2, 1])

For the minor axis in CSR (cols) and CSC (rows) use `numpy.bincount` with
minlength ``A.shape[1]`` for CSR and ``A.shape[0]`` for CSC:

    >>> csr_minor_stored_values = np.bincount(A.indices, minlength=A.shape[1])

For COO, use the minor axis approach for either `axis`:

    >>> A = A.tocoo()
    >>> coo_axis0_stored_values = np.bincount(A.coords[0], minlength=A.shape[1])
    >>> coo_axis1_stored_values = np.bincount(A.coords[1], minlength=A.shape[0])

Examples
--------

    >>> A = sp.sparse.csr_array([[4, 5, 0], [7, 0, 0]])
    >>> A.count_nonzero(axis=0)
    array([2, 1, 0])
z"count_nonzero not implemented for .r   r   r   rU   axisclsnames      r   count_nonzero_spbase.count_nonzero  s)    n ..))!$Fwiq"QRRr   c                 L    U R                   R                  n[        SU S35      e)zNumber of stored values, including explicit zeros.

Parameters
----------
axis : {-2, -1, 0, 1, None} optional
    Report stored values for the whole array, or along a specified axis.

See also
--------
count_nonzero : Number of non-zero entries
zgetnnz not implemented for r   r   r   s      r   _getnnz_spbase._getnnzF  s(     ..))!$?y"JKKr   c                 "    U R                  5       $ )zqNumber of stored values, including explicit zeros.

See also
--------
count_nonzero : Number of non-zero entries
r   rT   s    r   nnz_spbase.nnzU       ||~r   c                 "    U R                  5       $ )zWNumber of stored values.

See also
--------
count_nonzero : Number of non-zero values.
r   rT   s    r   size_spbase.size_  r   r   c                     U R                   $ )zFormat string for matrix.)_formatrT   s    r   r   _spbase.formati  s     ||r   c                 "    U R                  5       $ )z
Transpose.)	transposerT   s    r   T	_spbase.Tn  s     ~~r   c                 "    U R                  5       $ rQ   )_realrT   s    r   real_spbase.reals      zz|r   c                 "    U R                  5       $ rQ   )_imagrT   s    r   imag_spbase.imagw  r   r   c                     [         U R                     u  p[        U [        5      (       a  SOSnSU SU SU R                   SU R
                   SU R                   S3$ )	Nr   r
   <z sparse z of dtype 'z'
	with z stored elements and shape >)_formatsr   r   r   r   r   r   )rU   _format_name
sparse_clss       r   __repr___spbase.__repr__{  sc    !$++. *4 9 9Wx
}HZLDJJ< HhhZ:4::,aI	
r   c                   ^ U R                  5       nU R                  5       nS n[        U 5      nU R                  S:X  a  U$ US-  nU R                  U:  a|  US-  mXC" [	        U4S jUR
                   5       5      UR                  S T 5      -  nUS-  nUT-
  mXC" [	        U4S jUR
                   5       5      UR                  T* S  5      -  nU$ XC" UR
                  UR                  5      -  nU$ )Nc                 d    [        [        S U  5       6 U5      nSR                  S U 5       5      $ )Nc              3   @   #    U  H  oR                  5       v   M     g 7frQ   )tolist).0cs     r   	<genexpr>1_spbase.__str__.<locals>.tostr.<locals>.<genexpr>  s     9&Qhhjj&s   
c              3   6   #    U  H  u  pS U SU 3v   M     g7f)z  	Nr   )r   idxvals      r   r   r     s     Eu83r#b.us   )zipjoin)coordsdatapairss      r   tostr_spbase.__str__.<locals>.tostr  s.    9&9:DAE99EuEEEr   r   z
  Coords	Values
r'   c              3   ,   >#    U  H	  oS T v   M     g 7frQ   r   r   r   halfs     r   r   "_spbase.__str__.<locals>.<genexpr>  s     :A$x   z
  :	:
c              3   .   >#    U  H
  oT* S  v   M     g 7frQ   r   r	  s     r   r   r    s     ;(Q$y(s   )r   r   reprr   tupler  r  )rU   r   Ar  outr
  s        @r   __str___spbase.__str__  s    $$&JJL	F 4j88q=J%%88hq=D5:::AFF5DMJJC<Cd?D5;!((;;QVVTEF^LLC 
 5166**C
r   c                 V    U R                   S:X  a  U R                  S:g  $ [        S5      e)N)r   r   r   z\The truth value of an array with more than one element is ambiguous. Use a.any() or a.all().)r   r   r   rT   s    r   __bool___spbase.__bool__  s1    ::88q=  M N Nr   c                     [        S5      e)Nz:sparse array length is ambiguous; use getnnz() or shape[0])r   rT   s    r   __len___spbase.__len__  s     ' ( 	(r   c                     Ub  XR                   :X  a  U(       a  U R                  5       $ U $  [        U SU-   5      n U" US9$ ! [         a  n[	        SU S35      UeSnAff = f! [
         a
    U" 5       s $ f = f)aY  Return this array/matrix in the passed format.

Parameters
----------
format : {str, None}
    The desired sparse format ("csr", "csc", "lil", "dok", "array", ...)
    or None for no conversion.
copy : bool, optional
    If True, the result is guaranteed to not share data with self.

Returns
-------
A : This array/matrix in the passed format.
NtozFormat z is unknown.r   )r   r   getattrAttributeErrorr   r   )rU   r   r   convert_methodes        r   r   _spbase.asformat  s     >V{{2yy{"H!(tf}!=
(%400 " H 76(,!?@aGH  (%''(s(   A A% 
A"AA"%A98A9c                     [        U5      (       a  U R                  U5      $ U R                  5       R                  U5      $ )z2Point-wise multiplication by another array/matrix.)r	   _mul_scalarr   multiplyrU   others     r   r#  _spbase.multiply  s5    ##E**zz|$$U++r   c                 @    U R                  5       R                  U5      $ )z;Element-wise maximum between this and another array/matrix.)r   maximumr$  s     r   r(  _spbase.maximum      zz|##E**r   c                 @    U R                  5       R                  U5      $ )z;Element-wise minimum between this and another array/matrix.)r   minimumr$  s     r   r,  _spbase.minimum  r*  r   c                 H    [         R                  " U5      (       a  X-  $ X-  $ )zOrdinary dot product

Examples
--------
>>> import numpy as np
>>> from scipy.sparse import csr_array
>>> A = csr_array([[1, 2, 0], [0, 0, 3], [4, 0, 5]])
>>> v = np.array([1, 0, -1])
>>> A.dot(v)
array([ 1, -3, -1], dtype=int64)

)r   r   r$  s     r   dot_spbase.dot  s#     ;;u<<r   c                 <    U R                  5       R                  XS9$ )zElement-wise power.r   )r   power)rU   nr   s      r   r3  _spbase.power  s    zz|!!!!11r   c                     U R                   U:X  a  U(       a  U R                  5       $ U $ U R                  5       R                  X5      $ rQ   )r   r   r   _broadcast_to)rU   r   r   s      r   r7  _spbase._broadcast_to  s8    ::"&499;0D0::<--e::r   c                 @    U R                  5       R                  U5      $ rQ   )r   __eq__r$  s     r   r:  _spbase.__eq__      zz|""5))r   c                 @    U R                  5       R                  U5      $ rQ   )r   __ne__r$  s     r   r>  _spbase.__ne__   r<  r   c                 @    U R                  5       R                  U5      $ rQ   )r   __lt__r$  s     r   rA  _spbase.__lt__  r<  r   c                 @    U R                  5       R                  U5      $ rQ   )r   __gt__r$  s     r   rD  _spbase.__gt__  r<  r   c                 @    U R                  5       R                  U5      $ rQ   )r   __le__r$  s     r   rG  _spbase.__le__	  r<  r   c                 @    U R                  5       R                  U5      $ rQ   )r   __ge__r$  s     r   rJ  _spbase.__ge__  r<  r   c                 4    [        U R                  5       5      $ rQ   )absr   rT   s    r   __abs___spbase.__abs__  s    4::<  r   c                 2    [        U R                  5       US9$ )N)ndigits)roundr   )rU   rQ  s     r   	__round___spbase.__round__  s    TZZ\733r   c                 @    U R                  5       R                  U5      $ rQ   )r   _add_sparser$  s     r   rV  _spbase._add_sparse      zz|''..r   c                 @    U R                  5       R                  U5      $ rQ   )r   
_add_denser$  s     r   rZ  _spbase._add_dense  s    zz|&&u--r   c                 @    U R                  5       R                  U5      $ rQ   )r   _sub_sparser$  s     r   r]  _spbase._sub_sparse  rX  r   c                 (    U R                  5       U-
  $ rQ   todenser$  s     r   
_sub_dense_spbase._sub_dense  s    ||~%%r   c                 &    XR                  5       -
  $ rQ   r`  r$  s     r   _rsub_dense_spbase._rsub_dense!  s    ||~%%r   c                 ~   [        U5      (       a!  US:X  a  U R                  5       $ [        S5      e[        U5      (       a6  UR                  U R                  :w  a  [        S5      eU R                  U5      $ [        U5      (       a1  [        R                  " XR                  5      nU R                  U5      $ [        $ )Nr   z:adding a nonzero scalar to a sparse array is not supportedinconsistent shapes)r	   r   r   r   r   r   rV  r   r   broadcast_torZ  NotImplementedr$  s     r   __add___spbase.__add__%  s    zyy{"% 'F G Ge__{{djj( !677##E**U^^OOE::6E??5))!!r   c                 $    U R                  U5      $ rQ   )rk  r$  s     r   __radd___spbase.__radd__6  s    ||E""r   c                 ~   [        U5      (       a!  US:X  a  U R                  5       $ [        S5      e[        U5      (       a6  UR                  U R                  :w  a  [        S5      eU R                  U5      $ [        U5      (       a1  [        R                  " XR                  5      nU R                  U5      $ [        $ )Nr   zAsubtracting a nonzero scalar from a sparse array is not supportedrh  )r	   r   r   r   r   r   r]  r   r   ri  rb  rj  r$  s     r   __sub___spbase.__sub__9  s    zyy{"% 'F G Ge__{{djj( !677##E**U^^OOE::6E??5))!!r   c                     [        U5      (       a"  US:X  a  U R                  5       * $ [        S5      e[        U5      (       a1  [        R
                  " XR                  5      nU R                  U5      $ [        $ )Nr   zAsubtracting a sparse array from a nonzero scalar is not supported)	r	   r   r   r   r   ri  r   re  rj  r$  s     r   __rsub___spbase.__rsub__I  si    z		|#% 'H I IU^^OOE::6E##E**!!r   c                    U R                   u  p#UR                  [        R                  L a  UR                  U4:X  a  U R                  U5      $ UR                  US4:X  aR  U R                  UR                  5       5      nU R                  S:X  a  UR                  S5      $ UR                  US5      $ UR                  S:X  a$  UR                  S   U:X  a  U R                  U5      $ [        U5      (       a  U R                  U5      $ Sn[        U5      (       aD  X1R                  S   :w  a!  [        U SU SUR                  S    S35      eU R                  U5      $ [        R                  " U5      nUR                  S:X  a$  UR                   [        R"                  :X  a  [$        $  UR                    UR                  S:X  d#  UR                  S:X  a  UR                  S   S:X  a  UR                  S   U:w  a!  [        U SU SUR                  S    S35      eU R                  [        R                  " U5      5      n[)        U[        R*                  5      (       a  U R-                  U5      nUR                  S:X  aH  UR                  S   S:X  a5  U R                  S:X  a  UR                  S5      nU$ UR                  S	S5      nU$ UR                  S:X  a  UR                  S   U:w  a!  [        U SU SUR                  S    S35      eU R                  [        R.                  " U5      5      n[)        U[        R*                  5      (       a  U R-                  U5      nU$ [        S
5      e! [&         a    Un GNf = f)znp.array-like matmul & `np.matrix`-like mul, i.e. `dot` or `NotImplemented`

interpret other and call one of the following
self._mul_scalar()
self._matmul_vector()
self._matmul_multivector()
self._matmul_sparse()
r   r'   r   z)matmul: dimension mismatch with signaturez (n,k=z),(k=z
,m)->(n,m)z,1?)->(n,1?)rY   zcould not interpret dimensions)r[   r   r   ndarrayr   _matmul_vectorravelrV   r   _matmul_multivectorr	   r"  r   r   _matmul_sparse
asanyarrayr   object_rj  r  r   r
   r   r   )rU   r%  MNresult
err_prefixother_as          r   _matmul_dispatch_spbase._matmul_dispatchU  s      ??bjj({{qd"**511A&,,U[[];99>!>>!,,~~a++qU[[^q%8//66##E**@
E??KKN" !l&5Q0@
K  &&u-- --&<<1"**!< "!	KK ::?ejjAo%++a.A2E{{1~" !l&5Q0@M  ((%9F%++**62zzQ5;;q>Q#699>#^^A.F M $^^B2FMZZ1_ {{1~" !l&5Q0@
K  --bjj.?@F%++**62M =>>S  	E	s   (M0 0N ?N c                 $    U R                  U5      $ rQ   r#  r$  s     r   __mul___spbase.__mul__      }}U##r   c                 $    U R                  U5      $ rQ   r  r$  s     r   __rmul___spbase.__rmul__  r  r   c                 @    U R                  5       R                  U5      $ rQ   )r   r"  r$  s     r   r"  _spbase._mul_scalar  rX  r   c                 @    U R                  5       R                  U5      $ rQ   )r   rx  r$  s     r   rx  _spbase._matmul_vector      zz|**511r   c                 @    U R                  5       R                  U5      $ rQ   )r   rz  r$  s     r   rz  _spbase._matmul_multivector  s    zz|//66r   c                 @    U R                  5       R                  U5      $ rQ   )r   r{  r$  s     r   r{  _spbase._matmul_sparse  r  r   c                 J   [        U5      (       a  U R                  U5      $  UR                  5       nU R                  5       R                  U5      nU[        L a  [        $ UR                  5       $ ! [         a'    [        R
                  " U5      R                  5       n Nnf = frQ   )r	   r"  r   r  r   r   r  rj  )rU   r%  trrets       r   _rmatmul_dispatch_spbase._rmatmul_dispatch  s    ##E**3__& .."33B7Cn$%%==?" " 3ZZ&0023s   A1 1.B"!B"c                 Z    [        U5      (       a  [        S5      eU R                  U5      $ Nz0Scalar operands are not allowed, use '*' instead)r	   r   r  r$  s     r   
__matmul___spbase.__matmul__  s0     / 0 0$$U++r   c                 Z    [        U5      (       a  [        S5      eU R                  U5      $ r  )r	   r   r  r$  s     r   __rmatmul___spbase.__rmatmul__  s0     / 0 0%%e,,r   c                    [        U5      (       Gaq  U(       aO  U(       a$  [        R                  " XR                  5       5      $ [        R                  " XR                  5       5      $ U(       ae  [        R
                  " U R                  [        R                  5      (       a1  U R                  [        R                  5      R                  SU-  5      $ U R                  SU-  5      n[        R                  " U5      R                  n[        R                  " U R                  [        R                  5      (       aE  [        R                  " U[        R                  5      (       a  UR                  U R                  5      $ U$ [        U5      (       a  U(       dG  U(       a  [        R                  " SU5      nO[        R                  " SU5      nU R                  U5      $ U(       a$  [        R                  " XR                  5       5      $ [        R                  " XR                  5       5      $ [        U5      (       a  U(       a  UR!                  XSS9$ U R#                  5       nU(       ab  [        R
                  " U R                  [        R                  5      (       a.  UR                  [        R                  5      R%                  U5      $ UR%                  U5      $ [&        $ )N      ?F)rdivide)r	   r   true_dividera  dividecan_castr   float64r   r"  r   
issubdtypeintegerr   r#  r   _divider   _divide_sparserj  )rU   r%  r  r  r   scalar_dtyperecipself_csrs           r   r  _spbase._divide  s   >>%@@99ULLN;;r{{4::rzzBB{{2::.::2e8DD$$RX.!zz%066MM$**bjj99lBJJ??88DJJ//HU^^NN2u5EIIb%0E}}U++>>%@@99ULLN;;e__}}T}FFzz|Hr{{4::rzzBBrzz2AA%HH..u55!!r   c                 "    U R                  USS9$ NT)r  r  r$  s     r   __truediv___spbase.__truediv__  s    ||Et|44r   c                 "    U R                  USS9$ r  r  r$  s     r   __div___spbase.__div__  s    ||Et|44r   c                     [         $ rQ   rj  r$  s     r   __rtruediv___spbase.__rtruediv__      r   c                     [         $ rQ   r  r$  s     r   __rdiv___spbase.__rdiv__  r  r   c                 $    U R                  5       * $ rQ   )r   rT   s    r   __neg___spbase.__neg__#  s    

}r   c                     [         $ rQ   r  r$  s     r   __iadd___spbase.__iadd__&      r   c                     [         $ rQ   r  r$  s     r   __isub___spbase.__isub__)  r  r   c                     [         $ rQ   r  r$  s     r   __imul___spbase.__imul__,  r  r   c                 $    U R                  U5      $ rQ   )__itruediv__r$  s     r   __idiv___spbase.__idiv__/  s      ''r   c                     [         $ rQ   r  r$  s     r   r  _spbase.__itruediv__2  r  r   c                 &    U R                   " U0 UD6$ rQ   )r3  )rU   r   r   s      r   __pow___spbase.__pow__5  s    zz4*6**r   c                 <    U R                  US9R                  USS9$ )a  
Reverses the dimensions of the sparse array/matrix.

Parameters
----------
axes : None, optional
    This argument is in the signature *solely* for NumPy
    compatibility reasons. Do not pass in anything except
    for the default value.
copy : bool, optional
    Indicates whether or not attributes of `self` should be
    copied whenever possible. The degree to which attributes
    are copied varies depending on the type of sparse array/matrix
    being used.

Returns
-------
p : `self` with the dimensions reversed.

Notes
-----
If `self` is a `csr_array` or a `csc_array`, then this will return a
`csc_array` or a `csr_array`, respectively.

See Also
--------
numpy.transpose : NumPy's implementation of 'transpose' for ndarrays
r   F)axesr   )r   r   )rU   r  r   s      r   r   _spbase.transpose8  s%    : zztz$..Du.EEr   c                     [         R                  " U R                  [         R                  5      (       a  U R	                  US9R                  SS9$ U(       a  U R                  5       $ U $ )aG  Element-wise complex conjugation.

If the array/matrix is of non-complex data type and `copy` is False,
this method does nothing and the data is not copied.

Parameters
----------
copy : bool, optional
    If True, the result is guaranteed to not share data with self.

Returns
-------
A : The element-wise complex conjugate.

r   F)r   r  r   complexfloatingr   	conjugater   rU   r   s     r   r  _spbase.conjugateW  sR      ==R%7%788::4:(222>>99;Kr   c                      U R                  US9$ )Nr   )r  r  s     r   conj_spbase.conjn  s    ~~4~((r   c                 >    U R                  5       R                  5       $ rQ   )r   r   rT   s    r   r   _spbase._reals      zz|!!##r   c                 >    U R                  5       R                  5       $ rQ   )r   r   rT   s    r   r   _spbase._imagv  r  r   c                    ^ U R                  5       nUR                  S:g  m[        U4S jUR                   5       5      $ )aS  Nonzero indices of the array/matrix.

Returns a tuple of arrays (row,col) containing the indices
of the non-zero elements of the array.

Examples
--------
>>> from scipy.sparse import csr_array
>>> A = csr_array([[1, 2, 0], [0, 0, 3], [4, 0, 5]])
>>> A.nonzero()
(array([0, 0, 1, 2, 2], dtype=int32), array([0, 1, 2, 0, 2], dtype=int32))

r   c              3   ,   >#    U  H	  oT   v   M     g 7frQ   r   )r   r   nz_masks     r   r   "_spbase.nonzero.<locals>.<genexpr>  s     6Xc\Xr  )r   r  r  r  )rU   r  r  s     @r   nonzero_spbase.nonzeroy  s2      JJL&&A+6QXX666r   c                     U R                   S:X  a  [        S5      eU R                  S   nUS:  a  X-  nUS:  d  X:  a  [        S5      eU R	                  S/U/S//4US4U R
                  S9nX-  nU$ )zUReturns a copy of column j of the array, as an (m x 1) sparse
array (column vector).
r   z4getcol not provided for 1d arrays. Use indexing A[j]rY   r   index out of boundsr   r   )rV   r   r   
IndexErrorrk   r   )rU   jr  col_selectorr  s        r   _getcol_spbase._getcol  s     99>STT JJrNq5FAq5AF233**QC1#s+<23Qtzz + K$r   c                     U R                   S:X  a  [        S5      eU R                  S   nUS:  a  X-  nUS:  d  X:  a  [        S5      eU R	                  S/S/U//4SU4U R
                  S9nX0-  $ )zNReturns a copy of row i of the array, as a (1 x n) sparse
array (row vector).
r   z$getrow not meaningful for a 1d arrayr   r  r  )rV   r   r   r  rp   r   )rU   ir~  row_selectors       r   _getrow_spbase._getrow  s     99>CDD JJqMq5FAq5AF233**QC1#s+<23Qtzz + K""r   c                 >    U R                  U R                  XS95      $ )a~  
Return a dense representation of this sparse array.

Parameters
----------
order : {'C', 'F'}, optional
    Whether to store multi-dimensional data in C (row-major)
    or Fortran (column-major) order in memory. The default
    is 'None', which provides no ordering guarantees.
    Cannot be specified in conjunction with the `out`
    argument.

out : ndarray, 2-D, optional
    If specified, uses this array as the output buffer
    instead of allocating a new array to return. The
    provided array must have the same shape and dtype as
    the sparse array on which you are calling the method.

Returns
-------
arr : ndarray, 2-D
    An array with the same shape and containing the same
    data represented by the sparse array, with the requested
    memory order. If `out` was passed, the same object is
    returned after being modified in-place to contain the
    appropriate values.
r   r  )r   toarrayrU   r   r  s      r   ra  _spbase.todense  s     8   E!CDDr   c                 :    U R                  SS9R                  XS9$ )a  
Return a dense ndarray representation of this sparse array/matrix.

Parameters
----------
order : {'C', 'F'}, optional
    Whether to store multidimensional data in C (row-major)
    or Fortran (column-major) order in memory. The default
    is 'None', which provides no ordering guarantees.
    Cannot be specified in conjunction with the `out`
    argument.

out : ndarray, 2-D, optional
    If specified, uses this array as the output buffer
    instead of allocating a new array to return. The provided
    array must have the same shape and dtype as the sparse
    array/matrix on which you are calling the method. For most
    sparse types, `out` is required to be memory contiguous
    (either C or Fortran ordered).

Returns
-------
arr : ndarray, 2-D
    An array with the same shape and containing the same
    data represented by the sparse array/matrix, with the requested
    memory order. If `out` was passed, the same object is
    returned after being modified in-place to contain the
    appropriate values.
Fr   r  )r   r  r  s      r   r  _spbase.toarray  s#    < zzuz%--E-CCr   c                 :    U R                  US9R                  SS9$ )zConvert this array/matrix to Compressed Sparse Row format.

With copy=False, the data/indices may be shared between this array/matrix and
the resultant csr_array/matrix.
r   F)r   r   r  s     r   r   _spbase.tocsr  #     zztz$***66r   c                 :    U R                  US9R                  SS9$ )zConvert this array/matrix to Dictionary Of Keys format.

With copy=False, the data/indices may be shared between this array/matrix and
the resultant dok_array/matrix.
r   F)r   todokr  s     r   r  _spbase.todok  r  r   c                 :    U R                  SS9R                  US9$ )zConvert this array/matrix to COOrdinate format.

With copy=False, the data/indices may be shared between this array/matrix and
the resultant coo_array/matrix.
Fr   )r   r   r  s     r   r   _spbase.tocoo  #     zzuz%+++66r   c                 :    U R                  SS9R                  US9$ )zConvert this array/matrix to List of Lists format.

With copy=False, the data/indices may be shared between this array/matrix and
the resultant lil_array/matrix.
Fr   )r   tolilr  s     r   r  _spbase.tolil  r	  r   c                 :    U R                  US9R                  SS9$ )zConvert this array/matrix to sparse DIAgonal format.

With copy=False, the data/indices may be shared between this array/matrix and
the resultant dia_array/matrix.
r   F)r   todiar  s     r   r  _spbase.todia'  r  r   c                 :    U R                  SS9R                  XS9$ )a  Convert this array/matrix to Block Sparse Row format.

With copy=False, the data/indices may be shared between this array/matrix and
the resultant bsr_array/matrix.

When blocksize=(R, C) is provided, it will be used for construction of
the bsr_array/matrix.
Fr   )	blocksizer   )r   tobsr)rU   r  r   s      r   r  _spbase.tobsr/  s#     zzuz%++i+KKr   c                 :    U R                  US9R                  SS9$ )zConvert this array/matrix to Compressed Sparse Column format.

With copy=False, the data/indices may be shared between this array/matrix and
the resultant csc_array/matrix.
r   F)r   tocscr  s     r   r  _spbase.tocsc:  r  r   c                 "    U R                  U SS9$ )zzReturns a copy of this array/matrix.

No data/indices will be shared between the returned value and current
array/matrix.
Tr   )r   rT   s    r   r   _spbase.copyB  s     ~~d~..r   c                 X   [        U5        [        U R                  5      nU R                  S:X  aB  US;  a  [	        S5      eU [
        R                  " U R                  US9-  nUR                  X#S9$ U R                  u  pgUc5  X R                  [
        R                  " US4US95      -  R                  X#S9$ US:  a  US-  nUS:X  a*  U R                  [
        R                  " SU4US95      U -  nO(X R                  [
        R                  " US4US95      -  nUR                  XUS9$ )	a  
Sum the array/matrix elements over a given axis.

Parameters
----------
axis : {-2, -1, 0, 1, None} optional
    Axis along which the sum is computed. The default is to
    compute the sum of all the array/matrix elements, returning a scalar
    (i.e., `axis` = `None`).
dtype : dtype, optional
    The type of the returned array/matrix and of the accumulator in which
    the elements are summed.  The dtype of `a` is used by default
    unless `a` has an integer dtype of less precision than the default
    platform integer.  In that case, if `a` is signed then the platform
    integer is used while if `a` is unsigned then an unsigned integer
    of the same precision as the platform integer is used.

    .. versionadded:: 0.18.0

out : np.matrix, optional
    Alternative output matrix in which to place the result. It must
    have the same shape as the expected output, but the type of the
    output values will be cast if necessary.

    .. versionadded:: 0.18.0

Returns
-------
sum_along_axis : np.matrix
    A matrix with the same shape as `self`, with the specified
    axis removed.

See Also
--------
numpy.matrix.sum : NumPy's implementation of 'sum' for matrices

r   NrY   r   axis must be None, -1 or 0r2  r   r  r   r'   r   r   r  )
r   r   r   rV   r   r   onesr   sumr   )	rU   r   r   r  	res_dtyperesr~  r  r  s	            r   r  _spbase.sumJ  s.   L 	T "$**-	99>=( !=>>9==C77700
 zz< ((!Qy)IJJcc'( !8AID 19##Ai0C
 **Ai0 C wwD3w77r   c                 j   [        U5        U R                  R                  n[        R                  " U R                  [        R
                  5      =(       d/    [        R                  " U R                  [        R                  5      nUc  U(       a  [        R                  nO [        R                  " U5      R                  nU(       a  [        R                  OUnU R                  U5      nU R                  S:X  a1  US;  a  [        S5      eXpR                  S   -  nUR                  XCS9$ Uc.  XpR                  S   U R                  S   -  -  R                  XCS9$ US:  a  US-  nUS:X  a#  USU R                  S   -  -  R                  SXCS	9$ USU R                  S   -  -  R                  SXCS	9$ )
a  
Compute the arithmetic mean along the specified axis.

Returns the average of the array/matrix elements. The average is taken
over all elements in the array/matrix by default, otherwise over the
specified axis. `float64` intermediate and return values are used
for integer inputs.

Parameters
----------
axis : {-2, -1, 0, 1, None} optional
    Axis along which the mean is computed. The default is to compute
    the mean of all elements in the array/matrix (i.e., `axis` = `None`).
dtype : data-type, optional
    Type to use in computing the mean. For integer inputs, the default
    is `float64`; for floating point inputs, it is the same as the
    input dtype.

    .. versionadded:: 0.18.0

out : np.matrix, optional
    Alternative output matrix in which to place the result. It must
    have the same shape as the expected output, but the type of the
    output values will be cast if necessary.

    .. versionadded:: 0.18.0

Returns
-------
m : np.matrix

See Also
--------
numpy.matrix.mean : NumPy's implementation of 'mean' for matrices

r   r  r  rY   r  r   r'   r  r  )r   r   r   r   r  r  bool_r  r   rV   r   r   r  )	rU   r   r   r  r   integralinter_dtype
inter_selfr!  s	            r   mean_spbase.mean  s   J 	TJJOO	MM$**bjj9 8MM$**bhh7 	 =JJ	,,I %-bjj)[[-
99>=( !=>>zz"~-C77744<**Q-$**Q-"?@9./ !8AID 19#

1"56;;i < 2 2 #

1"56;;i < 2 2r   c                 <    U R                  5       R                  US9$ )a  Returns the kth diagonal of the array/matrix.

Parameters
----------
k : int, optional
    Which diagonal to get, corresponding to elements a[i, i+k].
    Default: 0 (the main diagonal).

    .. versionadded:: 1.0

See also
--------
numpy.diagonal : Equivalent numpy function.

Examples
--------
>>> from scipy.sparse import csr_array
>>> A = csr_array([[1, 2, 0], [0, 0, 3], [4, 0, 5]])
>>> A.diagonal()
array([1, 0, 5])
>>> A.diagonal(k=1)
array([2, 3])
k)r   diagonal)rU   r,  s     r   r-  _spbase.diagonal  s    0 zz|$$q$))r   c                 <    U R                  US9R                  5       $ )zReturns the sum along diagonals of the sparse array/matrix.

Parameters
----------
offset : int, optional
    Which diagonal to get, corresponding to elements a[i, i+offset].
    Default: 0 (the main diagonal).

r+  )r-  r  )rU   offsets     r   trace_spbase.trace  s     }}v}&**,,r   c                     U R                   u  p4US:  a  X$:  d  US:  a  U* U:  a  [        S5      eU R                  [        R                  " U5      U5        g)a"  
Set diagonal or off-diagonal elements of the array/matrix.

Parameters
----------
values : array_like
    New values of the diagonal elements.

    Values may have any length. If the diagonal is longer than values,
    then the remaining diagonal entries will not be set. If values are
    longer than the diagonal, then the remaining values are ignored.

    If a scalar value is given, all of the diagonal is set to it.

k : int, optional
    Which off-diagonal to set, corresponding to elements a[i,i+k].
    Default: 0 (the main diagonal).

r   zk exceeds array dimensionsN)r   r   _setdiagr   r   )rU   valuesr,  r~  r  s        r   setdiag_spbase.setdiag  sK    ( zzEaf!a%QB!G9::bjj(!,r   c                 
   U R                   u  p4US:  ax  UR                  S:X  a)  [        X2-   U5      n[        U5       H  nXXb-
  U4'   M     g[        X2-   U[	        U5      5      nUS::  a  g[        USU 5       H  u  pgXpXb-
  U4'   M     gUR                  S:X  a)  [        X4U-
  5      n[        U5       H  nXXfU-   4'   M     g[        X4U-
  [	        U5      5      nUS::  a  g[        USU 5       H  u  pgXpXfU-   4'   M     g)zJThis part of the implementation gets overridden by the
different formats.
r   N)r   rV   minr   rR   	enumerate)rU   r5  r,  r~  r  	max_indexr  vs           r   r4  _spbase._setdiag!  s    zzq5{{aQK	y)A%+N *  QF4	>%fZi&89DA%&N : {{aQ3K	y)A%+EN *  Q3F4	>%fZi&89DA%&EN :r   c                    UbT  Ub  [        S5      eUR                  U R                  :w  d  UR                  U R                  :w  a  [        S5      eSUS'   U$ [        R                  " U R                  U R                  US9$ )Nz,order cannot be specified if out is not Nonez6out array must be same dtype and shape as sparse arrayg        .)r   r   )r   r   r   r   zerosr  s      r   _process_toarray_args_spbase._process_toarray_args?  sy    ?   "/ 0 0yyDJJ&#))tzz*A  "0 1 1CHJ88DJJdjjFFr   c                 Z    SSK Jn  U" UUU=(       a    [        U [        5      (       + 5      $ )aQ  
Determine index dtype for array.

This wraps _sputils.get_index_dtype, providing compatibility for both
array and matrix API sparse matrices. Matrix API sparse matrices would
attempt to downcast the indices - which can be computationally
expensive and undesirable for users. The array API changes this
behaviour.

See discussion: https://github.com/scipy/scipy/issues/16774

The get_index_dtype import is due to implementation details of the test
suite. It allows the decorator ``with_64bit_maxval_limit`` to mock a
lower int32 max value for checks on the matrix API's downcasting
behaviour.
r   )get_index_dtype)_sputilsrC  r   r   )rU   arraysmaxvalcheck_contentsrC  s        r   _get_index_dtype_spbase._get_index_dtypeL  s/    " 	. v% . Pz$7P3PS 	Sr   )rS   r   )unsafeTrQ   )F)r   )FF)NF)T)NN)NNN)r   NF)ur   r   r   r   __doc____array_priority__r   	_allow_ndpropertyintrV   r[   r`   rf   rk   rp   ru   rz   r   r   r   r   r   r   classmethodr   r   r   r   r   r   r   r   r   strr   r   r   r   r   r  r  __nonzero__r  r   r#  r(  r,  r/  r3  r7  r:  r>  rA  rD  rG  rJ  rN  rS  rV  rZ  r]  rb  re  rk  rn  rq  rt  r  r  r  r"  rx  rz  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r   r   r  r  r  ra  r  r   r  r   r  r  r  r  r   r  r(  r-  r1  r6  r4  r@  rH  r   r   r   r   rM   rM   =   sw    GI c     0 0               *. 	C  )MV@6> ) ) ' ' 8StL S   c             
4N K
((N,++ $2;******!4/./&&""#" 
"\?|$$/272#$,-*"X55(+F>.) $$DL$$7(&#LE<DF77777	L7/K8ZI2V*4
--2'<GSr   rM   c                       \ rS rSrSrSrg)r   ie  z3A namespace class to separate sparray from spmatrixr   N)r   r   r   r   rK  r   r   r   r   r   r   e  s    =r   r   c                 "    [        U [        5      $ )ak  Is `x` of a sparse array or sparse matrix type?

Parameters
----------
x
    object to check for being a sparse array or sparse matrix

Returns
-------
bool
    True if `x` is a sparse array or a sparse matrix, False otherwise

Notes
-----
Use `isinstance(x, sp.sparse.sparray)` to check between an array or matrix.
Use `a.format` to check the sparse format, e.g. `a.format == 'csr'`.

Examples
--------
>>> import numpy as np
>>> from scipy.sparse import csr_array, csr_matrix, issparse
>>> issparse(csr_matrix([[5]]))
True
>>> issparse(csr_array([[5]]))
True
>>> issparse(np.array([[5]]))
False
>>> issparse(5)
False
)r   rM   xs    r   r   r   l  s    > a!!r   c                 "    [        U [        5      $ )a  Is `x` of a sparse matrix type?

Parameters
----------
x
    object to check for being a sparse matrix

Returns
-------
bool
    True if `x` is a sparse matrix, False otherwise

Examples
--------
>>> import numpy as np
>>> from scipy.sparse import csr_array, csr_matrix, isspmatrix
>>> isspmatrix(csr_matrix([[5]]))
True
>>> isspmatrix(csr_array([[5]]))
False
>>> isspmatrix(np.array([[5]]))
False
>>> isspmatrix(5)
False
)r   r   rU  s    r   r   r     s    4 a""r   ).rK  numpyr   rD  r   r   r   r   r   r	   r
   r   r   _matrixr   __all__Warningr   r    r   r   	frozensetsintanarcsinarctansinhtanharcsinharctanhrintsignexpm1log1pdeg2radrad2degfloorceiltruncsqrt _ufuncs_with_fixed_point_at_zeror   rM   r   r   r   r   r   r   <module>rp     sR   $ 7 7 7 7	G 		- 		m 	
EA12 A./A+, A' A34	
 A12 A|$ A'( A<= Az? B*+ B89 B-. B;< B+, B./  B)*!" 45,-$'0 $-
		299bggrww




BGGRWWbhh"**


BHHbggrxx.: $;   eS eSP)> > //"D#r   