
    `iC                         d dl Z d dlZd dlmZ d dlmZ d dlmZ 	 d dlmZ ej	        Z	ej
        Z
n'# e$ r  G d de          Z	 G d de	          Z
Y nw xY w G d	 d
e          Zd Zej        ZeZdS )    N)_core)_util)_sputilsc                       e Zd ZdS )SparseWarningN__name__
__module____qualname__     l/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupyx/scipy/sparse/_base.pyr   r              r   r   c                       e Zd ZdS )SparseEfficiencyWarningNr   r   r   r   r   r      r   r   r   c                      e Zd ZdZdZdTdZed             ZdUdZd Z	d	 Z
d
 Zd ZeZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'ed&             Z(ed'             Z)ed(             Z*ed)             Z+ed*             Z,ed+             Z-ed,             Z.e.j/        d-             Z.d. Z0d/ Z1d0 Z2dVd2Z3dVd3Z4e3j        e4_        d4 Z5d5 Z6dWd7Z7d8 Z8d9 Z9d: Z:d; Z;d< Z<dUd=Z=d> Z>dXd?Z?d@ Z@dA ZAdUdBZBdCdDdEZCdF ZDdWdGZEdXdHZFdYdIZGdZdKZHd[dLZId[dMZJd[dNZKdYdOZLd[dPZMd[dQZNd[dRZOdZdSZPdS )\spmatrixzOBase class of all sparse matrixes.

    See :class:`scipy.sparse.spmatrix`
    e   2   c                 R    | j         t          k    rt          d          || _        d S )Nz7This class is not intended to be instantiated directly.)	__class__r   
ValueErrormaxprint)selfr   s     r   __init__zspmatrix.__init__!   s2    >X%%IK K K r   c                     t           )z(CUDA device on which this array resides.NotImplementedErrorr   s    r   devicezspmatrix.device'   s
     "!r   Nc                     t           )a.  Return a copy of the array on host memory.

        Args:
            stream (cupy.cuda.Stream): CUDA stream object. If it is given, the
                copy runs asynchronously. Otherwise, the copy is synchronous.

        Returns:
            scipy.sparse.spmatrix: An array on host memory.

        r   )r   streams     r   getzspmatrix.get,   s
     "!r   c                      t          d          )Nz;sparse matrix length is ambiguous; use getnnz() or shape[0])	TypeErrorr   s    r   __len__zspmatrix.__len__9   s     3 4 4 	4r   c                 D    t          |                                           S N)strr#   r   s    r   __str__zspmatrix.__str__=   s     488::r   c              #   `   K   t          | j        d                   D ]}| |d d f         V  d S Nr   )rangeshape)r   rs     r   __iter__zspmatrix.__iter__B   sH      tz!}%% 	 	Aq!!!t*	 	r   c                 L    | j         dk    r| j        dk    S t          d          )N)   r2   r   z\The truth value of an array with more than one element is ambiguous. Use a.any() or a.all().)r.   nnzr   r   s    r   __bool__zspmatrix.__bool__F   s6    :8q=  M N N Nr   c                 P    |                                                      |          S r(   )tocsr__eq__r   others     r   r7   zspmatrix.__eq__O       zz||""5)))r   c                 P    |                                                      |          S r(   )r6   __ne__r8   s     r   r<   zspmatrix.__ne__R   r:   r   c                 P    |                                                      |          S r(   )r6   __lt__r8   s     r   r>   zspmatrix.__lt__U   r:   r   c                 P    |                                                      |          S r(   )r6   __gt__r8   s     r   r@   zspmatrix.__gt__X   r:   r   c                 P    |                                                      |          S r(   )r6   __le__r8   s     r   rB   zspmatrix.__le__[   r:   r   c                 P    |                                                      |          S r(   )r6   __ge__r8   s     r   rD   zspmatrix.__ge__^   r:   r   c                 N    |                                                                  S r(   )r6   __abs__r   s    r   rF   zspmatrix.__abs__a   s    zz||##%%%r   c                 P    |                                                      |          S r(   )r6   __add__r8   s     r   rH   zspmatrix.__add__d       zz||##E***r   c                 P    |                                                      |          S r(   )r6   __radd__r8   s     r   rK   zspmatrix.__radd__g       zz||$$U+++r   c                 P    |                                                      |          S r(   )r6   __sub__r8   s     r   rN   zspmatrix.__sub__j   rI   r   c                 P    |                                                      |          S r(   )r6   __rsub__r8   s     r   rP   zspmatrix.__rsub__m   rL   r   c                 P    |                                                      |          S r(   )r6   __mul__r8   s     r   rR   zspmatrix.__mul__p   rI   r   c                     t          j        |          st          |          r|j        dk    r| |z  S 	 |j        }n# t
          $ r
 t          cY S w xY w| j        |z  j        S r,   )cupyisscalarisdensendimTAttributeErrorNotImplemented)r   r9   trs      r   __rmul__zspmatrix.__rmul__s   sx    = 	#75>> 	#ejAoo%<&W! & & &%%%%&FRK?"s   = AAc                 r    t          j        |          rt          d          |                     |          S Nz0Scalar operands are not allowed, use '*' instead)r   isscalarliker   rR   r8   s     r   
__matmul__zspmatrix.__matmul__~   s>    e$$ 	2 1 2 2 2||E"""r   c                 r    t          j        |          rt          d          |                     |          S r^   )r   r_   r   r\   r8   s     r   __rmatmul__zspmatrix.__rmatmul__   s>    e$$ 	2 1 2 2 2}}U###r   c                 P    |                                                      |          S r(   )r6   __div__r8   s     r   rd   zspmatrix.__div__   rI   r   c                 P    |                                                      |          S r(   )r6   __rdiv__r8   s     r   rf   zspmatrix.__rdiv__   rL   r   c                 P    |                                                      |          S r(   )r6   __truediv__r8   s     r   rh   zspmatrix.__truediv__   s    zz||''...r   c                 P    |                                                      |          S r(   )r6   __rtruediv__r8   s     r   rj   zspmatrix.__rtruediv__   s    zz||((///r   c                 ,    |                                   S r(   )r6   r   s    r   __neg__zspmatrix.__neg__   s    

}r   c                     t           S r(   rZ   r8   s     r   __iadd__zspmatrix.__iadd__       r   c                     t           S r(   rn   r8   s     r   __isub__zspmatrix.__isub__   rp   r   c                     t           S r(   rn   r8   s     r   __imul__zspmatrix.__imul__   rp   r   c                 ,    |                      |          S r(   )__itruediv__r8   s     r   __idiv__zspmatrix.__idiv__   s      '''r   c                     t           S r(   rn   r8   s     r   rv   zspmatrix.__itruediv__   rp   r   c                    | j         \  }}||k    rt          d          t          j        |          rt	          |          }|dk     rt          d          |dk    r+ddl}|j        j        	                    || j
        d          S |dk    r|                                 S |                     |dz            }|dz  r| |z  |z  S ||z  S t          j        |          rt          d	          t          S )
as  Calculates n-th power of the matrix.

        This method calculates n-th power of a given matrix. The matrix must
        be a squared matrix, and a given exponent must be an integer.

        Args:
            other (int): Exponent.

        Returns:
            cupyx.scipy.sparse.spmatrix: A sparse matrix representing n-th
            power of this matrix.

        zmatrix is not squarer   zexponent must be >= 0Ncsr)dtypeformatr2      zexponent must be an integer)r.   r%   r   	isintlikeintr   cupyx.scipy.sparsescipysparseidentityr{   copy__pow__r_   rZ   )r   r9   mncupyxtmps         r   r   zspmatrix.__pow__   s    z1662333?5!! 	"JJEqyy !8999zz)))){)22TZ 3 7 7 7!yy{{"ll5A:..19 %#:++9$&& 	":;;;!!r   c                 *    |                                  S )zDense ndarray representation of this matrix.

        This property is equivalent to
        :meth:`~cupyx.scipy.sparse.spmatrix.toarray` method.

        toarrayr   s    r   Az
spmatrix.A   s     ||~~r   c                 *    |                                  S r(   )	transposer   s    r   rX   z
spmatrix.T       ~~r   c                 *    |                                  S r(   )getHr   s    r   Hz
spmatrix.H   s    yy{{r   c                     dS )Nr}   r   r   s    r   rW   zspmatrix.ndim   s    qr   c                 *    |                                  S r(   getnnzr   s    r   sizezspmatrix.size       {{}}r   c                 *    |                                  S r(   r   r   s    r   r3   zspmatrix.nnz   r   r   c                 *    |                                  S r(   )	get_shaper   s    r   r.   zspmatrix.shape   r   r   c                 0    |                      |           d S r(   )	set_shape)r   values     r   r.   zspmatrix.shape   s    ur   c                 V    ||| j         k    r| S  t          | d|z                         S )zwReturn this matrix in a given sparse format.

        Args:
            format (str or None): Format you need.
        Nto)r|   getattr)r   r|   s     r   asformatzspmatrix.asformat   s6     >Vt{22K/74//111r   c                     | j         j        dk    r| S t          j        | j         d          }|                     |          S )a&  Upcasts matrix to a floating point format.

        When the matrix has floating point type, the method returns itself.
        Otherwise it makes a copy with floating point type and the same format.

        Returns:
            cupyx.scipy.sparse.spmatrix: A matrix with float type.

        f)r{   kindnumpypromote_typesastype)r   typs     r   asfptypezspmatrix.asfptype  s>     :?c!!K%dj#66C;;s###r   c                     |                                                      |                              | j                  S )zCasts the array to given data type.

        Args:
            t: Type specifier.

        Returns:
            cupyx.scipy.sparse.spmatrix:
                A copy of the array with the given type and the same format.

        )r6   r   r   r|   )r   ts     r   r   zspmatrix.astype  s0     zz||""1%%..t{;;;r   Tc                     | j         j        dk    r*|                     |                              d          S |r|                                 S | S )a  Element-wise complex conjugation.

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

        Args:
            copy (bool):
                If True, the result is guaranteed to not share data with self.

        Returns:
            cupyx.scipy.sparse.spmatrix : The element-wise complex conjugate.

        cr   F)r{   r   r6   conjr   r   r   s     r   r   zspmatrix.conj  sS     :?c!!::4:((--5-999 	99;;Kr   c                 .    |                      |          S )Nr   )r   r   s     r   	conjugatezspmatrix.conjugate3  s    yydy###r   c                 0    |                      | d          S )zReturns a copy of this matrix.

        No data/indices will be shared between the returned value and current
        matrix.
        Tr   )r   r   s    r   r   zspmatrix.copy8  s     ~~d~...r   c                     t           )z)Number of non-zero entries, equivalent tor   r   s    r   count_nonzerozspmatrix.count_nonzero@      !!r   r   c                 R    |                                                      |          S )a  Returns the k-th diagonal of the matrix.

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

        Returns:
            cupy.ndarray : The k-th diagonal.
        )k)r6   diagonal)r   r   s     r   r   zspmatrix.diagonalD  s#     zz||$$q$)))r   c                 >    t          j        |          r| |z  S | |z  S )zOrdinary dot product)r   rU   r8   s     r   dotzspmatrix.dotP  s(    >%   	 %<%<r   c                 N    |                                                                  S r(   )r   r   r   s    r   r   zspmatrix.getHW  s    ~~$$&&&r   c                     t           r(   r   r   s    r   r   zspmatrix.get_shapeZ  s    !!r   c                     | j         S r(   )r|   r   s    r   	getformatzspmatrix.getformat_  s
    {r   c                     | j         S r(   )r   r   s    r   getmaxprintzspmatrix.getmaxprintb  s
    }r   c                     t           )z2Number of stored values, including explicit zeros.r   )r   axiss     r   r   zspmatrix.getnnze  r   r   c                 P    |                                                      |          S r(   )r6   maximumr8   s     r   r   zspmatrix.maximumk  rI   r   c                 Z   d }t          j        |           | j        j        } || j                  }||rt          j        }nt	          j        |          j        }|rt          j        n|}|                     |          }|E|t	          j        | j        d         | j        d         z            z  	                    ||          S |dk     r|dz  }|dk    r)|d| j        d         z  z  	                    d||          S |d| j        d         z  z  	                    d||          S )	a  
        Compute the arithmetic mean along the specified axis.

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

        Args:
            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 matrix
                (i.e., `axis` = `None`).
            dtype (dtype): 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.
            out (cupy.ndarray): 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.

        Returns:
            m (cupy.ndarray) : Output array of means

        .. seealso::
            :meth:`scipy.sparse.spmatrix.mean`

        c                 ~    t          j        | t           j                  pt          j        | t           j                  S r(   )rT   
issubdtypeintegerbool_r{   s    r   _is_integralz#spmatrix.mean.<locals>._is_integral  s.    OE4<88 7OE4:668r   Nr   r2   r{   outr}   g      ?)r   r{   r   )
r   validateaxisr{   typerT   float64r   arrayr.   sum)	r   r   r{   r   r   	res_dtypeintegralinter_dtype
inter_selfs	            r   meanzspmatrix.meann  sX   <	8 	8 	8 	d###JO	<
++ = ) L	
5)).I '/=dllI[[--
<
1
1-"/ "/ /9#../ !88AID 199#
1"56;;iS < 2 2 2 #
1"56;;iS < 2 2 2r   c                 P    |                                                      |          S r(   )r6   minimumr8   s     r   r   zspmatrix.minimum  rI   r   c                 P    |                                                      |          S )z+Point-wise multiplication by another matrix)r6   multiplyr8   s     r   r   zspmatrix.multiply  s    zz||$$U+++r   c                 T    |                                                      ||          S )Nr   )r6   power)r   r   r{   s      r   r   zspmatrix.power  s#    zz||!!!5!111r   Corderc                    t          j        || j                  }|| j        k    r| S |                                                     ||          S )a5  Gives a new shape to a sparse matrix without changing its data.

        Args:
            shape (tuple):
                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. 'F' means to read
                and write the elements using Fortran-like index order. Default:
                C.

        Returns:
            cupyx.scipy.sparse.coo_matrix: sparse matrix

        r   )r   check_shaper.   tocooreshape)r   r   r.   s      r   r   zspmatrix.reshape  sK      $UDJ77DJKzz||##E#777r   c                 0    |                      |           d S r(   )r   )r   r.   s     r   r   zspmatrix.set_shape  s    Ur   c                     t           )ar  Set diagonal or off-diagonal elements of the array.

        Args:
            values (cupy.ndarray): 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 is 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 diagonal to set, corresponding to elements
                a[i, i+k]. Default: 0 (the main diagonal).
        r   )r   valuesr   s      r   setdiagzspmatrix.setdiag  s
     "!r   c                    t          j        |           | j        \  }}|C|                     t	          j        || j                                                ||          S |dk     r|dz  }|dk    rH| j                            t	          j        || j                            	                    d|          }nB|                     t	          j        || j                            	                    |d          }|6|j        |j        k    rt          d          t          j        ||           |S ||                    |d	          S |S )
a/  Sums the matrix elements over a given axis.

        Args:
            axis (int or ``None``): Axis along which the sum is computed.
                If it is ``None``, it computes the sum of all the elements.
                Select from ``{None, 0, 1, -2, -1}``.
            dtype: The type of returned matrix. If it is not specified, type
                of the array is used.
            out (cupy.ndarray): Output matrix.

        Returns:
            cupy.ndarray: Summed array.

        .. seealso::
           :meth:`scipy.sparse.spmatrix.sum`

        Nr   r   r   r}   r2   zdimensions do not matchFr   )r   r   r.   r   rT   onesr{   r   rX   r   r   r   elementwise_copyr   )r   r   r{   r   r   r   rets          r   r   zspmatrix.sum  sH   $ 	d###
 z1<88DIatz:::;;?? @ & & & !88AID199&**TYq
;;;<<DDQJJCC((49Qdj999::BB1aHHC?yCI%% !:;;;"3,,,J::e%:000Jr   c                 T    |                                                      ||          S )z5Return a dense ndarray representation of this matrix.r   r   )r6   r   r   r   r   s      r   r   zspmatrix.toarray  s#    zz||##%S#999r   Fc                 V    |                      |                              d          S )z/Convert this matrix to Block Sparse Row format.r   F)r6   tobsr)r   	blocksizer   s      r   r   zspmatrix.tobsr  '    zztz$$***666r   c                 V    |                      |                              d          S )z)Convert this matrix to COOrdinate format.r   F)r6   r   r   s     r   r   zspmatrix.tocoo  r   r   c                 V    |                      |                              d          S )z7Convert this matrix to Compressed Sparse Column format.r   F)r6   tocscr   s     r   r   zspmatrix.tocsc   r   r   c                     t           )z4Convert this matrix to Compressed Sparse Row format.r   r   s     r   r6   zspmatrix.tocsr$  r   r   c                 0    |                      ||          S )z4Return a dense matrix representation of this matrix.r   r   r   s      r   todensezspmatrix.todense(  s    ||%S|111r   c                 V    |                      |                              d          S )z.Convert this matrix to sparse DIAgonal format.r   F)r6   todiar   s     r   r   zspmatrix.todia,  r   r   c                 V    |                      |                              d          S )z1Convert this matrix to Dictionary Of Keys format.r   F)r6   todokr   s     r   r   zspmatrix.todok0  r   r   c                 V    |                      |                              d          S )z*Convert this matrix to LInked List format.r   F)r6   tolilr   s     r   r  zspmatrix.tolil4  r   r   c                 X    |                      |                              |d          S )z-Reverses the dimensions of the sparse matrix.r   F)axesr   )r6   r   )r   r  r   s      r   r   zspmatrix.transpose8  s)    zztz$$..Du.EEEr   )r   r(   )T)r   )NNN)NN)NF)F)Qr	   r
   r   __doc____array_priority__r   propertyr    r#   r&   r*   r0   r4   __nonzero__r7   r<   r>   r@   rB   rD   rF   rH   rK   rN   rP   rR   r\   r`   rb   rd   rf   rh   rj   rl   ro   rr   rt   rw   rv   r   r   rX   r   rW   r   r3   r.   setterr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r6   r   r   r   r  r   r   r   r   r   r      s        
 ! ! ! ! " " X"" " " "4 4 4  
  N N N K* * ** * ** * ** * ** * ** * *& & &+ + +, , ,+ + +, , ,+ + +# # ## # #$ $ $+ + +, , ,/ / /0 0 0        ( ( (  &" &" &"P   X     X    X   X   X   X     X  \  \	2 	2 	2$ $ $ < < <   *$ $ $ $ I/ / /" " "
* 
* 
* 
*     ' ' '" " "
    " " " "+ + +@2 @2 @2 @2D+ + +, , ,2 2 2 2 %( 8 8 8 8 8.  " " " "- - - -^: : : :7 7 7 77 7 7 77 7 7 7" " " "2 2 2 27 7 7 77 7 7 77 7 7 7F F F F F Fr   r   c                 ,    t          | t                    S )zChecks if a given matrix is a sparse matrix.

    Returns:
        bool: Returns if ``x`` is :class:`cupyx.scipy.sparse.spmatrix` that is
        a base class of all sparse matrix classes.

    )
isinstancer   )xs    r   issparser  =  s     a"""r   )r   rT   r   r   r   r   scipy.sparser   _sparser   r   ImportErrorWarningobjectr   r  rV   
isspmatrixr   r   r   <module>r     sM           $ $ $ $ $ $ ' ' ' ' ' '	"""""")M%=              -     	bF bF bF bF bFv bF bF bFJ# # # -


s   1 !AA