a
    CCCf1+                     @   s   d Z dZg dZddlZddlmZ ddlmZm	Z	 ddl
mZmZ dd	lmZ dd
lmZ G dd deZdd ZG dd dee	ZG dd deeZdS )z&Compressed Sparse Column matrix formatzrestructuredtext en)	csc_array
csc_matrixisspmatrix_csc    N   )spmatrix)_spbasesparray)	csc_tocsr	expandptr)upcast)
_cs_matrixc                   @   s   e Zd ZdZd ddZejje_dd Zd!dd	Zejje_d"d
dZ	ej	je	_dd Z
ej
je
_dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zedd ZdS )#	_csc_baseZcscNFc                 C   sB   |d ur|dkrt d| j\}}| j| j| j| jf||f|dS )N)r   r   zvSparse arrays/matrices do not support an 'axes' parameter because swapping dimensions is the only logical permutation.copy)
ValueErrorshape_csr_containerdataindicesindptr)selfZaxesr   MN r   M/var/www/html/django/DPS/env/lib/python3.9/site-packages/scipy/sparse/_csc.py	transpose   s    
z_csc_base.transposec                 c   s   |   E d H  d S N)tocsr)r   r   r   r   __iter__!   s    z_csc_base.__iter__c                 C   s   |r|   S | S d S r   r   )r   r   r   r   r   tocsc$   s    z_csc_base.tocscc           	   	   C   s   | j \}}| j| j| jft| j|d}tj|d |d}tj| j|d}tj| jt| j	d}t
||| j|| j|| j||| | j|||f| j dd}d|_|S )N)maxvalr   dtypeF)r   r   T)r   Z_get_index_dtyper   r   maxZnnznpemptyr   r"   r	   Zastyper   r   Zhas_sorted_indices)	r   r   r   r   Z	idx_dtyper   r   r   Ar   r   r   r   ,   s*    



z_csc_base.tocsrc           	      C   s   |  | j\}}| j}tjt|| jjd}t|| j| |  ||f\}}| j	dk}|| }|| }tj
|dd}|| }|| }||fS )Nr!   r   Z	mergesort)kind)_swapr   r   r$   r%   lenr"   r
   r   r   Zargsort)	r   Z	major_dimZ	minor_dimZminor_indicesZmajor_indicesrowcolZnz_maskindr   r   r   nonzeroE   s    
z_csc_base.nonzeroc                 C   sN   | j \}}t|}|dk r"||7 }|dk s2||kr>td| | j|d S )z]Returns a copy of row i of the matrix, as a (1 x n)
        CSR matrix (row vector).
        r   index (%d) out of rangeminor)r   int
IndexError_get_submatrixr   r   ir   r   r   r   r   _getrow^   s    
z_csc_base._getrowc                 C   sL   | j \}}t|}|dk r"||7 }|dk s2||kr>td| | j|ddS )zcReturns a copy of column i of the matrix, as a (m x 1)
        CSC matrix (column vector).
        r   r.   T)majorr   )r   r1   r2   r3   r4   r   r   r   _getcolj   s    
z_csc_base._getcolc                 C   s   |  |j|dS )Nr/   )_major_index_fancyr3   r   r*   r+   r   r   r   _get_intXarrayv   s    z_csc_base._get_intXarrayc                 C   s,   |j dv r| j||ddS | |j|dS )Nr   NTr7   r0   r   r/   )stepr3   _major_slicer:   r   r   r   _get_intXslicey   s    
z_csc_base._get_intXslicec                 C   s,   |j dv r| j||ddS | j|d|S )Nr<   Tr=   r7   )r>   r3   _minor_slicer:   r   r   r   _get_sliceXint~   s    
z_csc_base._get_sliceXintc                 C   s   |  ||S r   )r9   rB   r:   r   r   r   _get_sliceXarray   s    z_csc_base._get_sliceXarrayc                 C   s   | j |d|S )NrA   )r3   _minor_index_fancyr:   r   r   r   _get_arrayXint   s    z_csc_base._get_arrayXintc                 C   s   |  ||S r   )r?   rE   r:   r   r   r   _get_arrayXslice   s    z_csc_base._get_arrayXslicec                 C   s   | d | d fS )zBswap the members of x if this is a column-oriented matrix
        r   r   r   xr   r   r   r(      s    z_csc_base._swap)NF)F)F)__name__
__module____qualname___formatr   r   __doc__r   r   r   r-   r   r6   r8   r;   r@   rC   rD   rF   rG   staticmethodr(   r   r   r   r   r      s(   






r   c                 C   s
   t | tS )a  Is `x` of csc_matrix type?

    Parameters
    ----------
    x
        object to check for being a csc matrix

    Returns
    -------
    bool
        True if `x` is a csc matrix, False otherwise

    Examples
    --------
    >>> from scipy.sparse import csc_array, csc_matrix, coo_matrix, isspmatrix_csc
    >>> isspmatrix_csc(csc_matrix([[5]]))
    True
    >>> isspmatrix_csc(csc_array([[5]]))
    False
    >>> isspmatrix_csc(coo_matrix([[5]]))
    False
    )
isinstancer   rH   r   r   r   r      s    r   c                   @   s   e Zd ZdZdS )r   a,  
    Compressed Sparse Column array.

    This can be instantiated in several ways:
        csc_array(D)
            where D is a 2-D ndarray

        csc_array(S)
            with another sparse array or matrix S (equivalent to S.tocsc())

        csc_array((M, N), [dtype])
            to construct an empty array with shape (M, N)
            dtype is optional, defaulting to dtype='d'.

        csc_array((data, (row_ind, col_ind)), [shape=(M, N)])
            where ``data``, ``row_ind`` and ``col_ind`` satisfy the
            relationship ``a[row_ind[k], col_ind[k]] = data[k]``.

        csc_array((data, indices, indptr), [shape=(M, N)])
            is the standard CSC representation where the row indices for
            column i are stored in ``indices[indptr[i]:indptr[i+1]]``
            and their corresponding values are stored in
            ``data[indptr[i]:indptr[i+1]]``.  If the shape parameter is
            not supplied, the array dimensions are inferred from
            the index arrays.

    Attributes
    ----------
    dtype : dtype
        Data type of the array
    shape : 2-tuple
        Shape of the array
    ndim : int
        Number of dimensions (this is always 2)
    nnz
    size
    data
        CSC format data array of the array
    indices
        CSC format index array of the array
    indptr
        CSC format index pointer array of the array
    has_sorted_indices
    has_canonical_format
    T

    Notes
    -----

    Sparse arrays can be used in arithmetic operations: they support
    addition, subtraction, multiplication, division, and matrix power.

    Advantages of the CSC format
        - efficient arithmetic operations CSC + CSC, CSC * CSC, etc.
        - efficient column slicing
        - fast matrix vector products (CSR, BSR may be faster)

    Disadvantages of the CSC format
      - slow row slicing operations (consider CSR)
      - changes to the sparsity structure are expensive (consider LIL or DOK)

    Canonical format
      - Within each column, indices are sorted by row.
      - There are no duplicate entries.

    Examples
    --------

    >>> import numpy as np
    >>> from scipy.sparse import csc_array
    >>> csc_array((3, 4), dtype=np.int8).toarray()
    array([[0, 0, 0, 0],
           [0, 0, 0, 0],
           [0, 0, 0, 0]], dtype=int8)

    >>> row = np.array([0, 2, 2, 0, 1, 2])
    >>> col = np.array([0, 0, 1, 2, 2, 2])
    >>> data = np.array([1, 2, 3, 4, 5, 6])
    >>> csc_array((data, (row, col)), shape=(3, 3)).toarray()
    array([[1, 0, 4],
           [0, 0, 5],
           [2, 3, 6]])

    >>> indptr = np.array([0, 2, 3, 6])
    >>> indices = np.array([0, 2, 2, 0, 1, 2])
    >>> data = np.array([1, 2, 3, 4, 5, 6])
    >>> csc_array((data, indices, indptr), shape=(3, 3)).toarray()
    array([[1, 0, 4],
           [0, 0, 5],
           [2, 3, 6]])

    NrJ   rK   rL   rN   r   r   r   r   r      s   r   c                   @   s   e Zd ZdZdS )r   a?  
    Compressed Sparse Column matrix.

    This can be instantiated in several ways:
        csc_matrix(D)
            where D is a 2-D ndarray

        csc_matrix(S)
            with another sparse array or matrix S (equivalent to S.tocsc())

        csc_matrix((M, N), [dtype])
            to construct an empty matrix with shape (M, N)
            dtype is optional, defaulting to dtype='d'.

        csc_matrix((data, (row_ind, col_ind)), [shape=(M, N)])
            where ``data``, ``row_ind`` and ``col_ind`` satisfy the
            relationship ``a[row_ind[k], col_ind[k]] = data[k]``.

        csc_matrix((data, indices, indptr), [shape=(M, N)])
            is the standard CSC representation where the row indices for
            column i are stored in ``indices[indptr[i]:indptr[i+1]]``
            and their corresponding values are stored in
            ``data[indptr[i]:indptr[i+1]]``.  If the shape parameter is
            not supplied, the matrix dimensions are inferred from
            the index arrays.

    Attributes
    ----------
    dtype : dtype
        Data type of the matrix
    shape : 2-tuple
        Shape of the matrix
    ndim : int
        Number of dimensions (this is always 2)
    nnz
    size
    data
        CSC format data array of the matrix
    indices
        CSC format index array of the matrix
    indptr
        CSC format index pointer array of the matrix
    has_sorted_indices
    has_canonical_format
    T

    Notes
    -----

    Sparse matrices can be used in arithmetic operations: they support
    addition, subtraction, multiplication, division, and matrix power.

    Advantages of the CSC format
        - efficient arithmetic operations CSC + CSC, CSC * CSC, etc.
        - efficient column slicing
        - fast matrix vector products (CSR, BSR may be faster)

    Disadvantages of the CSC format
      - slow row slicing operations (consider CSR)
      - changes to the sparsity structure are expensive (consider LIL or DOK)

    Canonical format
      - Within each column, indices are sorted by row.
      - There are no duplicate entries.

    Examples
    --------

    >>> import numpy as np
    >>> from scipy.sparse import csc_matrix
    >>> csc_matrix((3, 4), dtype=np.int8).toarray()
    array([[0, 0, 0, 0],
           [0, 0, 0, 0],
           [0, 0, 0, 0]], dtype=int8)

    >>> row = np.array([0, 2, 2, 0, 1, 2])
    >>> col = np.array([0, 0, 1, 2, 2, 2])
    >>> data = np.array([1, 2, 3, 4, 5, 6])
    >>> csc_matrix((data, (row, col)), shape=(3, 3)).toarray()
    array([[1, 0, 4],
           [0, 0, 5],
           [2, 3, 6]])

    >>> indptr = np.array([0, 2, 3, 6])
    >>> indices = np.array([0, 2, 2, 0, 1, 2])
    >>> data = np.array([1, 2, 3, 4, 5, 6])
    >>> csc_matrix((data, indices, indptr), shape=(3, 3)).toarray()
    array([[1, 0, 4],
           [0, 0, 5],
           [2, 3, 6]])

    NrQ   r   r   r   r   r     s   r   )rN   __docformat____all__numpyr$   Z_matrixr   _baser   r   Z_sparsetoolsr	   r
   Z_sputilsr   Z_compressedr   r   r   r   r   r   r   r   r   <module>   s    _