
    `i3                         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 d dlm	Z	 g dZ
 G d d	ej                  Zd
 Zd Z G d de          Zd Zd Z e             dS )    N)internal)_util)_base)_coo)_sputils)arcsinarcsinharctanarctanhceildeg2radexpm1floorlog1prad2degrintsignsinsinhsqrttantanhtruncc                       e Zd Zd Zed             ZddZd Zd Zd Z	ddZ
ej        j
        j        e
_        d	 Zej        j        j        e_        d
 ZddZddZdS )_data_matrixc                     || _         d S N)data)selfr   s     l/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupyx/scipy/sparse/_data.py__init__z_data_matrix.__init__   s    			    c                     | j         j        S )zData type of the matrix.)r   dtyper   s    r    r$   z_data_matrix.dtype   s     yr"   Tc                     t           r   )NotImplementedError)r   r   copys      r    
_with_dataz_data_matrix._with_data   s    !!r"   c                 P    |                      t          | j                            S )zElementwise absolute.)r)   absr   r%   s    r    __abs__z_data_matrix.__abs__   s    s49~~...r"   c                 8    |                      | j                   S )zElementwise negative.)r)   r   r%   s    r    __neg__z_data_matrix.__neg__"   s    	z***r"   c                 \    |                      | j                            |                    S )zCasts the array to given data type.

        Args:
            dtype: Type specifier.

        Returns:
            A copy of the array with a given type.

        )r)   r   astype)r   ts     r    r0   z_data_matrix.astype&   s&     ty//22333r"   c                     t          j        | j        t           j                  r.|                     | j                                        |          S |r|                                 S | S )Nr(   )cupy
issubdtyper$   complexfloatingr)   r   conjr(   )r   r(   s     r    r7   z_data_matrix.conj2   sX    ?4:t';<< 	??49>>#3#3$???? 	99;;Kr"   c                 ^    |                      | j                                        d          S )NTr3   )r)   r   r(   r%   s    r    r(   z_data_matrix.copy<   s$    ty~~//d;;;r"   c                 4    t          j        | j                  S )aW  Returns number of non-zero entries.

        .. note::
           This method counts the actual number of non-zero entories, which
           does not include explicit zero entries.
           Instead ``nnz`` returns the number of entries including explicit
           zeros.

        Returns:
            Number of non-zero entries.

        )r4   count_nonzeror   r%   s    r    r:   z_data_matrix.count_nonzeroA   s     !$),,,r"   Nc                     t          j        |           | j        \  }}| j                                        }|||z  }n	|dv r|}n|}|                     ||z                                |||          S )a  Compute the arithmetic mean along the specified axis.

        Args:
            axis (int or ``None``): Axis along which the sum is computed.
                If it is ``None``, it computes the average of all the elements.
                Select from ``{None, 0, 1, -2, -1}``.

        Returns:
            cupy.ndarray: Summed array.

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

        N)r   )r   validateaxisshaper   r(   r)   sum)r   axisr$   outnRownColr   ns           r    meanz_data_matrix.meanP   s~     	d###Z
dy~~<tAAW__AAAtax((,,T5#>>>r"   c                     || j                                         }n| j                             |d          }||z  }|                     |          S )zpElementwise power function.

        Args:
            n: Exponent.
            dtype: Type specifier.

        NTr3   )r   r(   r0   r)   )r   rD   r$   r   s       r    powerz_data_matrix.powerl   sQ     =9>>##DD9##E#55D
t$$$r"   )T)NNNr   )__name__
__module____qualname__r!   propertyr$   r)   r,   r.   r0   r7   r   spmatrix__doc__r(   r:   rE   rG    r"   r    r   r      s             X" " " "/ / /+ + +
4 
4 
4    >&.DL< < < >&.DL- - -? ? ? ?8% % % % % %r"   r   c                     t          j        | j                  }| |k    }t          j        |                                |                                t          j        | j        |k     r| j        nd                    S )N)r4   arangesizewhereanyargmaxasarray)indrD   	positionsdiffs       r    _find_missing_indexrZ   |   sd    CH%%I)D:

ASXX2668 8 8r"   c                    t          j        | j                  }|| j        k    r|S | j        | j        d         z  | j        z   }t          ||          }t          j        ||k    t          j	        ||          |          S )N   )
npprodr>   nnzrowcolrZ   r4   rS   minimum)matamzeromrR   rW   zero_inds          r    _non_zero_cmprh      sx    739Dsw	g	!$sw.&sD11zIL2&&  	r"   c                   V    e Zd ZdZd Zd Zd Zd Zdddd	Zdddd
Z	ddZ
ddZdS )_minmax_mixinzlMixin for min and max methods.
    These are not implemented for dia_matrix, hence the separate class.

    c           	         | j         |         }|dk    rt          d          | j         d|z
           }|dk    r|                                 n|                                 }|                                 |                    |||          }t          j        |          }|dk    }	t          j        |	|          }t          j        |	|          }|dk    rAt          j
        |t          j        t          |                    |ff| j        d|f          S t          j
        ||t          j        t          |                    ff| j        |df          S )Nr   &zero-size array to reduction operationr\   )r$   r>   )r>   
ValueErrortocsctocsrsum_duplicates_minor_reducer4   rQ   compressr   
coo_matrixzeroslenr$   )
r   r@   
min_or_maxexplicitNMrc   valuemajor_indexmasks
             r    _min_or_max_axisz_minmax_mixin._min_or_max_axis   sG   Jt66EFFFJq4x "aiidjjlllTZZ\\ !!*dH==k!nnzmD+66dE**199?CJJ//=>jA0 0 0 0 ?djU&<&<=>jA0 0 0 0r"   c                 @   |t          d          t          j        |           |d| j        v rt          d          t	          j        d| j                  }| j        dk    r|S |                                   || j	                  }|r|S | j        t          j        | j                  k    rJ|t          j        u rt	          j        ||          }n&|t          j        u rt	          j        ||          }nJ |S |dk     r|dz  }|                     |||          S )N2Sparse matrices do not support an 'out' parameter.r   rl   rN   )r$   F   )rm   r   r=   r>   r4   rt   r$   r_   rp   r   r   r^   minrb   maxmaximumr}   )r   r@   rA   rv   rw   re   rf   s          r    _min_or_maxz_minmax_mixin._min_or_max   s3   ? 4 6 6 6 	d###<DJ !IJJJ:b
333Dx1}}!!!
49%%A x8=4444))T1--AA48++T1--AA 5H!88AID$$T:x@@@r"   c                 .   | j         |         dk    rt          d          |dk    r|                                 n|                                 }|                                 |                    ||          }|dk    r|d d d f         S |d d d f         S )Nr   z7Can't apply the operation along a zero-sized dimension.)r>   rm   rn   ro   rp   _arg_minor_reduce)r   r@   oprc   rz   s        r    _arg_min_or_max_axisz"_minmax_mixin._arg_min_or_max_axis   s    :dq   * + + + #aiidjjlllTZZ\\ %%b$//199qqq>!D>!r"   c           
      l   |t          d          t          j        |           |d| j        v rt          d          | j        dk    rdS t          j        | j                            d                    }| 	                                }|
                                  ||j                  }|j        |         }t          j         |||          |j        |         |j        d         z  |j        |         z   t          ||||                    S |dk     r|dz  }|                     ||          S )Nr   r   z-Can't apply the operation to an empty matrix.r\   r   )rm   r   r=   r>   r_   r4   rV   r$   typetocoorp   r   rS   r`   ra   rh   r   )	r   r@   rA   r   comparere   rc   rd   rf   s	            r    _arg_min_or_maxz_minmax_mixin._arg_min_or_max   s<   ? 3 4 4 4 	d###<DJ  "4 5 5 5 x1}}q|DJOOA$6$677jjll""$$$R\\HRLzGAt$$cgbkCIaL&@372;&N!#r4335 5 5 !88AID((r222r"   NF)rw   c                    |r3d                     | j        j                  }t          j        |           |                     ||t          j        |          S )a  Returns the maximum of the matrix or maximum along an axis.

        Args:
            axis (int): {-2, -1, 0, 1, ``None``} (optional)
                Axis along which the sum is computed. The default is to
                compute the maximum over all the matrix 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 (bool): Return the maximum value explicitly specified and
                ignore all implicit zero entries. If the dimension has no
                explicit values, a zero is then returned to indicate that it is
                the only implicit value. This parameter is experimental and may
                change in the future.

        Returns:
            (cupy.ndarray or float): Maximum of ``a``. If ``axis`` is
            ``None``, the result is a scalar value. If ``axis`` is given,
            the result is an array of dimension ``a.ndim - 1``. This
            differs from numpy for computational efficiency.

        .. seealso:: min : The minimum value of a sparse matrix along a given
          axis.
        .. seealso:: numpy.matrix.max : NumPy's implementation of ``max`` for
          matrices

        z%explicit of cupyx.scipy.sparse.{}.max)format	__class__rH   r   experimentalr   r4   r   r   r@   rA   rw   api_names        r    r   z_minmax_mixin.max  V    <  	)>EE') )Hx(((c48X>>>r"   c                    |r3d                     | j        j                  }t          j        |           |                     ||t          j        |          S )a  Returns the minimum of the matrix or maximum along an axis.

        Args:
            axis (int): {-2, -1, 0, 1, ``None``} (optional)
                Axis along which the sum is computed. The default is to
                compute the minimum over all the matrix 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 (bool): Return the minimum value explicitly specified and
                ignore all implicit zero entries. If the dimension has no
                explicit values, a zero is then returned to indicate that it is
                the only implicit value. This parameter is experimental and may
                change in the future.

        Returns:
            (cupy.ndarray or float): Minimum of ``a``. If ``axis`` is
            None, the result is a scalar value. If ``axis`` is given, the
            result is an array of dimension ``a.ndim - 1``. This differs
            from numpy for computational efficiency.

        .. seealso:: max : The maximum value of a sparse matrix along a given
          axis.
        .. seealso:: numpy.matrix.min : NumPy's implementation of 'min' for
          matrices

        z%explicit of cupyx.scipy.sparse.{}.min)r   r   rH   r   r   r   r4   r   r   s        r    r   z_minmax_mixin.min&  r   r"   c                 Z    |                      ||t          j        t          j                  S )a  Returns indices of maximum elements along an axis.

        Implicit zero elements are taken into account. If there are several
        maximum values, the index of the first occurrence is returned. If
        ``NaN`` values occur in the matrix, the output defaults to a zero entry
        for the row/column in which the NaN occurs.

        Args:
            axis (int): {-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.

        Returns:
            (cupy.narray or int): Indices of maximum elements. If array,
            its size along ``axis`` is 1.

        )r   r4   rU   greaterr   r@   rA   s      r    rU   z_minmax_mixin.argmaxJ  s"    , ##D#t{DLIIIr"   c                 Z    |                      ||t          j        t          j                  S )a  
        Returns indices of minimum elements along an axis.

        Implicit zero elements are taken into account. If there are several
        minimum values, the index of the first occurrence is returned. If
        ``NaN`` values occur in the matrix, the output defaults to a zero entry
        for the row/column in which the NaN occurs.

        Args:
            axis (int): {-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.

        Returns:
            (cupy.narray or int): Indices of minimum elements. If matrix,
            its size along ``axis`` is 1.

        )r   r4   argminlessr   s      r    r   z_minmax_mixin.argminb  s"    . ##D#t{DIFFFr"   )NN)rH   rI   rJ   rM   r}   r   r   r   r   r   rU   r   rN   r"   r    rj   rj      s         
0 0 04A A A@" " " 3 3 3@"?5 "? "? "? "? "?H"?5 "? "? "? "? "?HJ J J J0G G G G G Gr"   rj   c                 `      fd}d z  |_          |_        t          t           |           d S )Nc                 x    t          t                    } || j                  }|                     |          S r   )getattrr4   r   r)   )r   ufuncresult	func_names      r    fz_install_ufunc.<locals>.f~  s5    i((ty!!v&&&r"   zElementwise %s.)rM   rH   setattrr   )r   r   s   ` r    _install_ufuncr   |  sI    ' ' ' ' '
 "I-AIAJL)Q'''''r"   c                  8    t           D ]} t          |            d S r   )_ufuncsr   )r   s    r    _install_ufuncsr     s,     " "	y!!!!" "r"   )r4   numpyr]   
cupy._corer   r   cupyx.scipy.sparser   r   r   r   rL   r   rZ   rh   objectrj   r   r   rN   r"   r    <module>r      sG                    $ $ $ $ $ $ # # # # # # ' ' ' ' ' '  h% h% h% h% h%5> h% h% h%V8 8 8
 
 
gG gG gG gG gGF gG gG gGT
( 
( 
(" " "
      r"   