
    (phP                         S r SSKrSSKrSSKJrJrJr  SSKJ	r	J
r
  / r " S S\5      r\ H"  r\R                  rS r\" \\\" \5      5        M$     S	 r " S
 S5      rg)zBase class for sparse matrice with a .data attribute

subclasses must provide a _with_data() method that
creates a new matrix with the same sparsity pattern
as self but with a different data array

    N   )_spbasesparray _ufuncs_with_fixed_point_at_zero)isscalarlikevalidateaxisc                   V   \ rS rSrSS.S jr\S 5       r\R                  S 5       rS rS r	SS	 jr
S
 rS rS rS rS rSS jr\R                   R$                  \l        SS jr\R&                  R$                  \l        S r\R(                  R$                  \l        SS jrS rSrg)_data_matrix   Nmaxprintc                .    [         R                  " XUS9  g )Nr   )r   __init__)selfarg1r   s      E/var/www/html/venv/lib/python3.13/site-packages/scipy/sparse/_data.pyr   _data_matrix.__init__   s    h7    c                 .    U R                   R                  $ Ndatadtyper   s    r   r   _data_matrix.dtype   s    yyr   c                 $    XR                   l        g r   r   )r   newtypes     r   r   r      s    !		r   c                 \    [        U S5      (       a  U R                  5         U R                  $ )Nsum_duplicates)hasattrr   r   r   s    r   _deduped_data_data_matrix._deduped_data    s&    4)**!yyr   c                 R    U R                  [        U R                  5       5      5      $ r   )
_with_dataabsr!   r   s    r   __abs___data_matrix.__abs__%   s    s4#5#5#7899r   c                 f    U R                  [        R                  " U R                  5       US95      $ )N)decimals)r$   nparoundr!   )r   ndigitss     r   	__round___data_matrix.__round__(   s%    ryy););)=PQQr   c                 L    U R                  U R                  R                  5      $ r   )r$   r   realr   s    r   _real_data_matrix._real+       tyy~~..r   c                 L    U R                  U R                  R                  5      $ r   )r$   r   imagr   s    r   _imag_data_matrix._imag.   r3   r   c                     U R                   R                  S:X  a  [        S5      eU R                  U R                  * 5      $ )Nbz0negating a boolean sparse array is not supported)r   kindNotImplementedErrorr$   r   r   s    r   __neg___data_matrix.__neg__1   s9    ::??c!% '2 3 3		z**r   c                 \    [        U5      (       a  U =R                  U-  sl        U $ [        $ r   r   r   NotImplementedr   others     r   __imul___data_matrix.__imul__7   s&    IIIKr   c                 f    [        U5      (       a  SU-  nU =R                  U-  sl        U $ [        $ )Ng      ?r?   )r   rB   recips      r   __itruediv___data_matrix.__itruediv__=   s/    %KEIIIK!!r   c                    [         R                  " U5      nU R                  U:w  aF  U R                  U R                  R	                  XSS9SS9nUR                  UR                  5       SS9$ U(       a  U R                  5       $ U $ )NT)castingcopyrK   F)r*   r   r$   r   astyper!   rK   )r   r   rJ   rK   matrixs        r   rM   _data_matrix.astypeE   s}    ::__		  d C % F $$V%9%9%;%$HH99;Kr   c                     [         R                  " U R                  [         R                  5      (       a(  U R	                  U R
                  R                  5       US9$ U(       a  U R                  5       $ U $ )NrL   )r*   
issubdtyper   complexfloatingr$   r   	conjugaterK   )r   rK   s     r   rS   _data_matrix.conjugateT   sQ    ==R%7%788??499#6#6#8t?DD99;Kr   c                 R    U R                  U R                  R                  5       SS9$ NTrL   )r$   r   rK   r   s    r   rK   _data_matrix.copy^   s     tyy~~/d;;r   c                     [        U5      (       d  [        S5      eU(       d  [        S5      eU R                  5       nUb  UR                  U5      nU R	                  X1-  5      $ )a  
This function performs element-wise power.

Parameters
----------
n : scalar
    n is a non-zero scalar (nonzero avoids dense ones creation)
    If zero power is desired, special case it to use `np.ones`

dtype : If dtype is not specified, the current dtype will be preserved.

Raises
------
NotImplementedError : if n is a zero scalar
    If zero power is desired, special case it to use
    ``np.ones(A.shape, dtype=A.dtype)``
zinput is not scalarzpzero power is not supported as it would densify the matrix.
Use `np.ones(A.shape, dtype=A.dtype)` for this case.)r   r;   r!   rM   r$   )r   nr   r   s       r   power_data_matrix.powerc   sd    $ A%&;<<%G 
 !!#;;u%Dty))r   c                 >    U R                  U R                  U-  5      $ r   )r$   r   rA   s     r   _mul_scalar_data_matrix._mul_scalar   s    tyy5011r    )r   )unsafeT)Tr   )__name__
__module____qualname____firstlineno__r   propertyr   setterr!   r&   r-   r1   r6   r<   rC   rG   rM   r   __doc__rS   rK   rZ   r]   __static_attributes__r_   r   r   r
   r
      s    )- 8   \\" "
:R//+" ^^++FN  ))11I< <<''DL*F2r   r
   c                 V   ^  U 4S jnS[          S[          S3Ul        [         Ul        U$ )Nc                 P   > T" U R                  5       5      nU R                  USS9$ rV   )r!   r$   )r   resultops     r   method_create_method.<locals>.method   s)    **,-F??6?55r   zElement-wise z.

See `numpy.z` for more information.)namerg   ra   )rl   rm   s   ` r   _create_methodrp      s4    	6 *$ 0((,v-DFr   c                 V    [        U 5       H  u  p#X#:w  d  M  Us  $    WS-  nX!:  a  U$ g)Nr   )	enumerate)indrY   kas       r   _find_missing_indexrw      s4    #6H  FAur   c                       \ rS rSrSrS rS rS rS rSSS	.S
 jjr	SSS	.S jjr
SSS	.S jjrSSS	.S jjrSSS	.S jjrSSS	.S jjrSrg)_minmax_mixin   zdMixin for min and max methods.

These are not implemented for dia_matrix, hence the separate class.
c           	      r   U R                   U   nUS:X  a  [        S5      eU R                   SU-
     nU R                  US9nUS:X  a  U R                  5       OU R	                  5       nUR                  5         UR                  U5      u  pU(       d3  [        R                  " UR                  5      U   U:  n
U" X   S5      X'   U	S:g  n[        R                  " X5      R                  USS9n[        R                  " X5      n	[        U [        5      (       a!  U4nU4nU R                  X4XR                  S9$ US:X  a=  U R                  U	[        R                   " [#        U	5      US9U44U R                  SU4S	9$ U R                  X[        R                   " [#        U	5      US944U R                  US4S	9$ )
Nr   &zero-size array to reduction operationr   )maxvalFrL   )shaper   r   )r   r~   )r~   
ValueError_get_index_dtypetocsctocsrr   _minor_reducer*   diffindptrcompressrM   
isinstancer   _coo_containerr   zeroslen)r   axis
min_or_maxexplicitNM	idx_dtypematmajor_indexvaluenot_fullmaskcoordsr~   s                 r   _min_or_max_axis_minmax_mixin._min_or_max_axis   s   JJt6EFFJJq4x )))3	"aidjjlTZZ\ ..z:wwszz*;7!;H(!<EOzkk$4;;IE;RD(dG$$!^FDE&&e::&VV19&&#e*I>LMjjA '  
 &&bhhs5z&KLMjjA '  r   c                 P   Ub  [        S5      e[        U5        U R                  S:X  a  US;  a  [        S5      eS nUc  SU R                  ;   a  [        S5      eU R                  R                  S5      nU R                  S:X  a  U$ UR                  U R                  5       R                  5       5      nU R                  [        R                  " U R                  5      :w  a  U(       d  U" XV5      nU$ US:  a  US-  nUS:X  d  US:X  a  U R                  XU5      $ [        S5      e)Nz0Sparse arrays do not support an 'out' parameter.r   Nr   rr   axis out of ranger   r|      )r   r   ndimr~   r   typennzreducer!   ravelmathprodr   )r   r   outr   r   zeroms          r   _min_or_max_minmax_mixin._min_or_max   s   ?OPPT99>=( !455D<DJJ !IJJ::??1%Dxx1}!!$"4"4"6"<"<">?Axx499TZZ00t'H!8AIDAI419((8DD011r   c                    U R                   U   S:X  a  [        S5      eUS:  a  US-  nU R                  R                  S5      nUS:X  a  U R	                  5       OU R                  5       nUR                  5         UR                  UR                   5      u  px[        R                  " U[        S9n	[        R                  " [        R                  " UR                  5      5      u  n
U
 H  nUR                  XS-    u  pUR                  X nUR                  X nU" U5      nUU   nU(       a  X-
  S:  a	  UU   X'   MW  MY  U" UU5      (       d  X-
  U:X  a	  UU   X'   Mx  [!        X5      nUU:X  a  [#        UU5      X'   M  UX'   M     [%        U [&        5      (       a  U	$ US:X  a  U	R)                  SS5      n	U R+                  U	5      $ )Nr   z8Cannot apply the operation along a zero-sized dimension.r   r   r   rr   )r~   r   r   r   r   r   r   _swapr*   r   intnonzeror   r   r   indicesrw   minr   r   reshape_ascontainer)r   r   argmin_or_argmaxcomparer   r   r   ret_size	line_sizeretnz_linesipqr   r   extreme_indexextreme_valuezero_inds                      r   _arg_min_or_max_axis"_minmax_mixin._arg_min_or_max_axis   s   ::dq WXX!8AIDzzq!"aidjjlTZZ\!ii		2hhxs+JJrwwszz23	A::aA&DA88A=Dkk!&G,T2M /M519$]3CF  =$//15I3E$]3CF27FH$,!$]H!=!)# & dG$$J19++b!$C  %%r   c                    Ub  [        S5      e[        U5        U R                  S:X  a  US;  a  [        S5      eS nUb  U R                  XXE5      $ SU R                  ;   a  [        S5      eU R
                  S:X  a  U(       a  [        S5      egU R                  R                  S5      nU R                  5       nUR                  5         U" UR                  5      nU(       a  U$ UR                  U   n	UR                  S   n
U" X5      (       a4  [        UR                  U   5      U
-  [        UR                  U   5      -   $ [        R                  " U R                  5      nXR
                  :X  a4  [        UR                  U   5      U
-  [        UR                  U   5      -   $ UR                  U
-  UR                  -   n[!        X5      nX:X  a  [#        X5      $ U$ )	Nz/Sparse types do not support an 'out' parameter.r   r   r   r   z.Cannot apply the operation to an empty matrix.z=Cannot apply the operation to zero matrix when explicit=True.rr   )r   r   r   r   r~   r   r   r   tocoor   r   r   rowcolr   r   rw   r   )r   r   r   r   r   r   r   r   r   r   num_colsizelinear_indicesfirst_implicit_zero_indexs                 r   _arg_min_or_max_minmax_mixin._arg_min_or_max  s   ?NOOT99>=( !455D,,TWWW

?MNN88q=  "7 8 8zzq!jjl(2  /))B- =''sww}-.83sww}?U;VVV yy$77?sww}-.83sww}?U;VVV
 7*SWW4$7$M! 0@@((r   NF)r   c                D    U R                  X[        R                  U5      $ )a  Return the maximum of the array/matrix or maximum along an axis.

By default, all elements are taken into account, not just the non-zero ones.
But with `explicit` set, only the stored elements are considered.

Parameters
----------
axis : {-2, -1, 0, 1, None} optional
    Axis along which the sum is computed. The default is to
    compute the maximum over all elements, returning
    a scalar (i.e., `axis` = `None`).

out : None, optional
    This argument is in the signature *solely* for NumPy
    compatibility reasons. Do not pass in anything except
    for the default value, as this argument is not used.

explicit : {False, True} optional (default: False)
    When set to True, only the stored elements will be considered.
    If a row/column is empty, the sparse.coo_array returned
    has no stored element (i.e. an implicit zero) for that row/column.

    .. versionadded:: 1.15.0

Returns
-------
amax : coo_array or scalar
    Maximum of `a`. If `axis` is None, the result is a scalar value.
    If `axis` is given, the result is a sparse.coo_array of dimension
    ``a.ndim - 1``.

See Also
--------
min : The minimum value of a sparse array/matrix along a given axis.
numpy.max : NumPy's implementation of 'max'

)r   r*   maximumr   r   r   r   s       r   max_minmax_mixin.maxO      L 2::x@@r   c                D    U R                  X[        R                  U5      $ )a  Return the minimum of the array/matrix or maximum along an axis.

By default, all elements are taken into account, not just the non-zero ones.
But with `explicit` set, only the stored elements are considered.

Parameters
----------
axis : {-2, -1, 0, 1, None} optional
    Axis along which the sum is computed. The default is to
    compute the minimum over all elements, returning
    a scalar (i.e., `axis` = `None`).

out : None, optional
    This argument is in the signature *solely* for NumPy
    compatibility reasons. Do not pass in anything except for
    the default value, as this argument is not used.

explicit : {False, True} optional (default: False)
    When set to True, only the stored elements will be considered.
    If a row/column is empty, the sparse.coo_array returned
    has no stored element (i.e. an implicit zero) for that row/column.

    .. versionadded:: 1.15.0

Returns
-------
amin : coo_matrix or scalar
    Minimum of `a`. If `axis` is None, the result is a scalar value.
    If `axis` is given, the result is a sparse.coo_array of dimension
    ``a.ndim - 1``.

See Also
--------
max : The maximum value of a sparse array/matrix along a given axis.
numpy.min : NumPy's implementation of 'min'

)r   r*   minimumr   s       r   r   _minmax_mixin.minw  r   r   c                D    U R                  X[        R                  U5      $ )a  Return the maximum, ignoring any Nans, along an axis.

Return the maximum, ignoring any Nans, of the array/matrix along an axis.
By default this takes all elements into account, but with `explicit` set,
only stored elements are considered.

.. versionadded:: 1.11.0

Parameters
----------
axis : {-2, -1, 0, 1, None} optional
    Axis along which the maximum is computed. The default is to
    compute the maximum over all elements, returning
    a scalar (i.e., `axis` = `None`).

out : None, optional
    This argument is in the signature *solely* for NumPy
    compatibility reasons. Do not pass in anything except
    for the default value, as this argument is not used.

explicit : {False, True} optional (default: False)
    When set to True, only the stored elements will be considered.
    If a row/column is empty, the sparse.coo_array returned
    has no stored element (i.e. an implicit zero) for that row/column.

    .. versionadded:: 1.15.0

Returns
-------
amax : coo_array or scalar
    Maximum of `a`. If `axis` is None, the result is a scalar value.
    If `axis` is given, the result is a sparse.coo_array of dimension
    ``a.ndim - 1``.

See Also
--------
nanmin : The minimum value of a sparse array/matrix along a given axis,
         ignoring NaNs.
max : The maximum value of a sparse array/matrix along a given axis,
      propagating NaNs.
numpy.nanmax : NumPy's implementation of 'nanmax'.

)r   r*   fmaxr   s       r   nanmax_minmax_mixin.nanmax      X 277H==r   c                D    U R                  X[        R                  U5      $ )a  Return the minimum, ignoring any Nans, along an axis.

Return the minimum, ignoring any Nans, of the array/matrix along an axis.
By default this takes all elements into account, but with `explicit` set,
only stored elements are considered.

.. versionadded:: 1.11.0

Parameters
----------
axis : {-2, -1, 0, 1, None} optional
    Axis along which the minimum is computed. The default is to
    compute the minimum over all elements, returning
    a scalar (i.e., `axis` = `None`).

out : None, optional
    This argument is in the signature *solely* for NumPy
    compatibility reasons. Do not pass in anything except for
    the default value, as this argument is not used.

explicit : {False, True} optional (default: False)
    When set to True, only the stored elements will be considered.
    If a row/column is empty, the sparse.coo_array returned
    has no stored element (i.e. an implicit zero) for that row/column.

    .. versionadded:: 1.15.0

Returns
-------
amin : coo_array or scalar
    Minimum of `a`. If `axis` is None, the result is a scalar value.
    If `axis` is given, the result is a sparse.coo_array of dimension
    ``a.ndim - 1``.

See Also
--------
nanmax : The maximum value of a sparse array/matrix along a given axis,
         ignoring NaNs.
min : The minimum value of a sparse array/matrix along a given axis,
      propagating NaNs.
numpy.nanmin : NumPy's implementation of 'nanmin'.

)r   r*   fminr   s       r   nanmin_minmax_mixin.nanmin  r   r   c                b    U R                  X[        R                  [        R                  U5      $ )a*  Return indices of maximum elements along an axis.

By default, implicit zero elements are taken into account. If there are
several minimum values, the index of the first occurrence is returned.
If `explicit` is set, only explicitly stored elements will be considered.

Parameters
----------
axis : {-2, -1, 0, 1, None}, optional
    Axis along which the argmax is computed. If None (default), index
    of the maximum element in the flatten data is returned.

out : None, optional
    This argument is in the signature *solely* for NumPy
    compatibility reasons. Do not pass in anything except for
    the default value, as this argument is not used.

explicit : {False, True} optional (default: False)
    When set to True, only explicitly stored elements will be considered.
    If axis is not None and a row/column has no stored elements, argmax
    is undefined, so the index ``0`` is returned for that row/column.

    .. versionadded:: 1.15.0

Returns
-------
ind : numpy.matrix or int
    Indices of maximum elements. If matrix, its size along `axis` is 1.
)r   r*   argmaxgreaterr   s       r   r   _minmax_mixin.argmax  s#    < ##Dryy"**hOOr   c                b    U R                  X[        R                  [        R                  U5      $ )a+  Return indices of minimum elements along an axis.

By default, implicit zero elements are taken into account. If there are
several minimum values, the index of the first occurrence is returned.
If `explicit` is set, only explicitly stored elements will be considered.

Parameters
----------
axis : {-2, -1, 0, 1, None}, optional
    Axis along which the argmin is computed. If None (default), index
    of the minimum element in the flatten data is returned.

out : None, optional
    This argument is in the signature *solely* for NumPy
    compatibility reasons. Do not pass in anything except for
    the default value, as this argument is not used.

explicit : {False, True} optional (default: False)
    When set to True, only explicitly stored elements will be considered.
    If axis is not None and a row/column has no stored elements, argmin
    is undefined, so the index ``0`` is returned for that row/column.

    .. versionadded:: 1.15.0

Returns
-------
 ind : numpy.matrix or int
    Indices of minimum elements. If matrix, its size along `axis` is 1.
)r   r*   argminlessr   s       r   r   _minmax_mixin.argmin  s#    < ##Dryy"''8LLr   r_   )NN)ra   rb   rc   rd   rg   r   r   r   r   r   r   r   r   r   r   rh   r_   r   r   ry   ry      sy    
!F2<)&V3)j&A5 &AP&A5 &AP,>e ,>\,>e ,>\Pe P@Me M Mr   ry   )rg   r   numpyr*   _baser   r   r   _sputilsr   r   __all__r
   npfuncra   ro   rp   setattrrw   ry   r_   r   r   <module>r      so      E E 0

s27 s2n /F??D	 L$v 67 /"	QM QMr   