o
    X۷i	                     @  sX   d dl mZ d dlZd dlZd dlmZ dd ZdddZddd	Zd
d Z	dd Z
dS )    )annotationsN)sparsec                 C  sD   t |  tj| dd} |   | jdk}| j| | j| | j| fS )a  Returns the indices and values of the nonzero elements of a matrix

    Args:
        A (cupy.ndarray or cupyx.scipy.sparse.spmatrix): Matrix whose nonzero
            elements are desired.

    Returns:
        tuple of cupy.ndarray:
            It returns (``I``, ``J``, ``V``). ``I``, ``J``, and ``V`` contain
            respectively the row indices, column indices, and values of the
            nonzero matrix entries.

    .. seealso:: :func:`scipy.sparse.find`
    Tcopyr   )_check_A_typer   
coo_matrixsum_duplicatesdatarowcol)Anz_mask r   Q/home/ubuntu/vllm_env/lib/python3.10/site-packages/cupyx/scipy/sparse/_extract.pyfind	   s
   
r   c                 C  s6   t |  tj| dd} | j| | jk}t| ||S )a  Returns the lower triangular portion of a matrix in sparse format

    Args:
        A (cupy.ndarray or cupyx.scipy.sparse.spmatrix): Matrix whose lower
            triangular portion is desired.
        k (integer): The top-most diagonal of the lower triangle.
        format (string): Sparse format of the result, e.g. 'csr', 'csc', etc.

    Returns:
        cupyx.scipy.sparse.spmatrix:
            Lower triangular portion of A in sparse format.

    .. seealso:: :func:`scipy.sparse.tril`
    Fr   r   r   r   r
   r   _masked_cooasformatr   kformatmaskr   r   r   tril      r   c                 C  s6   t |  tj| dd} | j| | jk}t| ||S )a  Returns the upper triangular portion of a matrix in sparse format

    Args:
        A (cupy.ndarray or cupyx.scipy.sparse.spmatrix): Matrix whose upper
            triangular portion is desired.
        k (integer): The bottom-most diagonal of the upper triangle.
        format (string): Sparse format of the result, e.g. 'csr', 'csc', etc.

    Returns:
        cupyx.scipy.sparse.spmatrix:
            Upper triangular portion of A in sparse format.

    .. seealso:: :func:`scipy.sparse.triu`
    Fr   r   r   r   r   r   triu4   r   r   c                 C  s.   t | tjstjj| sd}t|d S d S )Nz5A must be cupy.ndarray or cupyx.scipy.sparse.spmatrix)
isinstancecupyndarraycupyxscipyr   
isspmatrix	TypeError)r   msgr   r   r   r   I   s   r   c                 C  s:   | j | }| j| }| j| }tj|||ff| j| jdS )N)shapedtype)r
   r   r	   r   r   r#   r$   )r   r   r
   r   r	   r   r   r   r   O   s   


r   )r   N)
__future__r   r   r   cupyx.scipyr   r   r   r   r   r   r   r   r   r   <module>   s    

