
    `i5                         	 d dl ZdZn# e$ r dZY nw xY wd dlZd dlmZ d dlmZ d dlZ	d dlm
Z
 d dlmZ  G d d	ej                  Zd
 ZdS )    NTF)driver)runtime)_base)_compressedc                       e Zd ZdZdZddZd Zd Zd Zd Z	d	 Z
dd
Zd ZddZddZddZd ZddZd Zd Zd Zd Zd Zd Zd Zd ZdS )
csc_matrixa  Compressed Sparse Column matrix.

    This can be instantiated in several ways.

    ``csc_matrix(D)``
        ``D`` is a rank-2 :class:`cupy.ndarray`.
    ``csc_matrix(S)``
        ``S`` is another sparse matrix. It is equivalent to ``S.tocsc()``.
    ``csc_matrix((M, N), [dtype])``
        It constructs an empty matrix whose shape is ``(M, N)``. Default dtype
        is float64.
    ``csc_matrix((data, (row, col)))``
        All ``data``, ``row`` and ``col`` are one-dimenaional
        :class:`cupy.ndarray`.
    ``csc_matrix((data, indices, indptr))``
        All ``data``, ``indices`` and ``indptr`` are one-dimenaional
        :class:`cupy.ndarray`.

    Args:
        arg1: Arguments for the initializer.
        shape (tuple): Shape of a matrix. Its length must be two.
        dtype: Data type. It must be an argument of :class:`numpy.dtype`.
        copy (bool): If ``True``, copies of given arrays are always used.

    .. seealso::
        :class:`scipy.sparse.csc_matrix`

    cscNc                    t           st          d          | j                            |          }| j                            |          }| j                            |          }t          j                            |||f| j	                  S )a  Returns a copy of the array on host memory.

        .. warning::
           You need to install SciPy to use this method.

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

        Returns:
            scipy.sparse.csc_matrix: Copy of the array on host memory.

        zscipy is not available)shape)
_scipy_availableRuntimeErrordatagetindicesindptrscipysparser   _shape)selfstreamr   r   r   s        k/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupyx/scipy/sparse/_csc.pyr   zcsc_matrix.get0   s       	97888y}}V$$,""6**((|&&7F#4; ' 8 8 	8    c                     ddl m} |                    d          r|                    |d          }n|                    |          }|j        |j        |j        fS )Nr   cusparsedenseToSparser	   )format)cupyxr   check_availabilityr   	dense2cscr   r   r   )r   xr   ms       r   _convert_densezcsc_matrix._convert_denseF   sj    """"""&&77 	&&&q&77AA""1%%Avqy!(**r   c                 
    ||fS N )r   r!   ys      r   _swapzcsc_matrix._swapO   s    1vr   c                 
   ddl m} t          j        |          r1|                                  |                     | j        |z            S t           j        j        	                    |          r|                                  |                                 |
                    d          r>|                                 }|                                 |                    ||          S |
                    d          r+t          j        s| j        }|                    ||d          S |
                    d          r>|                                 }|                                 |                    ||          S t$          t'          |          rm|                                  |                                 |
                    d          r3t          j        s'| j        }|j        }|                    ||dd          S |
                    d          rf|                                 }|                                }|                                 |                                 |                    ||          S |
                    d          rf|                                 }|                                }|                                 |                                 |                    ||          S t$          t           j        j                            |          r| |                                z  S t+          j        |          r|j        dk    r1|                                  |                     | j        |z            S |j        d	k    r|                                  |
                    d
          r+t          j        rt1          j                    dk    r|j        }n0|
                    d          rt          j        s|j        }nt$           || j        t          j        |          d          S |j        dk    r|                                  |
                    d          r+t          j        rt1          j                    dk    r|j        }n$|
                    d          r|j        }nt$           || j        t          j        |          d          S t?          d          t@          S )Nr   r   spgemmcsrgemmT)transacsrgemm2)r,   transb   csrmvispmv   csrmm2spmmzcould not interpret dimensions)!r   r   cupyisscalarsum_duplicates
_with_datar   r   r   isspmatrix_csrr   tocsrr*   r   is_hipTr+   r-   AssertionErrorisspmatrix_csc
isspmatrixr   isdensendimr   get_build_versionr0   r1   asfortranarrayr3   r4   
ValueErrorNotImplemented)r   otherr   abr0   csrmms          r   __mul__zcsc_matrix.__mul__R   s   """"""= V	"!!!??49u#4555[..u55 S	"!!!  """**844 %JJLL  """q%000,,Y77 	% 	%F''5'>>>,,Z88 %JJLL  """((E222$$E"" B	"!!!  """**955 %gn %FG''1T$'GGG,,Z88 %JJLLKKMM  """  """((A...,,X66 %JJLLKKMM  """  """q!,,,$$[**511 ,	"%++--'']5!! *	"zQ##%%%ty5'8999q##%%%//88) $N) "355CC %NEE11&99 ) ') %MEE((uTVT%8%?%?MMMMq##%%%//99) $N) "355CC %OEE0088 )$MEE((uTVT%8%?%?MMMM !ABBB!!r   c                     | j         }|                                 |j         }|j        | _        |j        | _        |j        | _        dS )zRemoves zero entories in place.N)r<   eliminate_zerosr   r   r   )r   tcompresss      r   rL   zcsc_matrix.eliminate_zeros   sB    F	3M	'or   c                 \    ddl m} | j        s|                    |            d| _        dS dS )zSorts the indices of this matrix *in place*.

        .. warning::
            Calling this function might synchronize the device.

        r   r   TN)r   r   has_sorted_indicescscsort)r   r   s     r   sort_indiceszcsc_matrix.sort_indices   sM     	#"""""& 	+T"""&*D###	+ 	+r   c                 v   ddl m} |d}|                                }| j        dk    r!t	          j        | j        | j        |          S |                                 }d|_	        |
                                 |                    d          r]t          j        r|j        dk    rF|                    |          }|dk    r|S |dk    rt	          j        |          S t!          d	          |dk    r|                    |j                  j        S |dk    r|                    |          S t!          d	          )
a  Returns a dense matrix representing the same value.

        Args:
            order ({'C', 'F', None}): Whether to store data in C (row-major)
                order or F (column-major) order. Default is C-order.
            out: Not supported.

        Returns:
            cupy.ndarray: Dense array representing the same matrix.

        .. seealso:: :meth:`scipy.sparse.csc_matrix.toarray`

        r   r   NC)r   dtypeorderFsparseToDenseFzorder not understood)r   r   uppernnzr5   zerosr   rU   copyhas_canonical_formatr7   r   r   r;   rW   ascontiguousarrayrD   	csr2denser<   	csc2dense)r   rV   outr   r!   r'   s         r   toarrayzcsc_matrix.toarray   s?    	#"""""=E8q==:DJdjNNNNIIKK!&	''88 	9 	9+,5199&&q))A||#-a000 !7888 ||))!#..00#))!,,, !7888r   c                 B   ddl m} |                                  |                                j        }|                                 |                    d          r|j        }n$|                    d          r|j        }nt           || j        |||          j        S )Nr   r   csrgeam2csrgeam)	r   r   r7   tocscr<   r   rd   re   NotImplementedError)r   rF   alphabetar   re   s         r   _add_sparsezcsc_matrix._add_sparse   s    """"""&&z22 	&'GG((33 	&&GG%%wtvueT2244r   Fc                     ddl m} |r3| j                                        }| j                                        }n| j        }| j        }|                    | ||          S )zConverts the matrix to COOrdinate format.

        Args:
            copy (bool): If ``False``, it shares data arrays as much as
                possible.

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

        r   r   )r   r   r   r\   r   csc2coo)r   r\   r   r   r   s        r   tocoozcsc_matrix.tocoo  sj     	#""""" 	#9>>##Dl''))GG9DlGdG444r   c                 2    |r|                                  S | S )a  Converts the matrix to Compressed Sparse Column format.

        Args:
            copy (bool): If ``False``, the method returns itself.
                Otherwise it makes a copy of the matrix.

        Returns:
            cupyx.scipy.sparse.csc_matrix: Converted matrix.

        r\   )r   r\   s     r   rf   zcsc_matrix.tocsc  s      	99;;Kr   c                     ddl m} |                    d          r|j        }n$|                    d          r|j        }nt
           ||           S )ax  Converts the matrix to Compressed Sparse Row format.

        Args:
            copy (bool): If ``False``, it shares data arrays as much as
                possible. Actually this option is ignored because all
                arrays in a matrix cannot be shared in csr to csc conversion.

        Returns:
            cupyx.scipy.sparse.csr_matrix: Converted matrix.

        r   r   csc2csr
csc2csrEx2)r   r   r   rq   rr   rg   )r   r\   r   rq   s       r   r:   zcsc_matrix.tocsr.  sl     	#""""" &&y11 	&&GG((66 	&)GG%%wt}}r   c                 *    |                                  S )zInverts the format.
        )r:   )r   s    r   _tocsxzcsc_matrix._tocsxF  s     zz||r   c                     |t          d          | j        d         | j        d         f}t          j        j                            | j        | j        | j        f||          }| j	        |_	        |S )aT  Returns a transpose matrix.

        Args:
            axes: This option is not supported.
            copy (bool): If ``True``, a returned matrix shares no data.
                Otherwise, it shared data arrays as much as possible.

        Returns:
            cupyx.scipy.sparse.csr_matrix: `self` with the dimensions reversed.

        NzoSparse matrices do not support an 'axes' parameter because swapping dimensions is the only logical permutation.r/   r   )r   r\   )
rD   r   r   r   r   
csr_matrixr   r   r   r]   )r   axesr\   r   transs        r   	transposezcsc_matrix.transposeO  s     GH H H 
1tz!},"--Ydk2%d . L L%)%>"r   c                 v    |                      t          ||dz             d                                          S )zReturns a copy of row i of the matrix, as a (1 x n)
        CSR matrix (row vector).

        Args:
            i (integer): Row

        Returns:
            cupyx.scipy.sparse.csc_matrix: Sparse matrix with single row
        r/   Tro   )_minor_sliceslicer:   r   is     r   getrowzcsc_matrix.getrowf  s5       q!a%t <<BBDDDr   c                 R    |                      t          ||dz             d          S )zReturns a copy of column i of the matrix, as a (m x 1)
        CSC matrix (column vector).

        Args:
            i (integer): Column

        Returns:
            cupyx.scipy.sparse.csc_matrix: Sparse matrix with single column
        r/   Tro   )_major_slicer|   r}   s     r   getcolzcsc_matrix.getcolr  s)       q!a%t <<<r   c                 x    t          ||dz             }|                     |                              |          S Nr/   )r|   _major_index_fancyr{   r   rowcols      r   _get_intXarrayzcsc_matrix._get_intXarray~  s7    Cq!!&&s++88===r   c                     t          ||dz             }|j        dv }|                     |                              ||          S )Nr/   )r/   Nro   )r|   stepr   r{   )r   r   r   r\   s       r   _get_intXslicezcsc_matrix._get_intXslice  sH    Cq!!x9$  %%223T2BBBr   c                 |    t          ||dz             }|                     |                              |d          S )Nr/   Tro   )r|   r   r{   r   s      r   _get_sliceXintzcsc_matrix._get_sliceXint  s<    Cq!!  %%223T2BBBr   c                 R    |                      |                              |          S r%   )r   r{   r   s      r   _get_sliceXarrayzcsc_matrix._get_sliceXarray  s$    &&s++88===r   c                 x    t          ||dz             }|                     |                              |          S r   )r|   r   _minor_index_fancyr   s      r   _get_arrayXintzcsc_matrix._get_arrayXint  s7    Cq!!  %%88===r   c                 R    |                      |                              |          S r%   )r   r   r   s      r   _get_arrayXslicezcsc_matrix._get_arrayXslice  s$      %%88===r   r%   )NN)F)NF)__name__
__module____qualname____doc__r   r   r#   r(   rJ   rL   rR   rb   rj   rm   rf   r:   rt   ry   r   r   r   r   r   r   r   r   r&   r   r   r   r      s        : F8 8 8 8,+ + +  Y" Y" Y"|& & &+ + ++9 +9 +9 +9Z5 5 5 5 5 5 5,       0     .
E 
E 
E
= 
= 
=> > >C C C
C C C> > >> > >> > > > >r   r   c                 ,    t          | t                    S )zChecks if a given matrix is of CSC format.

    Returns:
        bool: Returns if ``x`` is :class:`cupyx.scipy.sparse.csc_matrix`.

    )
isinstancer   )r!   s    r   r>   r>     s     a$$$r   )scipy.sparser   r   ImportErrorr5   cupy_backends.cuda.apir   r   cupyx.scipy.sparser   r   r   _compressed_sparse_matrixr   r>   r&   r   r   <module>r      s        ) ) ) ) ) ) * * * * * *     $ $ $ $ $ $ * * * * * *D> D> D> D> D>6 D> D> D>N% % % % %s   	 