L i+dZdZgdZddlZddlmZddlmZm Z ddl m Z m Z dd l mZdd lmZGd d eZd ZGddee ZGddeeZy)z&Compressed Sparse Column matrix formatzrestructuredtext en) csc_array csc_matrixisspmatrix_cscN)spmatrix)_spbasesparray) csr_tocsc expandptr)upcast) _cs_matrixcLeZdZdZddZejj e_dZddZejj e_ddZ ejj e _dZ e jj e _dZ d Z d Zd Zd Zd ZdZdZedZy) _csc_basecscNc||dk7r td|j\}}|j|j|j|j f||f|S)N)rrzvSparse arrays/matrices do not support an 'axes' parameter because swapping dimensions is the only logical permutation.copy) ValueErrorshape_csr_containerdataindicesindptr)selfaxesrMNs W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/sparse/_csc.py transposez_csc_base.transposesm  LM Mzz1""DIIt||$(KK$134a&t#E Ec#@K|jEd{y7wN)tocsr)rs r__iter__z_csc_base.__iter__!s::<s c*|r|jS|Sr"r)rrs rtocscz_csc_base.tocsc$s 99; Kr c h|j\}}|j|j|jft |j |}t j|dz|}t j|j |}t j|j t|j}t|||jj||jj||j||||j|||f|jd}d|_|S)N)maxvalrdtypeF)rrT)r_get_index_dtyperrmaxnnznpemptyr r*r astyperrhas_sorted_indices) rrrr idx_dtyperrrAs rr#z_csc_base.tocsr,sjj!))4;; *E+.txx+;*= !a%y1((48895xxtzz(:;!Q++$$Y/,,%%i0))      7F #**5   $r c|j|j\}}|j}tjt ||jj }t||j||j||f\}}|jdk7}||}||}tj|d}||}||}||fS)Nr)r mergesort)kind) _swaprrr.r/lenr*r rrargsort) r major_dim minor_dim minor_indices major_indicesrowcolnz_maskinds rnonzeroz_csc_base.nonzeroEs $zz$**5 9 ]!34<<;M;MN )T[[-8::}m<=S))q.'l'ljj;/#h#hCxr c|j\}}t|}|dkr||z }|dks||k\rtd|d|j|j S)z]Returns a copy of row i of the matrix, as a (1 x n) CSR matrix (row vector). rindex () out of rangeminor)rint IndexError_get_submatrixr#rirrs r_getrowz_csc_base._getrow^shzz1 F q5 FA q5AFwqc89 9"""+1133r c|j\}}t|}|dkr||z }|dks||k\rtd|d|j|dS)zcReturns a copy of column i of the matrix, as a (m x 1) CSC matrix (column vector). rrDrET)majorr)rrHrIrJrKs r_getcolz_csc_base._getcoljsazz1 F q5 FA q5AFwqc89 9"""66r cD|j|j|S)NrF)_major_index_fancyrJrr>r?s r_get_intXarrayz_csc_base._get_intXarrayvs!&&s+:::EEr c|jdvr|j||dS|j|j|S)NrNTrOrGrrF)steprJ _major_slicerSs r_get_intXslicez_csc_base._get_intXsliceysE 88y &&S$&G G  %4434??r c|jdvr|j||dS|j|j|S)NrVTrWrO)rXrJ _minor_slicerSs r_get_sliceXintz_csc_base._get_sliceXint~sE 88y &&S$&G G"""-::3??r cB|j|j|Sr")rRr]rSs r_get_sliceXarrayz_csc_base._get_sliceXarrays&&s+88==r c|j|j|}|jdkDr|j|jS|S)Nr\r)rJ_minor_index_fancyndimreshaper)rr>r?ress r_get_arrayXintz_csc_base._get_arrayXintsC!!!,??D 88a<;;syy) ) r cB|j|j|Sr")rYrbrSs r_get_arrayXslicez_csc_base._get_arrayXslices  %88==r c|d|dfS)zBswap the members of x if this is a column-oriented matrix rrxs rr7z_csc_base._swapstQqTzr )NF)F)__name__ __module__ __qualname___formatrr__doc__r$r&r#rBr rMrPrTrZr^r`rfrh staticmethodr7rjr rrrsG E ))11I  MM))EM.MM))EM.!((00GO 4 7F@ @ > > r rc"t|tS)aIs `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 ) isinstancerrks rrrs. a $$r ceZdZdZy)ra, 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]]) Nrmrnrorqrjr rrr[r rceZdZdZy)ra? 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]]) Nrvrjr rrrrwr r)rq __docformat____all__numpyr._matrixr_baserr _sparsetoolsr r _sputilsr _compressedr rrrrrjr rrs[,% 7#.#D DN%6\ 7\~\9\r