Ë
    ÏÍ:jºO  ã                   ó¸   — 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mZmZmZ dd	lmZ dd
lmZ  G d„ de«      Zd„ Z G d„ dee	«      Z G d„ dee«      Zy)z#Compressed Sparse Row matrix formatzrestructuredtext en)Ú	csr_arrayÚ
csr_matrixÚisspmatrix_csré    Né   )Úspmatrix)Ú_spbaseÚsparray)Ú	csr_tocscÚ	csr_tobsrÚcsr_count_blocksÚget_csr_submatrixÚcsr_sample_values)Úupcast)Ú
_cs_matrixc                   óø  ‡ — e Zd ZdZdZdd„Zej
                  j                  e_        dd„Zej                  j                  e_        dd„Z	ej                  j                  e	_        dˆ fd„	Z
ej                  j                  e
_        dd„Zej                  j                  e_        dd„Zej                  j                  e_        ed	„ «       Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zˆ xZS )Ú	_csr_baseÚcsr)r   é   c                 óø   — |�|dk7  rt        d«      ‚| j                  dk(  r|r| j                  «       S | S | j                  \  }}| j	                  | j
                  | j                  | j                  f||f|¬«      S )N)r   r   zvSparse arrays/matrices do not support an 'axes' parameter because swapping dimensions is the only logical permutation.r   ©ÚshapeÚcopy)Ú
ValueErrorÚndimr   r   Ú_csc_containerÚdataÚindicesÚindptr)ÚselfÚaxesr   ÚMÚNs        úf/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/scipy/sparse/_csr.pyÚ	transposez_csr_base.transpose   s‹   € ØÐ ¨¢Üð Ló Mð Mð �9‰9˜Š>Ù"&�4—9‘9“;Ð0¨DÐ0Ø�z‰z‰ˆˆ1Ø×"Ñ" D§I¡I¨t¯|©|Ø$(§K¡Kð$1Ø9:¸A¸ÀTð #ó Kð 	Kó    c                 óÌ  — | j                   dk7  rt        d«      ‚| j                  | j                  | j                  ¬«      }| j                  «        | j                  | j                  | j                  }}}|j                  |j                  }}t        | j                  d   «      D ];  }||   }	||dz      }
||	|
 j                  «       ||<   ||	|
 j                  «       ||<   Œ= |S )Nr   z.Cannot convert a 1d sparse array to lil format©Údtyper   r   )r   r   Ú_lil_containerr   r(   Úsum_duplicatesr   r   r   ÚrowsÚrangeÚtolist)r   r   ÚlilÚptrÚindÚdatr+   r   ÚnÚstartÚends              r#   Útolilz_csr_base.tolil$   sÕ   € Ø�9‰9˜Š>ÜÐMÓNÐNØ×!Ñ! $§*¡*°D·J±JÐ!Ó?ˆà×ÑÔØ—k‘k $§,¡,¨t¯y©y�ˆCˆØ—X‘X˜sŸx™xˆdˆä�t—z‘z !‘}Ó%ò 	.ˆAØ˜‘FˆEØ�a˜‘c‘(ˆCØ˜% �n×+Ñ+Ó-ˆD�‰GØ˜% �n×+Ñ+Ó-ˆD�ŠGð		.ð ˆ
r%   c                 ó*   — |r| j                  «       S | S ©N©r   )r   r   s     r#   Útocsrz_csr_base.tocsr7   s   € ÙØ—9‘9“;ÐàˆKr%   c                 óJ   •— t         ‰| �  |¬«      }| j                  |_        |S )Nr8   )ÚsuperÚtocooÚhas_canonical_format)r   r   ÚAÚ	__class__s      €r#   r<   z_csr_base.tocoo?   s(   ø€ Ü‰G‰M˜tˆMÓ$ˆð "&×!:Ñ!:ˆÔØˆr%   c           
      ó¢  — | j                   dk7  rt        d«      ‚| j                  \  }}| j                  | j                  | j
                  ft        | j                  |«      ¬«      }t        j                  |dz   |¬«      }t        j                  | j                  |¬«      }t        j                  | j                  t        | j                  «      ¬«      }t        ||| j                  j                  |d¬«      | j
                  j                  |d¬«      | j                  |||«       | j                  |||f| j                  ¬«      }d	|_        |S )
Nr   z.Cannot convert a 1d sparse array to csc format©Úmaxvalr   r'   Fr8   ©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#   Útocscz_csr_base.tocscI   s  € Ø�9‰9˜Š>ÜÐMÓNÐNØ�z‰z‰ˆˆ1Ø×)Ñ)¨4¯;©;¸¿¹Ð*EÜ+.¨t¯x©x¸Ó+;ð *ó =ˆ	ä—‘˜!˜a™% yÔ1ˆÜ—(‘(˜4Ÿ8™8¨9Ô5ˆÜ�x‰x˜Ÿ™¬¨t¯z©zÓ(:Ô;ˆä�!�QØ—+‘+×$Ñ$ Y°UÐ$Ó;Ø—,‘,×%Ñ% i°eÐ%Ó<Ø—)‘)ØØØô	ð ×Ñ  w°Ð 7¸t¿z¹zÐÓJˆØ#ˆÔØˆr%   c                 ó  — | j                   dk7  rt        d«      ‚|€ddlm} | j	                   || «      ¬«      S |dk(  rR| j
                  j                  ddd«      | j                  | j                  f}| j                  || j                  |¬«      S |\  }}| j                  \  }}|dk  s|dk  s||z  d	k7  s||z  d	k7  rt        d
|› �«      ‚t        ||||| j                  | j                  «      }	| j                  | j                  | j                  ft        ||z  |	«      ¬«      }
t        j                  ||z  dz   |
¬«      }t        j                  |	|
¬«      }t        j                   |	||f| j"                  ¬«      }t%        ||||| j                  j'                  |
d¬«      | j                  j'                  |
d¬«      | j
                  |||j)                  «       «
       | j                  |||f| j                  ¬«      S )Nr   z.Cannot convert a 1d sparse array to bsr formatr   )Úestimate_blocksize)Ú	blocksize)r   r   éÿÿÿÿr   r   zinvalid blocksize rA   r'   Fr8   rC   )r   r   Ú_spfuncsrN   Útobsrr   Úreshaper   r   Ú_bsr_containerr   r   rD   rE   rG   rH   Úzerosr(   r   rI   Úravel)r   rO   r   rN   Úarg1ÚRÚCr!   r"   ÚblksrK   r   r   r   s                 r#   rR   z_csr_base.tobsra   sÜ  € Ø�9‰9˜Š>ÜÐMÓNÐNØÐÝ4Ø—:‘:Ñ(:¸4Ó(@�:ÓAÐAà˜%ÒØ—I‘I×%Ñ% b¨¨1Ó-¨d¯l©l¸4¿;¹;ÐGˆDØ×&Ñ& t°4·:±:ÀDÐ&ÓIÐIð ‰CˆAˆaØ—*‘*‰CˆAˆaà�1Šu˜˜Aš  Q¡¨!¢¨q°1©u¸ªzÜ Ð#5°i°[Ð!AÓBÐBä# A a¨¨!¨D¯K©K¸¿¹ÓEˆDà×-Ñ-¨t¯{©{¸D¿L¹LÐ.IÜ/2°1°a±4¸«ð .ó @ˆIä—X‘X˜a ™d 1™f¨IÔ6ˆFÜ—h‘h˜t¨9Ô5ˆGÜ—8‘8˜T ! A˜J¨d¯j©jÔ9ˆDä�a˜˜A˜qØ—k‘k×(Ñ(¨¸Ð(Ó?Ø—l‘l×)Ñ)¨)¸%Ð)Ó@Ø—i‘iØ˜g t§z¡z£|ô	5ð ×&Ñ&Ø�w Ð'¨t¯z©zð 'ó ð r%   c                 ó   — | S )zBswap the members of x if this is a column-oriented matrix
        © ©Úxs    r#   Ú_swapz_csr_base._swap‰   s	   € ð ˆr%   c              #   ó¢  K  — | j                   dk(  rŠ| j                  j                  d«      }d}t        | j                  | j
                  «      D ]%  \  }}t        ||z
  «      D ]  }|–— Œ |–— |dz   }Œ' t        | j                  d   |z
  «      D ]  }|–— Œ y t        j                  d| j                  j                  ¬«      }t        | t        «      r| j                  dd  nd| j                  d   f}d}| j                  dd  D ]C  }	|	|z
  |d<   | j                  ||	 }
| j
                  ||	 }| j                  ||
|f|d¬«      –— |	}ŒE y ­w)Nr   r   r   r'   Tr   )r   r(   ÚtypeÚzipr   r   r,   r   rG   rU   r   Ú
isinstancer	   r?   )r   ÚzeroÚuÚvÚdÚ_r   r   Úi0Úi1r   r   s               r#   Ú__iter__z_csr_base.__iter__�   sM  è ø€ Ø�9‰9˜Š>Ø—:‘:—?‘? 1Ó%ˆDØˆAÜ˜DŸL™L¨$¯)©)Ó4ò ‘��1Ü˜q 1™u›ò �AØ“Jðà’Ø˜‘E‘ð	ô
 ˜4Ÿ:™: a™=¨1Ñ,Ó-ò �Ø“
ðàä—‘˜! 4§;¡;×#4Ñ#4Ô5ˆä",¨T´7Ô";�—
‘
˜1˜2‘À!ÀTÇZÁZÐPQÁ]ÐASˆØˆØ—+‘+˜a˜b�/ò 	ˆBØ˜R™ˆF�1‰IØ—l‘l 2 bÐ)ˆGØ—9‘9˜R Ð#ˆDØ—.‘. $¨°Ð!8ÀÈD�.ÓQÒQØ‰Bñ	ùs   ‚EEc                 ó¼  — | j                   dk(  r5|dvrt        d|› d�«      ‚| j                  d| j                  d   fd¬«      S | j                  \  }}t	        |«      }|dk  r||z  }|dk  s||k\  rt        d|› d�«      ‚t        ||| j                  | j                  | j                  ||dz   d|«	      \  }}}| j                  |||fd|f| j                  d¬	«      S )
z]Returns a copy of row i of the matrix, as a (1 x n)
        CSR matrix (row vector).
        r   )r   rP   úindex (ú) out of ranger   Tr8   F©r   r(   r   )r   Ú
IndexErrorrS   r   Úintr   r   r   r   r?   r(   ©r   Úir!   r"   r   r   r   s          r#   Ú_getrowz_csr_base._getrow§   sõ   € ð �9‰9˜Š>Ø˜ÑÜ  7¨1¨#¨^Ð!<Ó=Ð=Ø—<‘<  D§J¡J¨q¡MÐ 2¸�<Ó>Ð>à�z‰z‰ˆˆ1Ü�‹FˆØˆqŠ5Ø�‰FˆAØˆqŠ5�A˜’FÜ˜w q c¨Ð8Ó9Ð9Ü 1Øˆq�$—+‘+˜tŸ|™|¨T¯Y©Y¸¸1¸q¹5À!ÀQó!HÑˆ�˜à�~‰~˜t W¨fÐ5¸aÀ¸VØ$(§J¡J°Uð ó <ð 	<r%   c                 óh  — | j                   dk(  rt        d«      ‚| j                  \  }}t        |«      }|dk  r||z  }|dk  s||k\  rt	        d|› d�«      ‚t        ||| j                  | j                  | j                  d|||dz   «	      \  }}}| j                  |||f|df| j                  d¬«      S )zLReturns a copy of column i. A (m x 1) sparse array (column vector).
        r   z4getcol not provided for 1d arrays. Use indexing A[j]r   rm   rn   Fro   )r   r   r   rq   rp   r   r   r   r   r?   r(   rr   s          r#   Ú_getcolz_csr_base._getcol»   sÅ   € ð �9‰9˜Š>ÜÐSÓTÐTØ�z‰z‰ˆˆ1Ü�‹FˆØˆqŠ5Ø�‰FˆAØˆqŠ5�A˜’FÜ˜w q c¨Ð8Ó9Ð9Ü 1Øˆq�$—+‘+˜tŸ|™|¨T¯Y©Y¸¸1¸aÀÀQÁó!HÑˆ�˜à�~‰~˜t W¨fÐ5¸aÀ¸VØ$(§J¡J°Uð ó <ð 	<r%   c                 óÌ   — t        j                  | j                  |k(  «      }|j                  r| j                  |d      S | j                  j
                  j                  d«      S ©Nr   )rG   Úflatnonzeror   Úsizer   r(   ra   )r   ÚidxÚspots      r#   Ú_get_intz_csr_base._get_intË   sL   € Ü�~‰~˜dŸl™l¨cÑ1Ó2ˆØ�9Š9Ø—9‘9˜T !™WÑ%Ð%Ø�y‰y�‰×#Ñ# AÓ&Ð&r%   c                 óà   — |t        d «      k(  r| j                  «       S |j                  dv r2| j                  d|d¬«      }|j	                  |j
                  d   «      S | j                  |«      S )N©r   Nr   Tr8   rP   )Úslicer   ÚstepÚ_get_submatrixrS   r   Ú_minor_slice)r   r{   Úrets      r#   Ú
_get_slicez_csr_base._get_sliceÑ   se   € Ø”%˜“+ÒØ—9‘9“;ÐØ�8‰8�yÑ Ø×%Ñ% a¨°4Ð%Ó8ˆCØ—;‘;˜sŸy™y¨™}Ó-Ð-Ø× Ñ  Ó%Ð%r%   c                 ó¤  — | j                  | j                  «      }t        j                  ||¬«      }|j                  dk(  r| j                  g | j                  ¬«      S d| j                  d   }}t        j                  ||¬«      }t        j                  ||¬«      }t        j                  |j                  | j                  ¬«      }t        ||| j                  | j                  | j                  |j                  |||«	       |j                  d   dkD  r|j                  n|j                  d   f}| j                  |j                  |«      «      S )Nr'   r   r   )rD   r   rG   Úasarrayrz   r?   r(   r   Ú
zeros_likerH   r   r   r   rS   )	r   r{   rK   r!   r"   ÚrowÚcolÚvalÚ	new_shapes	            r#   Ú
_get_arrayz_csr_base._get_arrayÙ   sú   € Ø×)Ñ)¨$¯,©,Ó7ˆ	Ü�j‰j˜ IÔ.ˆØ�8‰8�qŠ=Ø—>‘> "¨D¯J©J�>Ó7Ð7à�$—*‘*˜Q‘-ˆ1ˆÜ�m‰m˜C yÔ1ˆÜ�j‰j˜ IÔ.ˆÜ�h‰h�s—x‘x t§z¡zÔ2ˆÜ˜!˜Q §¡¨T¯\©\¸4¿9¹9ØŸ(™( C¨¨cô	3ð "%§¡¨1¡°Ò!1�C—I’I¸¿	¹	À!¹°ˆ	Ø�~‰~˜cŸk™k¨)Ó4Ó5Ð5r%   c                 óB   — | j                  |«      j                  |«      S r7   )rt   Ú_minor_index_fancy©r   r‰   rŠ   s      r#   Ú_get_intXarrayz_csr_base._get_intXarrayé   s   € Ø�|‰|˜CÓ ×3Ñ3°CÓ8Ð8r%   c                 ó¶  — |j                   dv r| j                  ||d¬«      S | j                  \  }}|j                  |«      \  }}}| j                  ||dz    \  }}	| j                  ||	 }
| j
                  ||	 }|dkD  r|
|k\  |
|k  z  }n|
|k  |
|kD  z  }t        |«      dkD  r||
|z
  |z  dk(  z  }|
|   |z
  |z  }
||   }t        j                  dt        |
«      g«      }|dk  r|d d d…   }t        |
d d d…   «      }
dt        dt        t        j                  t        ||z
  «      |z  «      «      «      f}| j                  ||
|f|| j                  d¬	«      S )
Nr   Tr8   r   r   r   rP   Fro   )r�   r‚   r   r   r   r   ÚabsrG   ÚarrayÚlenrE   rq   ÚceilÚfloatr?   r(   )r   r‰   rŠ   r!   r"   r3   ÚstopÚstrideÚiiÚjjÚrow_indicesÚrow_datar0   Ú
row_indptrr   s                  r#   Ú_get_intXslicez_csr_base._get_intXsliceì   s‡  € Ø�8‰8�yÑ Ø×&Ñ& s¨C°dÐ&Ó;Ð;ð �z‰z‰ˆˆ1Ø!Ÿk™k¨!›nÑˆˆt�Và—‘˜S  Q¡Ð'‰ˆˆBØ—l‘l 2 bÐ)ˆØ—9‘9˜R Ð#ˆà�AŠ:Ø %Ñ'¨K¸$Ñ,>Ñ?‰Cà %Ñ'¨K¸$Ñ,>Ñ?ˆCäˆv‹;˜Š?Ø�K %Ñ'¨6Ñ1°QÑ6Ñ6ˆCà" 3Ñ'¨%Ñ/°FÑ:ˆØ˜C‘=ˆÜ—X‘X˜q¤# kÓ"2Ð3Ó4ˆ
à�AŠ:Ø¡ " ‘~ˆHÜ˜k©$¨B¨$Ñ/Ó0ˆKà”C˜œ3œrŸw™w¤u¨T°E©\Ó':¸VÑ'CÓDÓEÓFÐGˆØ�~‰~˜x¨°jÐAÈØ$(§J¡J°Uð ó <ð 	<r%   c                 óˆ   — |j                   dv r| j                  ||d¬«      S | j                  |«      j                  |¬«      S )Nr   Tr8   ©Úminor)r�   r‚   Ú_major_slicer�   s      r#   Ú_get_sliceXintz_csr_base._get_sliceXint  sE   € Ø�8‰8�yÑ Ø×&Ñ& s¨C°dÐ&Ó;Ð;Ø× Ñ  Ó%×4Ñ4¸3Ð4Ó?Ð?r%   c                 óB   — | j                  |«      j                  |«      S r7   )r£   r�   r�   s      r#   Ú_get_sliceXarrayz_csr_base._get_sliceXarray  s   € Ø× Ñ  Ó%×8Ñ8¸Ó=Ð=r%   c                 óœ   — | j                  |«      j                  |¬«      }|j                  dkD  r|j                  |j                  «      S |S )Nr¡   r   )Ú_major_index_fancyr‚   r   rS   r   )r   r‰   rŠ   Úress       r#   Ú_get_arrayXintz_csr_base._get_arrayXint  sC   € Ø×%Ñ% cÓ*×9Ñ9ÀÐ9ÓDˆØ�8‰8�aŠ<Ø—;‘;˜sŸy™yÓ)Ð)Øˆ
r%   c                 óà   — |j                   dvr@t        j                  |j                  | j                  d   «      Ž }| j                  ||«      S | j                  |«      j                  |¬«      S )Nr   r   r¡   )r�   rG   Úaranger   r   Ú_get_arrayXarrayr¨   r‚   r�   s      r#   Ú_get_arrayXslicez_csr_base._get_arrayXslice  s_   € Ø�8‰8˜9Ñ$Ü—)‘)˜SŸ[™[¨¯©°A©Ó7Ð8ˆCØ×(Ñ(¨¨cÓ2Ð2Ø×&Ñ& sÓ+×:Ñ:ÀÐ:ÓEÐEr%   c                 ó*   — | j                  d||«       y rx   )Ú	_set_many©r   r{   r^   s      r#   Ú_set_intz_csr_base._set_int!  s   € Ø�‰�q˜#˜qÕ!r%   c                 ó�   — t        j                  ||j                  «      }| j                  t        j                  |«      ||«       y r7   )rG   Úbroadcast_tor   r°   rˆ   r±   s      r#   Ú
_set_arrayz_csr_base._set_array$  s/   € Ü�O‰O˜A˜sŸy™yÓ)ˆØ�‰”r—}‘} SÓ)¨3°Õ2r%   )NF)F)NT)Ú__name__Ú
__module__Ú__qualname__Ú_formatÚ	_allow_ndr$   r   Ú__doc__r5   r9   r<   rL   rR   Ústaticmethodr_   rk   rt   rv   r}   r…   r�   r‘   rŸ   r¤   r¦   rª   r®   r²   rµ   Ú__classcell__)r?   s   @r#   r   r      sÿ   ø„ Ø€GØ€Ió
Kð  ×)Ñ)×1Ñ1€IÔóð" —M‘M×)Ñ)€E„Móð —M‘M×)Ñ)€E„Mõð —M‘M×)Ñ)€E„Móð, —M‘M×)Ñ)€E„Mó"ðH —M‘M×)Ñ)€E„Mð ñó ðò
ò0<ò(<ò 'ò&ò6ò 9ò<òB@ò
>òòFò"ö3r%   r   c                 ó"   — t        | t        «      S )a”  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
    )rc   r   r]   s    r#   r   r   )  s   € ô@ �aœÓ$Ð$r%   c                   ó   — e Zd ZdZy)r   ab  
    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]])

    N©r¶   r·   r¸   r»   r\   r%   r#   r   r   M  s   „ ò@r%   r   c                   ó   — e Zd ZdZy)r   a4  
    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]])

    NrÀ   r\   r%   r#   r   r   Ñ  s   „ òIr%   r   )r»   Ú__docformat__Ú__all__ÚnumpyrG   Ú_matrixr   Ú_baser   r	   Ú_sparsetoolsr
   r   r   r   r   Ú_sputilsr   Ú_compressedr   r   r   r   r   r\   r%   r#   ú<module>rÊ      sc   ðÙ )à%€â
7€ã å ß #÷Aõ Aå å #ôT3�
ô T3òn %ôHA�	˜7ô AôHJ�˜9õ Jr%   