+
    nDjO                         R t Rt. ROt^ RIt^RIHt ^RIHtH	t	 ^RI
HtHtHtHtHt ^RIHt ^R	IHt  ! R
 R]4      tR t ! R R]]	4      t ! R R]]4      tR# )z#Compressed Sparse Row matrix formatzrestructuredtext en	csr_array
csr_matrixN)spmatrix)_spbasesparray)	csr_tocsc	csr_tobsrcsr_count_blocksget_csr_submatrixcsr_sample_values)upcast)
_cs_matrixc                     a a ] tR t^t oRtRtRR lt]P                  P                  ]n        RR lt	]P                  P                  ]	n        RR lt
]P                  P                  ]
n        RV 3R llt]P                  P                  ]n        RR lt]P                  P                  ]n        RR lt]P                  P                  ]n        ]R 4       tR	 tR
 tR tR tR tR tR tR tR tR tR tR tR tR tRtVtV ;t # )	_csr_basecsrc                   Ve   VR8w  d   \        R4      hV P                  ^8X  d   V'       d   V P                  4       # T # V P                  w  r4V P	                  V P
                  V P                  V P                  3WC3VR7      # )NzvSparse arrays/matrices do not support an 'axes' parameter because swapping dimensions is the only logical permutation.shapecopy)       )
ValueErrorndimr   r   _csc_containerdataindicesindptr)selfaxesr   MNs   &&&  K/data/cameron/venvs/s3viz/lib/python3.14/site-packages/scipy/sparse/_csr.py	transpose_csr_base.transpose   s     L M M 99>"&499;0D0zz""DIIt||$(KK$19:T # K 	K    c                   V P                   ^8w  d   \        R4      hV P                  V P                  V P                  R7      pV P                  4        V P                  V P                  V P                  rTpVP                  VP                  rv\        V P                  ^ ,          4       FB  pW8,          p	W8^,           ,          p
WIV
 P                  4       Wh&   WYV
 P                  4       Wx&   KD  	  V# )   z.Cannot convert a 1d sparse array to lil formatdtype)r   r   _lil_containerr   r(   sum_duplicatesr   r   r   rowsrangetolist)r   r   lilptrinddatr+   r   nstartends   &&         r!   tolil_csr_base.tolil$   s    99>MNN!!$**DJJ!?kk$,,tyyXXsxxdtzz!}%AFEc(Cn++-DGn++-DG	 & 
r$   c                6    V'       d   V P                  4       # V # Nr   )r   r   s   &&r!   tocsr_csr_base.tocsr7   s    99;Kr$   c                J   < \         SV `  VR 7      pV P                  Vn        V# )r9   )supertocoohas_canonical_format)r   r   A	__class__s   && r!   r>   _csr_base.tocoo?   s(    GMtM$ "&!:!:r$   c           
        V P                   ^8w  d   \        R4      hV P                  w  r#V P                  V P                  V P
                  3\        V P                  V4      R7      p\        P                  ! V^,           VR7      p\        P                  ! V P                  VR7      p\        P                  ! V P                  \        V P                  4      R7      p\        W#V P                  P                  VRR7      V P
                  P                  VRR7      V P                  VVV4       V P                  WvV3V P                  R7      pRVn        V# )r&   z.Cannot convert a 1d sparse array to csc formatmaxvalr'   Fr9   r   T)r   r   r   _get_index_dtyper   r   maxnnznpemptyr   r(   r   astyper   r   has_sorted_indices)	r   r   r   r    	idx_dtyper   r   r   r@   s	   &&       r!   tocsc_csr_base.tocscI   s   99>MNNzz))4;;*E+.txx+; * =	!a%y1((48895xxtzz(:;!++$$YU$;,,%%ie%<))	  7tzzJ#r$   c                0   V P                   ^8w  d   \        R4      hVf   ^RIHp V P	                  V! V 4      R7      # VR8X  dR   V P
                  P                  R^^4      V P                  V P                  3pV P                  W@P                  VR7      # Vw  rVV P                  w  rxV^8  g"   V^8  g   Wu,          ^ 8w  g   W,          ^ 8w  d   \        RV 24      h\        WxWVV P                  V P                  4      p	V P                  V P                  V P                  3\        W,          V	4      R7      p
\        P                  ! Wu,          ^,           V
R7      p\        P                  ! WR7      p\        P                   ! WV3V P"                  R7      p\%        WxWVV P                  P'                  V
RR	7      V P                  P'                  V
RR	7      V P
                  WVP)                  4       4
       V P                  WV3V P                  R
7      # )r&   z.Cannot convert a 1d sparse array to bsr format)estimate_blocksize)	blocksizer   zinvalid blocksize rD   r'   Fr9   rF   )r   r   )r   r   _spfuncsrR   tobsrr   reshaper   r   _bsr_containerr   r	   rG   rH   rJ   rK   zerosr(   r   rL   ravel)r   rS   r   rR   arg1RCr   r    blksrN   r   r   r   s   &&&           r!   rV   _csr_base.tobsra   s   99>MNN4::(:4(@:AA%II%%b1-dll4;;GD&&t::D&II CA**CA1uA!quz #5i[!ABB#ADKKED--t{{DLL.I/214 . @IXXad1fI6Fhht5G88TAJdjj9DaAkk(((?ll)))%)@iitzz|	5 &&'tzz '  r$   c                    V # )zBswap the members of x if this is a column-oriented matrix
         xs   &r!   _swap_csr_base._swap   s	     r$   c              #    "   V P                   ^8X  d   V P                  P                  ^ 4      p^ p\        V P                  V P
                  4       F.  w  r4\        W2,
          4       F  pVx  K	  	  Vx  V^,           pK0  	  \        V P                  ^ ,          V,
          4       F  pVx  K	  	  R# \        P                  ! ^V P                  P                  R7      p\        V \        4      '       d   V P                  R,          M^V P                  ^,          3p^ pV P                  R,           FD  p	W,
          V^&   V P                  W p
V P
                  W pV P                  WV3VRR7      x  T	pKF  	  R# 5i)r   Nr'   :r   NNTr   )r   r(   typezipr   r   r,   r   rJ   rY   r   
isinstancer   rA   )r   zerouvd_r   r   i0i1r   r   s   &           r!   __iter___csr_base.__iter__   s-    99>::??1%DADLL$))4quAJ &E	 5
 4::a=1,-
 .!4;;#4#45",T7";";

2!TZZPQ]AS++b//BF1Ill2)G99R#D..$!8D.QQB "s   E:E<c                   V P                   ^8X  d=   VR9  d   \        RV R24      hV P                  ^V P                  ^ ,          3RR7      # V P                  w  r#\	        V4      pV^ 8  d	   W,          pV^ 8  g   W8  d   \        RV R24      h\        W#V P                  V P                  V P                  W^,           ^ V4	      w  rEpV P                  WeV3^V3V P                  RR7      # )zMReturns a copy of row i of the matrix, as a (1 x n)
CSR matrix (row vector).
index () out of rangeTr9   Fr   r(   r   )r   rT   )r   
IndexErrorrW   r   intr
   r   r   r   rA   r(   r   ir   r    r   r   r   s   &&     r!   _getrow_csr_base._getrow   s     99> 71#^!<==<<DJJqM 2<>>zzFq5FAq5AFwqc899 1$++t||TYYq5!Q!H~~tf5aV$(JJU  < 	<r$   c                z   V P                   ^8X  d   \        R4      hV P                  w  r#\        V4      pV^ 8  d	   W,          pV^ 8  g   W8  d   \	        RV R24      h\        W#V P                  V P                  V P                  ^ W!V^,           4	      w  rEpV P                  WeV3V^3V P                  RR7      # )zLReturns a copy of column i. A (m x 1) sparse array (column vector).
        z4getcol not provided for 1d arrays. Use indexing A[j]rt   ru   Frv   )r   r   r   rx   rw   r
   r   r   r   rA   r(   ry   s   &&     r!   _getcol_csr_base._getcol   s     99>STTzzFq5FAq5AFwqc899 1$++t||TYY1Q!H~~tf5aV$(JJU  < 	<r$   c                    \         P                  ! V P                  V8H  4      pVP                  '       d   V P                  V^ ,          ,          # V P                  P
                  P                  ^ 4      # )r   )rJ   flatnonzeror   sizer   r(   rg   )r   idxspots   && r!   _get_int_csr_base._get_int   sN    ~~dllc1299999T!W%%yy##A&&r$   c                    V\        R 4      8X  d   V P                  4       # VP                  R9   d7   V P                  ^ VRR7      pVP	                  VP
                  R,          4      # V P                  V4      # )NTr9   r   NrT   )slicer   step_get_submatrixrW   r   _minor_slice)r   r   rets   && r!   
_get_slice_csr_base._get_slice   se    %+99;88y %%a4%8C;;syy}--  %%r$   c                   V P                  V P                  4      p\        P                  ! WR 7      pVP                  ^ 8X  d   V P                  . V P                  R 7      # ^V P                  ^ ,          rC\        P                  ! WR 7      p\        P                  ! WR 7      p\        P                  ! VP                  V P                  R 7      p\        W4V P                  V P                  V P                  VP                  WVV4	       VP                  ^ ,          ^8  d   VP                  MVP                  ^ ,          3pV P                  VP                  V4      4      # )r'   )rG   r   rJ   asarrayr   rA   r(   r   
zeros_likerK   r   r   r   rW   )	r   r   rN   r   r    rowcolval	new_shapes	   &&       r!   
_get_array_csr_base._get_array   s    ))$,,7	jj.88q=>>"DJJ>77$**Q-1mmC1jj.hhsxxtzz2!T\\499((Cc	3 "%1!1CII		!	~~ckk)455r$   c                B    V P                  V4      P                  V4      # r8   )r{   _minor_index_fancyr   r   r   s   &&&r!   _get_intXarray_csr_base._get_intXarray   s    ||C 33C88r$   c                   VP                   R9   d   V P                  WRR7      # V P                  w  r4VP                  V4      w  rVpV P                  W^,            w  rV P                  W p
V P
                  W pV^ 8  d   W8  W8  ,          pMW8*  W8  ,          p\        V4      ^8  d   WV,
          V,          ^ 8H  ,          pW,          V,
          V,          p
W,          p\        P                  ! ^ \        V
4      .4      pV^ 8  d"   VRRR1,          p\        V
RRR1,          4      p
^\        ^ \        \        P                  ! \        We,
          4      V,          4      4      4      3pV P                  WV3VV P                  RR7      # )r   NTr9   Frv   r   rT   )r   r   r   r   r   r   absrJ   arraylenrH   rx   ceilfloatrA   r(   )r   r   r   r   r    r3   stopstrideiijjrow_indicesrow_datar0   
row_indptrr   s   &&&            r!   _get_intXslice_csr_base._get_intXslice   sg   88y &&sd&;; zz!kk!nVSQ'll2)99R#A:'K,>?C'K,>?Cv;?%'61Q66C"'%/F:=XXq#k"234
A:"~Hk$B$/0KC3rwwuT\':V'CDEFG~~xjA$(JJU  < 	<r$   c                    VP                   R9   d   V P                  WRR7      # V P                  V4      P                  VR7      # )r   Tr9   minorr   )r   r   _major_slicer   s   &&&r!   _get_sliceXint_csr_base._get_sliceXint  sC    88y &&sd&;;  %4434??r$   c                B    V P                  V4      P                  V4      # r8   )r   r   r   s   &&&r!   _get_sliceXarray_csr_base._get_sliceXarray  s      %88==r$   c                    V P                  V4      P                  VR 7      pVP                  ^8  d   VP                  VP                  4      # V# )r   )_major_index_fancyr   r   rW   r   )r   r   r   ress   &&& r!   _get_arrayXint_csr_base._get_arrayXint  sC    %%c*999D88a<;;syy))
r$   c                    VP                   R9  dF   \        P                  ! VP                  V P                  ^,          4      !  pV P                  W4      # V P                  V4      P                  VR7      # )r   r   r   )r   rJ   aranger   r   _get_arrayXarrayr   r   r   s   &&&r!   _get_arrayXslice_csr_base._get_arrayXslice  s]    889$))S[[A78C((22&&s+:::EEr$   c                *    V P                  ^ W4       R# )r   N)	_set_manyr   r   rc   s   &&&r!   _set_int_csr_base._set_int!  s    q#!r$   c                    \         P                  ! W!P                  4      pV P                  \         P                  ! V4      W4       R # r8   )rJ   broadcast_tor   r   r   r   s   &&&r!   
_set_array_csr_base._set_array$  s+    OOAyy)r}}S)32r$   ra   )r   r&   )NF)F)NT)!__name__
__module____qualname____firstlineno___format	_allow_ndr"   r   __doc__r5   r:   r>   rO   rV   staticmethodrd   rq   r{   r~   r   r   r   r   r   r   r   r   r   r   r   __static_attributes____classdictcell____classcell__)rA   __classdict__s   @@r!   r   r      s    GI
K  ))11I" MM))EM MM))EM MM))EM, MM))EM"H MM))EM  
0<(< '&6 9<B@
>F"3 3r$   r   c                "    \        V \        4      # )a0  Is `x` of csr_matrix type?

.. warning::

   SciPy sparse is shifting from a sparse matrix interface to a sparse
   array interface. In the next few releases we expect to deprecate the
   sparse matrix interface. For documentation of the matrix
   interface, see the :ref:`spmatrix interface docs <spmatrix_api>`.
   For guidance on converting existing code to sparse arrays, see
   :ref:`Migration from spmatrix to sparray <migration_to_sparray>`.

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

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

Examples
--------
>>> from scipy.sparse import csr_array, csr_matrix, coo_matrix, isspmatrix_csr
>>> isspmatrix_csr(csr_matrix([[5]]))
True
>>> isspmatrix_csr(csr_array([[5]]))
False
>>> isspmatrix_csr(coo_matrix([[5]]))
False
)ri   r   rb   s   &r!   isspmatrix_csrr   )  s    @ a$$r$   c                       ] tR tRtRtRtR# )r   iM  a  
Compressed Sparse Row array.

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

    csr_array(S)
        with another sparse array or matrix S (equivalent to S.tocsr())

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

    csr_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]``.

    csr_array((data, indices, indptr), [shape=(M, N)])
        is the standard CSR representation where the column indices for
        row 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
----------
data : ndarray
    CSR format data array of the array
indices : ndarray
    CSR format index array of the array
indptr : ndarray
    CSR format index pointer array of the array
has_sorted_indices : bool
    Whether indices are sorted
has_canonical_format : bool
    Whether indices are sorted and no duplicate entries exist
dtype : dtype
    Data type of the array
shape : 2-tuple
    Shape of the array
ndim : int
    Number of dimensions (this is always 2)
format : str
    Three letter code for the format of the array storage, e.g. 'csr'
nnz : int
    Number of values stored in the array
size : int
    Number of values stored in the array
T : csr_array
    The transpose of the array
mT : csr_array
    The matrix transpose of the array

Notes
-----

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

Advantages of the CSR format
  - efficient arithmetic operations CSR + CSR, CSR * CSR, etc.
  - efficient row slicing
  - fast matrix vector products

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

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

Examples
--------

>>> import numpy as np
>>> from scipy.sparse import csr_array
>>> csr_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, 0, 1, 2, 2, 2])
>>> col = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3, 4, 5, 6])
>>> csr_array((data, (row, col)), shape=(3, 3)).toarray()
array([[1, 0, 2],
       [0, 0, 3],
       [4, 5, 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])
>>> csr_array((data, indices, indptr), shape=(3, 3)).toarray()
array([[1, 0, 2],
       [0, 0, 3],
       [4, 5, 6]])

Duplicate entries are summed together:

>>> row = np.array([0, 1, 2, 0])
>>> col = np.array([0, 1, 1, 0])
>>> data = np.array([1, 2, 4, 8])
>>> csr_array((data, (row, col)), shape=(3, 3)).toarray()
array([[9, 0, 0],
       [0, 2, 0],
       [0, 4, 0]])

As an example of how to construct a CSR array incrementally,
the following snippet builds a term-document array from texts:

>>> docs = [["hello", "world", "hello"], ["goodbye", "cruel", "world"]]
>>> indptr = [0]
>>> indices = []
>>> data = []
>>> vocabulary = {}
>>> for d in docs:
...     for term in d:
...         index = vocabulary.setdefault(term, len(vocabulary))
...         indices.append(index)
...         data.append(1)
...     indptr.append(len(indices))
...
>>> csr_array((data, indices, indptr), dtype=int).toarray()
array([[2, 1, 0, 0],
       [0, 1, 1, 1]])

ra   Nr   r   r   r   r   r   ra   r$   r!   r   r   M  s    @r$   c                       ] tR tRtRtRtR# )r   i  ah  
Compressed Sparse Row matrix.

.. warning::

   SciPy sparse is shifting from a sparse matrix interface to a sparse
   array interface. In the next few releases we expect to deprecate the
   sparse matrix interface. For documentation of the matrix
   interface, see the :ref:`spmatrix interface docs <spmatrix_api>`.
   For guidance on converting existing code to sparse arrays, see
   :ref:`Migration from spmatrix to sparray <migration_to_sparray>`.

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

    csr_matrix(S)
        with another sparse array or matrix S (equivalent to S.tocsr())

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

    csr_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]``.

    csr_matrix((data, indices, indptr), [shape=(M, N)])
        is the standard CSR representation where the column indices for
        row 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
----------
data : ndarray
    CSR format data array of the matrix
indices : ndarray
    CSR format index array of the matrix
indptr : ndarray
    CSR format index pointer array of the matrix
has_sorted_indices : bool
    Whether indices are sorted
has_canonical_format : bool
    Whether indices are sorted and no duplicate entries exist
dtype : dtype
    Data type of the matrix
shape : 2-tuple
    Shape of the matrix
ndim : int
    Number of dimensions (this is always 2)
format : str
    Three letter code for the format of the matrix storage, e.g. 'csr'
nnz : int
    Number of values stored in the matrix
size : int
    Number of values stored in the matrix
T : csr_matrix
    The transpose of the matrix
mT : csr_matrix
    The matrix transpose

Notes
-----

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

Advantages of the CSR format
  - efficient arithmetic operations CSR + CSR, CSR * CSR, etc.
  - efficient row slicing
  - fast matrix vector products

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

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

Examples
--------

>>> import numpy as np
>>> from scipy.sparse import csr_matrix
>>> csr_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, 0, 1, 2, 2, 2])
>>> col = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3, 4, 5, 6])
>>> csr_matrix((data, (row, col)), shape=(3, 3)).toarray()
array([[1, 0, 2],
       [0, 0, 3],
       [4, 5, 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])
>>> csr_matrix((data, indices, indptr), shape=(3, 3)).toarray()
array([[1, 0, 2],
       [0, 0, 3],
       [4, 5, 6]])

Duplicate entries are summed together:

>>> row = np.array([0, 1, 2, 0])
>>> col = np.array([0, 1, 1, 0])
>>> data = np.array([1, 2, 4, 8])
>>> csr_matrix((data, (row, col)), shape=(3, 3)).toarray()
array([[9, 0, 0],
       [0, 2, 0],
       [0, 4, 0]])

As an example of how to construct a CSR matrix incrementally,
the following snippet builds a term-document matrix from texts:

>>> docs = [["hello", "world", "hello"], ["goodbye", "cruel", "world"]]
>>> indptr = [0]
>>> indices = []
>>> data = []
>>> vocabulary = {}
>>> for d in docs:
...     for term in d:
...         index = vocabulary.setdefault(term, len(vocabulary))
...         indices.append(index)
...         data.append(1)
...     indptr.append(len(indices))
...
>>> csr_matrix((data, indices, indptr), dtype=int).toarray()
array([[2, 1, 0, 0],
       [0, 1, 1, 1]])

ra   Nr   ra   r$   r!   r   r     s    Ir$   )r   r   r   )r   __docformat____all__numpyrJ   _matrixr   _baser   r   _sparsetoolsr   r   r	   r
   r   _sputilsr   _compressedr   r   r   r   r   ra   r$   r!   <module>r      sc    )%
7   #A A  #T3
 T3n %HA	7 AHJ9 Jr$   