§
    fŠtjÂ  ã                   óH   — d Z dZg d¢ZddlmZmZ ddlmZ d„ Zdd	„Z	dd
„Z
dS )z.Functions to extract parts of sparse matrices
zrestructuredtext en)ÚfindÚtrilÚtriué   )Ú
coo_matrixÚ	coo_array)Úsparrayc                 ó®   — t          | d¬¦  «        } |                      ¦   «          | j        dk    }| j        |         | j        |         | j        |         fS )aT  Return the indices and values of the nonzero elements of a matrix

    Parameters
    ----------
    A : dense or sparse array or matrix
        Matrix whose nonzero elements are desired.

    Returns
    -------
    (I,J,V) : tuple of arrays
        I,J, and V contain the row indices, column indices, and values
        of the nonzero entries.


    Examples
    --------
    >>> from scipy.sparse import csr_array, find
    >>> A = csr_array([[7.0, 8.0, 0],[0, 0, 9.0]])
    >>> find(A)
    (array([0, 0, 1], dtype=int32),
     array([0, 1, 2], dtype=int32),
     array([ 7.,  8.,  9.]))

    T©Úcopyé    )r   Úsum_duplicatesÚdataÚrowÚcol)ÚAÚnz_masks     úS/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/scipy/sparse/_extract.pyr   r      sR   € õ4 	�!˜$ÐÑÔ€AØ×ÒÑÔÐàŒf˜Šk€GØŒ5�Œ>˜1œ5 œ>¨1¬6°'¬?Ð:Ð:ó    r   Nc                 ó8  — t          | t          ¦  «        rt          nt          } || d¬¦  «        } | j        |z   | j        k    }| j        |         }| j        |         }| j        |         } ||||ff| j        | j        ¬¦  «        }| 	                    |¦  «        S )a.  Return the lower triangular portion of a sparse array or matrix

    Returns the elements on or below the k-th diagonal of A.
        - k = 0 corresponds to the main diagonal
        - k > 0 is above the main diagonal
        - k < 0 is below the main diagonal

    Parameters
    ----------
    A : dense or sparse array or matrix
        Matrix whose lower trianglar portion is desired.
    k : integer : optional
        The top-most diagonal of the lower triangle.
    format : string
        Sparse format of the result, e.g. format="csr", etc.

    Returns
    -------
    L : sparse matrix
        Lower triangular portion of A in sparse format.

    See Also
    --------
    triu : upper triangle in sparse format

    Examples
    --------
    >>> from scipy.sparse import csr_array, tril
    >>> A = csr_array([[1, 2, 0, 0, 3], [4, 5, 0, 6, 7], [0, 0, 8, 9, 0]],
    ...               dtype='int32')
    >>> A.toarray()
    array([[1, 2, 0, 0, 3],
           [4, 5, 0, 6, 7],
           [0, 0, 8, 9, 0]], dtype=int32)
    >>> tril(A).toarray()
    array([[1, 0, 0, 0, 0],
           [4, 5, 0, 0, 0],
           [0, 0, 8, 0, 0]], dtype=int32)
    >>> tril(A).nnz
    4
    >>> tril(A, k=1).toarray()
    array([[1, 2, 0, 0, 0],
           [4, 5, 0, 0, 0],
           [0, 0, 8, 9, 0]], dtype=int32)
    >>> tril(A, k=-1).toarray()
    array([[0, 0, 0, 0, 0],
           [4, 0, 0, 0, 0],
           [0, 0, 0, 0, 0]], dtype=int32)
    >>> tril(A, format='csc')
    <Compressed Sparse Column sparse array of dtype 'int32'
        with 4 stored elements and shape (3, 5)>

    Fr
   ©ÚshapeÚdtype©
Ú
isinstancer   r   r   r   r   r   r   r   Úasformat©	r   ÚkÚformatÚ
coo_sparseÚmaskr   r   r   Únew_coos	            r   r   r   .   s�   € õl )¨­GÑ4Ô4ÐD•�½*€Jð 	ˆ
�1˜5Ð!Ñ!Ô!€AØŒ5�1‰9˜œÒ€Dà
Œ%�Œ+€CØ
Œ%�Œ+€CØŒ6�$Œ<€DØˆj˜$  c 
Ð+°1´7À!Ä'ÐJÑJÔJ€GØ×Ò˜FÑ#Ô#Ð#r   c                 ó8  — t          | t          ¦  «        rt          nt          } || d¬¦  «        } | j        |z   | j        k    }| j        |         }| j        |         }| j        |         } ||||ff| j        | j        ¬¦  «        }| 	                    |¦  «        S )az  Return the upper triangular portion of a sparse array or matrix

    Returns the elements on or above the k-th diagonal of A.
        - k = 0 corresponds to the main diagonal
        - k > 0 is above the main diagonal
        - k < 0 is below the main diagonal

    Parameters
    ----------
    A : dense or sparse array or matrix
        Matrix whose upper trianglar portion is desired.
    k : integer : optional
        The bottom-most diagonal of the upper triangle.
    format : string
        Sparse format of the result, e.g. format="csr", etc.

    Returns
    -------
    L : sparse array or matrix
        Upper triangular portion of A in sparse format.
        Sparse array if A is a sparse array, otherwise matrix.

    See Also
    --------
    tril : lower triangle in sparse format

    Examples
    --------
    >>> from scipy.sparse import csr_array, triu
    >>> A = csr_array([[1, 2, 0, 0, 3], [4, 5, 0, 6, 7], [0, 0, 8, 9, 0]],
    ...                dtype='int32')
    >>> A.toarray()
    array([[1, 2, 0, 0, 3],
           [4, 5, 0, 6, 7],
           [0, 0, 8, 9, 0]], dtype=int32)
    >>> triu(A).toarray()
    array([[1, 2, 0, 0, 3],
           [0, 5, 0, 6, 7],
           [0, 0, 8, 9, 0]], dtype=int32)
    >>> triu(A).nnz
    8
    >>> triu(A, k=1).toarray()
    array([[0, 2, 0, 0, 3],
           [0, 0, 0, 6, 7],
           [0, 0, 0, 9, 0]], dtype=int32)
    >>> triu(A, k=-1).toarray()
    array([[1, 2, 0, 0, 3],
           [4, 5, 0, 6, 7],
           [0, 0, 8, 9, 0]], dtype=int32)
    >>> triu(A, format='csc')
    <Compressed Sparse Column sparse array of dtype 'int32'
        with 8 stored elements and shape (3, 5)>

    Fr
   r   r   r   s	            r   r   r   q   s�   € õn )¨­GÑ4Ô4ÐD•�½*€Jð 	ˆ
�1˜5Ð!Ñ!Ô!€AØŒ5�1‰9˜œÒ€Dà
Œ%�Œ+€CØ
Œ%�Œ+€CØŒ6�$Œ<€DØˆj˜$  c 
Ð+°1´7À!Ä'ÐJÑJÔJ€GØ×Ò˜FÑ#Ô#Ð#r   )r   N)Ú__doc__Ú__docformat__Ú__all__Ú_coor   r   Ú_baser   r   r   r   © r   r   ú<module>r)      sš   ððð ð &€à
"Ð
"Ð
"€ð (Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø Ð Ð Ð Ð Ð ð;ð ;ð ;ðB@$ð @$ð @$ð @$ðFA$ð A$ð A$ð A$ð A$ð A$r   