Ë
    þ�DjŠ€  ã                   ó  — d Z dZg d¢ZddlZddlmZ ddlZddlm	Z	 dd	l
mZ dd
lmZmZmZ ddlmZmZmZmZ ddlmZmZ ddlmZmZmZmZmZmZmZm Z m!Z! ddl"Z" G d„ dee«      Z#dd„Z$d„ Z% G d„ de#e«      Z& G d„ dee#«      Z'y)z2 A sparse matrix in COOrdinate or 'triplet' formatzrestructuredtext en)Ú	coo_arrayÚ
coo_matrixÚisspmatrix_cooé    N)Úwarné   )Úcopy_if_neededé   )Úspmatrix)Ú	coo_tocsrÚcoo_todenseÚ
coo_matvec)ÚissparseÚSparseEfficiencyWarningÚ_spbaseÚsparray)Ú_data_matrixÚ_minmax_mixin)	Úupcast_charÚ	to_nativeÚisshapeÚgetdtypeÚgetdataÚdowncast_intp_indexÚget_index_dtypeÚcheck_shapeÚcheck_reshape_kwargsc                   óþ  — e Zd ZdZdd„Zed„ «       Zej                  d„ «       Zed„ «       Zej                  d„ «       Zd„ Z	e
j                  j                  e	_        dd	„Ze
j                  j                  e_        d
„ Zdd„Ze
j                  j                  e_        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e
j(                  j                  e_        d"d„Ze
j*                  j                  e_        d"d„Ze
j,                  j                  e_        d#d„Zej.                  j                  e_        d„ Zd$d„Zd d„Zd„ Zd„ Zd„ Zd„ Zd„ Z y)%Ú	_coo_baseÚcooNc                 óÚ  ‡‡‡— t        j                  | |«       t        | t        «      }‰st        Št        |t
        «      �rUt        ||¬«      r¢t        ||¬«      | _        | j                  t        | j                  «      ¬«      Št        |t        ¬«      }t        ˆfd„t        t        | j                  «      «      D «       «      | _        t!        j"                  g |¬«      | _        d| _        �n£	 |\  }}|€/t-        d„ |D «       «      rt+        d	«      ‚t        d
„ |D «       «      }t        ||¬«      | _        | j                  |t        | j.                  «      d¬«      Št        ˆˆfd„|D «       «      | _        t1        |‰|¬«      | _        d| _        �nýt3        |«      rê|j4                  | j4                  k(  rq‰rot        d„ |j                  D «       «      | _        |j$                  j7                  «       | _        t        |j.                  |¬«      | _        |j&                  | _        �nh|j9                  «       }
t        |
j                  «      | _        |
j$                  | _        t        |
j.                  |¬«      | _        d| _        �nt!        j:                  |«      }|s=t!        j<                  |«      }|j>                  dk7  rt)        d|j>                  › d�«      ‚t        |j.                  |¬«      | _        |�7t        ||¬«      | j                  k7  rd|› d| j                  › �}t+        |«      ‚| j                  t        | j                  «      ¬«      Š|jA                  «       }t        ˆfd„|D «       «      | _        ||   | _        d| _        |�"| j$                  jC                  |d¬«      | _        | jE                  «        y # t(        t*        f$ r}	t)        d«      |	‚d }	~	ww xY w)N©Úallow_1d©Úmaxval)Údefaultc              3   óL   •K  — | ]  }t        j                  g ‰¬ «      –— Œ y­w©©ÚdtypeN©ÚnpÚarray)Ú.0Ú_Ú	idx_dtypes     €úUC:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\scipy/sparse/_coo.pyú	<genexpr>z%_coo_base.__init__.<locals>.<genexpr>&   s)   øè ø€ ò $GØ)*ô %'§H¡H¨R°y×$AÐ$Añ $Gùó   ƒ!$r(   Tzinvalid input formatc              3   ó8   K  — | ]  }t        |«      d k(  –— Œ y­w)r   N©Úlen©r-   Úidxs     r0   r1   z%_coo_base.__init__.<locals>.<genexpr>1   s   è ø€ Ò;¨Sœ3˜s›8 q�=Ñ;ùs   ‚z4cannot infer dimensions from zero sized index arraysc              3   ór   K  — | ]/  }t        j                  t        j                  |«      «      d z   –— Œ1 y­w©r	   N)ÚoperatorÚindexr+   Úmaxr6   s     r0   r1   z%_coo_base.__init__.<locals>.<genexpr>4   s.   è ø€ ò "5Ø&)ô #+§.¡.´·±¸³Ó"=ÀÕ"Añ "5ùs   ‚57)r$   Úcheck_contentsc              3   óN   •K  — | ]  }t        j                  |‰‰¬ «      –— Œ y­w)©Úcopyr)   Nr*   )r-   r7   r@   r/   s     €€r0   r1   z%_coo_base.__init__.<locals>.<genexpr>;   s)   øè ø€ ò $8Ø),ô %'§H¡H¨S°tÀ9×$MÐ$Mñ $8ùs   ƒ"%r?   Fc              3   ó<   K  — | ]  }|j                  «       –— Œ y ­w©N©r@   r6   s     r0   r1   z%_coo_base.__init__.<locals>.<genexpr>B   s   è ø€ Ò'J°s¨¯©¯
Ñ'Jùó   ‚r   z!expected 2D array or matrix, not ÚDzinconsistent shapes: z != c              3   óD   •K  — | ]  }|j                  ‰d ¬«      –— Œ y­w)FrC   N)Úastype)r-   r7   Úindex_dtypes     €r0   r1   z%_coo_base.__init__.<locals>.<genexpr>[   s&   øè ø€ ò $8Ø),ð %(§J¡J¨{À J×$Gñ $8ùs   ƒ rC   )#r   Ú__init__Ú
isinstancer   r   Útupler   r   Ú_shapeÚ_get_index_dtyper<   r   ÚfloatÚranger5   Úcoordsr+   r,   ÚdataÚhas_canonical_formatÚ	TypeErrorÚ
ValueErrorÚanyÚshaper   r   Úformatr@   ÚtocooÚasarrayÚ
atleast_2dÚndimÚnonzerorG   Ú_check)ÚselfÚarg1rV   r)   r@   Úis_arrayÚ
data_dtypeÚobjrP   Úer   ÚMÚmessager/   rH   s       `        @@r0   rI   z_coo_base.__init__   sA  ú€ Ü×Ñ˜d DÔ)Ü˜d¤GÓ,ˆÙÜ!ˆDä�dœEÕ"Ü�t hÕ/Ü)¨$¸ÔB�”Ø ×1Ñ1¼¸T¿[¹[Ó9IÐ1ÓJ�	Ü% e´UÔ;�
Ü#ó $GÜ.3´C¸¿¹Ó4DÓ.Eô$Gó G�”äŸH™H R¨zÔ:�”	Ø,0�Ö)ðCØ"&‘K�C˜ð �=ÜÑ;°FÔ;Ô;Ü(ð *>ó ?ð ?ä!ñ "5Ø-3ô"5ó 5�Eä)¨%¸(ÔC�”à ×1Ñ1°&Ü9<¸T¿Z¹Z»ØAEð 2ó G�	ô $ô $8Ø06ô$8ó 8�”ä# C¨d¸%Ô@�”	Ø,1�Ö)ä˜Œ~Ø—;‘; $§+¡+Ò-±$Ü"'Ñ'J¸d¿k¹kÔ'JÓ"J�D”KØ $§	¡	§¡Ó 0�D”IÜ"-¨d¯j©jÀ8Ô"L�D”KØ04×0IÑ0I�DÖ-àŸ*™*›,�CÜ"'¨¯
©
Ó"3�D”KØ #§¡�D”IÜ"-¨c¯i©iÀ(Ô"K�D”KØ05�DÖ-ô —J‘J˜tÓ$�ÙÜŸ™ aÓ(�AØ—v‘v ’{Ü'Ð*KÈAÏFÉFÈ8ÐSTÐ(UÓVÐVä)¨!¯'©'¸HÔE�”ØÐ$Ü" 5°8Ô<ÀÇÁÒKØ$9¸%¸ÀÀTÇ[Á[ÀMÐ"R˜Ü(¨Ó1Ð1Ø"×3Ñ3¼3¸t¿{¹{Ó;KÐ3ÓL�ØŸ™›�Ü#ó $8Ø06ô$8ó 8�”à˜f™I�”	Ø,0�Ô)àÐØŸ	™	×(Ñ(¨°UÐ(Ó;ˆDŒIà�‰�øôm "¤:Ð.ò CÜ#Ð$:Ó;ÀÐBûðCús   Ã3O
 Ï
O*ÏO%Ï%O*c                 ó¤   — | j                   dkD  r| j                  d   S t        j                  | j                  «      }|j                  d¬«       |S )Nr	   éþÿÿÿF)Úwrite)r[   rP   r+   Ú
zeros_likeÚcolÚsetflags)r^   Úresults     r0   Úrowz_coo_base.rowe   s@   € à�9‰9�qŠ=Ø—;‘;˜r‘?Ð"Ü—‘˜tŸx™xÓ(ˆØ�‰˜eˆÔ$Øˆó    c                 óä   — | j                   dk  rt        d«      ‚t        j                  || j                  d   j
                  ¬«      }| j                  d d |fz   | j                  dd  z   | _        y )Nr   z8cannot set row attribute of a 1-dimensional sparse arrayrg   r(   éÿÿÿÿ)r[   rT   r+   rY   rP   r)   )r^   Únew_rows     r0   rm   z_coo_base.rown   s`   € à�9‰9�qŠ=ÜÐWÓXÐXÜ—*‘*˜W¨D¯K©K¸©O×,AÑ,AÔBˆØ—k‘k # 2Ð&¨'¨Ñ3°d·k±kÀ"À#Ð6FÑFˆ�rn   c                 ó    — | j                   d   S )Nrp   ©rP   )r^   s    r0   rj   z_coo_base.colu   s   € à�{‰{˜2‰Ðrn   c                 ó�   — t        j                  || j                  d   j                  ¬«      }| j                  d d |fz   | _        y )Nrp   r(   )r+   rY   rP   r)   )r^   Únew_cols     r0   rj   z_coo_base.coly   s9   € ä—*‘*˜W¨D¯K©K¸©O×,AÑ,AÔBˆØ—k‘k # 2Ð&¨'¨Ñ3ˆ�rn   c                 ó  — t        | t        «      }t        || j                  |¬«      }t	        |«      \  }}|| j                  k(  r|r| j                  «       S | S t        | j                  | j                  |¬«      }t        |«      dk(  r+|dk(  rt        ||d   «      }n.t        ||d   «      d d d…   }nt        j                  |||¬«      }|r| j                  j                  «       }	n| j                  }	| j                  |	|f|d¬	«      S )
Nr!   ©Úorderr   ÚCr	   r   rp   F©rV   r@   )rJ   r   r   rV   r   r@   Ú_ravel_coordsrP   r5   Údivmodr+   Úunravel_indexrQ   Ú	__class__)
r^   ÚargsÚkwargsr`   rV   rx   r@   Úflat_coordsÚ
new_coordsÚnew_datas
             r0   Úreshapez_coo_base.reshape~   sï   € Ü˜d¤GÓ,ˆÜ˜D $§*¡*°xÔ@ˆÜ*¨6Ó2‰ˆˆtð �D—J‘JÒÙØ—y‘y“{Ð"à�ô
 $ D§K¡K°·±À5ÔIˆÜˆu‹:˜Š?Ø˜Š|Ü# K°°q±Ó:‘
ä# K°°q±Ó:¹4¸R¸4Ñ@‘
ä×)Ñ)¨+°uÀEÔJˆJñ Ø—y‘y—~‘~Ó'‰Hà—y‘yˆHà�~‰~˜x¨Ð4¸EÈˆ~ÓNÐNrn   c                 óR  ‡— |�|dk(  r˜| j                   dk(  r‰t        | j                  «      Št        ˆfd„| j                  D «       «      rt        d«      ‚| j                  j                   dk7  st        d„ | j                  D «       «      rt        d«      ‚t        ‰«      S |dk  r|| j                   z  }|| j                   k\  rt        d«      ‚| j                   dkD  rt        d	«      ‚t        j                  t        | j                  d|z
     «      | j                  d|z
     ¬
«      S )Nr   r	   c              3   ó:   •K  — | ]  }t        |«      ‰k7  –— Œ y ­wrB   r4   )r-   r7   Únnzs     €r0   r1   z$_coo_base._getnnz.<locals>.<genexpr>¤   s   øè ø€ Ò: s”3�s“8˜s•?Ñ:ùs   ƒz3all index and data arrays must have the same lengthc              3   ó:   K  — | ]  }|j                   d k7  –— Œ y­wr9   )r[   r6   s     r0   r1   z$_coo_base._getnnz.<locals>.<genexpr>¨   s   è ø€ Ò)O¸C¨#¯(©(°a­-Ñ)Oùs   ‚z(row, column, and data arrays must be 1-Dzaxis out of boundsr   z?per-axis nnz for COO arrays with >2 dimensions is not supported)Ú	minlength)r[   r5   rQ   rU   rP   rT   ÚintÚNotImplementedErrorr+   Úbincountr   rV   )r^   Úaxisr‡   s     @r0   Ú_getnnzz_coo_base._getnnz¡   s  ø€ Øˆ<˜D AšI¨$¯)©)°qª.Ü�d—i‘i“.ˆCÜÓ:¨d¯k©kÔ:Ô:Ü ð "/ó 0ð 0ð �y‰y�~‰~ Ò"¤cÑ)OÀ4Ç;Á;Ô)OÔ&OÜ Ð!KÓLÐLä�s“8ˆOà�!Š8Ø�D—I‘IÑˆDØ�4—9‘9ÒÜÐ1Ó2Ð2Ø�9‰9�qŠ=Ü%ð 'Dó Eð Eä�{‰{Ô.¨t¯{©{¸1¸t¹8Ñ/DÓEØ%)§Z¡Z°°D±Ñ%9ô;ð 	;rn   c           
      óš  ‡— | j                   t        | j                  «      k7  r.t        dt        | j                  «      › d| j                   › �«      ‚t	        | j                  «      D ]G  \  }}|j
                  j                  dk7  sŒ t        d|› d|j
                  j                  › d�d¬«       ŒI | j                  | j                  t        | j                  «      ¬	«      Št        ˆfd
„| j                  D «       «      | _        t        | j                  «      | _        | j                  dkD  rŸt	        | j                  «      D ]†  \  }}|j                  «       | j                  |   k\  r/t        d|› d|j                  «       › d| j                  |   › �«      ‚|j!                  «       dk  sŒit        d|› d|j!                  «       › �«      ‚ yy)z' Checks data structure for consistency z2mismatching number of index arrays for shape; got z, expected Úizindex array z has non-integer dtype (ú)é   ©Ú
stacklevelr#   c              3   óL   •K  — | ]  }t        j                  |‰¬ «      –— Œ y­wr'   )r+   rY   )r-   r7   r/   s     €r0   r1   z#_coo_base._check.<locals>.<genexpr>Æ   s'   øè ø€ ò 5Ø!$ô ŸJ™J s°)×<Ð<ñ 5ùr2   r   zaxis z index z exceeds matrix dimension znegative axis z index: N)r[   r5   rP   rT   Ú	enumerater)   Úkindr   ÚnamerM   r<   rV   rK   r   rQ   r‡   Úmin)r^   r�   r7   r/   s      @r0   r]   z_coo_base._check¹   s˜  ø€ à�9‰9œ˜DŸK™KÓ(Ò(Üð $Ü$'¨¯©Ó$4Ð#5°[ÀÇÁÀðMó Nð Nô   §¡Ó,ò 	#‰FˆAˆsØ�y‰y�~‰~ Ó$Ü�| A 3Ð&>¸s¿y¹y¿~¹~Ð>NÈaÐPØ !ö#ð	#ð
 ×)Ñ)¨$¯+©+¼cÀ$Ç*Á*»oÐ)ÓNˆ	Üó 5Ø(,¯©ô5ó 5ˆŒä˜dŸi™iÓ(ˆŒ	à�8‰8�aŠ<Ü# D§K¡KÓ0ò N‘��3Ø—7‘7“9 §
¡
¨1¡Ò-Ü$ u¨Q¨C¨w°s·w±w³y°kð B9Ø9=¿¹ÀA¹¸ð&Ió Jð Jà—7‘7“9˜q“=Ü$ ~°a°S¸ÀÇÁÃÀÐ%LÓMÐMñNð rn   c                 ó®  ‡ — |€t        ‰ j                  «      d d d…   }not        ‰ t        «      rOt	        |«      ‰ j                  k7  rt        d«      ‚t	        t        |«      «      ‰ j                  k7  rt        d«      ‚|dk7  rt        d«      ‚t        ˆ fd„|D «       «      }t        ˆ fd„|D «       «      }‰ j                  ‰ j                  |f||¬«      S )	Nrp   z"axes don't match matrix dimensionszrepeated axis in transpose)r	   r   zoSparse matrices do not support an 'axes' parameter because swapping dimensions is the only logical permutation.c              3   ó<   •K  — | ]  }‰j                   |   –— Œ y ­wrB   )rL   ©r-   r�   r^   s     €r0   r1   z&_coo_base.transpose.<locals>.<genexpr>ß   s   øè ø€ Ò<°!˜tŸ{™{¨1�~Ñ<ùó   ƒc              3   ó<   •K  — | ]  }‰j                   |   –— Œ y ­wrB   rs   rœ   s     €r0   r1   z&_coo_base.transpose.<locals>.<genexpr>à   s   øè ø€ Ò=°1 §¡¨A¥Ñ=ùr�   rz   )
rO   r[   rJ   r   r5   rT   ÚsetrK   r~   rQ   )r^   Úaxesr@   Úpermuted_shapeÚpermuted_coordss   `    r0   Ú	transposez_coo_base.transposeÒ   sÆ   ø€ Øˆ<Ü˜Ÿ™Ó#¡D b DÑ)‰DÜ˜œgÔ&Ü�4‹y˜DŸI™IÒ%Ü Ð!EÓFÐFÜ”3�t“9‹~ §¡Ò*Ü Ð!=Ó>Ð>Ø�VŠ^Üð 9ó :ð :ô Ó<°tÔ<Ó<ˆÜÓ=¸Ô=Ó=ˆØ�~‰~˜tŸy™y¨/Ð:Ø$2¸ð ó ?ð 	?rn   c                 ó  ‡
— t        | t        «      }t        ||¬«      }t        |«      | j                  kD  rot        | j                  | j                  «      }t        j                  |«      }t        j                  |d | |«      | _        | j                  d | | _        || _        y t        |«      | j                  k  r…| j                  d t        |«      dz
   dz   d| j                  t        |«      z
  z  z   }| j                  |«      }|j                  d t        |«       | _        |j                  d t        |«       | _        t        d„ t!        | j                  |«      D «       «      }|r�t        j"                  j%                  t!        | j                  |«      D ��	cg c]
  \  }}	||	k  ‘Œ c}	}«      Š
‰
j'                  «       s7t)        ˆ
fd„| j                  D «       «      | _        | j                  ‰
   | _        || _        y c c}	}w )Nr!   r	   )rp   )r	   c              3   ó,   K  — | ]  \  }}||kD  –— Œ y ­wrB   © )r-   ÚoldÚnews      r0   r1   z#_coo_base.resize.<locals>.<genexpr>ÿ   s   è ø€ ÒM©(¨#¨s˜C #�IÑMùs   ‚c              3   ó(   •K  — | ]	  }|‰   –— Œ y ­wrB   r¦   ©r-   r7   Úmasks     €r0   r1   z#_coo_base.resize.<locals>.<genexpr>  s   øè ø€ Ò#E°# C¨¥IÑ#Eùó   ƒ)rJ   r   r   r5   r[   r{   rP   rV   ÚmathÚprodr+   r}   rQ   rL   r„   rU   ÚzipÚlogical_andÚreduceÚallrK   )r^   rV   r`   r�   Úmax_sizeÚ	tmp_shapeÚtmpÚis_truncatingr7   Úsizer«   s             @r0   Úresizez_coo_base.resizeæ   s§  ø€ Ü˜d¤GÓ,ˆÜ˜E¨HÔ5ˆô ˆu‹:˜Ÿ	™	Ò!Ü'¨¯©°T·Z±ZÓ@ˆKÜ—y‘y Ó'ˆHÜ×*Ñ*¨;°y¸Ð+AÀ5ÓIˆDŒKØŸ	™	 ) 8Ð,ˆDŒIØˆDŒKØô ˆu‹:˜Ÿ	™	Ò!à—‘˜OœS ›Z¨!™^Ð,Øñà˜$Ÿ)™)¤c¨%£jÑ0Ñ1ñ2ð ð
 —,‘,˜yÓ)ˆCØŸ*™* [¤c¨%£jÐ1ˆDŒKØŸ)™) K¤S¨£ZÐ0ˆDŒKô ÑM´c¸$¿*¹*ÀeÓ6LÔMÓMˆÙÜ—>‘>×(Ñ(Ü,/°·±¸UÓ,C÷*Ù(˜s D��d“
ó*ó ˆDð —8‘8”:Ü#Ó#E¸¿¹Ô#EÓE�”Ø ŸI™I d™O�”	àˆ�ùó*s   ÆH
c                 óÄ  — | j                  ||«      }t        |j                  j                  «      }|s!|j                  j                  st        d«      ‚| j                  dkD  rt        d«      ‚| j                  \  }}t        ||| j                  | j                  | j                  | j                  |j                  d«      |«       |j                  | j                  «      S )Nz&Output array must be C or F contiguousr   z'Cannot densify higher-rank sparse arrayÚA)Ú_process_toarray_argsrŠ   ÚflagsÚf_contiguousÚc_contiguousrT   r[   Ú_shape_as_2dr   r‡   rm   rj   rQ   Úravelr„   rV   )r^   rx   ÚoutÚBÚfortranrd   ÚNs          r0   Útoarrayz_coo_base.toarray  s±   € Ø×&Ñ& u¨cÓ2ˆÜ�a—g‘g×*Ñ*Ó+ˆÙ˜qŸw™w×3Ò3ÜÐEÓFÐFØ�9‰9�qŠ=ÜÐFÓGÐGð × Ñ ‰ˆˆ1Ü�A�q˜$Ÿ(™( D§H¡H¨d¯h©h¸¿	¹	Ø—G‘G˜C“L 'ô	+ð �y‰y˜Ÿ™Ó$Ð$rn   c                 óV  — | j                   dk7  rt        d«      ‚| j                  dk(  r'| j                  | j                  | j
                  ¬«      S ddlm} | j                  |j                  «      \  }}}}| j                  |||f|¬«      }| j                  s|j                  «        |S )aQ  Convert this array/matrix to Compressed Sparse Column format

        Duplicate entries will be summed together.

        Examples
        --------
        >>> from numpy import array
        >>> from scipy.sparse import coo_array
        >>> row  = array([0, 0, 1, 3, 1, 0, 0])
        >>> col  = array([0, 2, 1, 3, 1, 0, 0])
        >>> data = array([1, 1, 1, 1, 1, 1, 1])
        >>> A = coo_array((data, (row, col)), shape=(4, 4)).tocsc()
        >>> A.toarray()
        array([[3, 0, 1, 0],
               [0, 2, 0, 0],
               [0, 0, 0, 0],
               [0, 0, 0, 1]])

        r   z.Cannot convert a 1d sparse array to csc formatr   r(   r	   )Ú	csc_array©rV   )r[   rT   r‡   Ú_csc_containerrV   r)   Ú_cscrÇ   Ú_coo_to_compressedÚ_swaprR   Úsum_duplicates)r^   r@   rÇ   ÚindptrÚindicesrQ   rV   Úxs           r0   Útocscz_coo_base.tocsc  sš   € ð( �9‰9˜Š>ÜÐMÓNÐNØ�8‰8�qŠ=Ø×&Ñ& t§z¡z¸¿¹Ð&ÓDÐDå'Ø+/×+BÑ+BÀ9Ç?Á?Ó+SÑ(ˆF�G˜T 5à×#Ñ# T¨7°FÐ$;À5Ð#ÓIˆAØ×,Ò,Ø× Ñ Ô"ØˆHrn   c                 ó>  — | j                   dk(  r'| j                  | j                  | j                  ¬«      S ddlm} | j                  |j                  |¬«      }|\  }}}}| j                  |||f| j                  ¬«      }| j                  s|j                  «        |S )aN  Convert this array/matrix to Compressed Sparse Row format

        Duplicate entries will be summed together.

        Examples
        --------
        >>> from numpy import array
        >>> from scipy.sparse import coo_array
        >>> row  = array([0, 0, 1, 3, 1, 0, 0])
        >>> col  = array([0, 2, 1, 3, 1, 0, 0])
        >>> data = array([1, 1, 1, 1, 1, 1, 1])
        >>> A = coo_array((data, (row, col)), shape=(4, 4)).tocsr()
        >>> A.toarray()
        array([[3, 0, 1, 0],
               [0, 2, 0, 0],
               [0, 0, 0, 0],
               [0, 0, 0, 1]])

        r   r(   r	   )Ú	csr_arrayrC   rÈ   )
r‡   Ú_csr_containerrV   r)   Ú_csrrÓ   rË   rÌ   rR   rÍ   )	r^   r@   rÓ   ÚarraysrÎ   rÏ   rQ   rV   rÐ   s	            r0   Útocsrz_coo_base.tocsr>  s‘   € ð( �8‰8�qŠ=Ø×&Ñ& t§z¡z¸¿¹Ð&ÓDÐDå'Ø×,Ñ,¨Y¯_©_À4Ð,ÓHˆFØ+1Ñ(ˆF�G˜T 5à×#Ñ# T¨7°FÐ$;À4Ç:Á:Ð#ÓNˆAØ×,Ò,Ø× Ñ Ô"ØˆHrn   c                 ó^  —  || j                   «      \  }}| j                  | j                  t        | j                  |«      ¬«      }| j
                  dk(  rŠ|r| j                  d   j                  «       n| j                  d   }t        |«      }t        j                  d|g|¬«      }|r| j                  j                  «       n| j                  }	|||	| j                  fS  || j                  «      \  }
}t        |
«      }|
j                  |d¬«      }
|j                  |d¬«      }t        j                  |dz   |¬«      }t        j                  ||¬«      }t        j                  | j                  | j                  ¬«      }	t!        ||||
|| j                  |||	«	       |||	| j                  fS )z?convert (shape, coords, data) to (indptr, indices, data, shape)r#   r	   r   r(   FrC   )r¿   rM   rP   r<   r‡   r[   r@   r5   r+   r,   rQ   rV   rG   ÚemptyÚ
empty_liker)   r   )r^   Úswapr@   rd   rÄ   r/   rÏ   r‡   rÎ   rQ   ÚmajorÚminors               r0   rË   z_coo_base._coo_to_compressed^  s]  € á�D×%Ñ%Ó&‰ˆˆ1ð ×)Ñ)¨$¯+©+¼cÀ$Ç(Á(ÈAÓ>NÐ)ÓOˆ	à�9‰9˜Š>Ù/3�d—k‘k !‘n×)Ñ)Ô+¸¿¹ÀQ¹ˆGÜ�g“,ˆCÜ—X‘X˜q #˜h¨iÔ8ˆFÙ'+�4—9‘9—>‘>Ô#°·±ˆDØ˜7 D¨$¯*©*Ð4Ð4ñ ˜DŸK™KÓ(‰ˆˆuÜ�%‹jˆØ—‘˜Y¨U�Ó3ˆØ—‘˜Y¨U�Ó3ˆä—‘˜!˜a™% yÔ1ˆÜ—-‘- ¨YÔ7ˆÜ�}‰}˜TŸY™Y¨d¯j©jÔ9ˆä�!�Q˜˜U E¨4¯9©9°f¸gÀtÔLØ�w  d§j¡jÐ0Ð0rn   c                 ó*   — |r| j                  «       S | S rB   rC   )r^   r@   s     r0   rX   z_coo_base.tocooy  s   € ÙØ—9‘9“;ÐàˆKrn   c                 óŒ  — | j                   dk7  rt        d«      ‚| j                  «        | j                  | j                  z
  }t        j                  |d¬«      \  }}t        |«      dkD  rt        dt        |«      z  t        d¬«       | j                  j                  dk(  r"t        j                  d	| j                  ¬
«      }nbt        j                  t        |«      | j                  j                  «       dz   f| j                  ¬
«      }| j                  ||| j                  f<   | j                  ||f| j                   ¬«      S )Nr   z.Cannot convert a 1d sparse array to dia formatT)Úreturn_inverseéd   z:Constructing a DIA matrix with %d diagonals is inefficientr“   r   )r   r   r(   r	   rÈ   )r[   rT   rÍ   rj   rm   r+   Úuniquer5   r   r   rQ   r·   Úzerosr)   r<   Ú_dia_containerrV   )r^   r@   ÚksÚdiagsÚdiag_idxrQ   s         r0   Útodiaz_coo_base.todia�  sü   € Ø�9‰9˜Š>ÜÐMÓNÐNØ×ÑÔØ�X‰X˜Ÿ™Ñ ˆÜŸ)™) B°tÔ<‰ˆˆxäˆu‹:˜Òäð "Ü$'¨£Jñ/ä(°Qõ8ð
 �9‰9�>‰>˜QÒÜ—8‘8˜F¨$¯*©*Ô5‰Dä—8‘8œS ›Z¨¯©¯©«¸Ñ)9Ð:À$Ç*Á*ÔMˆDØ'+§y¡yˆD�˜4Ÿ8™8Ð#Ñ$à×"Ñ" D¨% =¸¿
¹
Ð"ÓCÐCrn   c                 ó  — | j                  «        | j                  | j                  | j                  ¬«      }| j                  dk(  r| j
                  d   }nt        | j
                  Ž }t        t        || j                  «      «      |_	        |S )Nr(   r	   r   )
rÍ   Ú_dok_containerrV   r)   r[   rP   r¯   ÚdictrQ   Ú_dict)r^   r@   ÚdokrP   s       r0   Útodokz_coo_base.todok™  sm   € Ø×ÑÔØ×!Ñ! $§*¡*°D·J±JÐ!Ó?ˆà�9‰9˜Š>Ø—[‘[ ‘^‰Fä˜$Ÿ+™+Ð&ˆFäœ˜V T§Y¡YÓ/Ó0ˆŒ	Øˆ
rn   c           
      óˆ  ‡	— | j                   dk7  rt        d«      ‚| j                  \  }}|| k  s||k\  r+t        j                  d| j
                  j                  ¬«      S t        j                  t        |t        |d«      z   |t        |d«      z
  «      | j                  ¬«      }| j                  |z   | j                  k(  Š	| j                  r| j                  ‰	   }| j
                  ‰	   }nCt        ˆ	fd„| j                  D «       «      }| j                  || j
                  ‰	   «      \  \  }}}|||t        |d«      z   <   |S )Nr   z diagonal requires two dimensionsr   r(   c              3   ó(   •K  — | ]	  }|‰   –— Œ y ­wrB   r¦   )r-   r7   Ú	diag_masks     €r0   r1   z%_coo_base.diagonal.<locals>.<genexpr>µ  s   øè ø€ Ò?¨C˜˜Y�Ñ?ùr¬   )r[   rT   rV   r+   rÙ   rQ   r)   rã   r™   r<   rm   rj   rR   rK   rP   Ú_sum_duplicates)
r^   ÚkÚrowsÚcolsÚdiagrm   rQ   Úindsr.   rñ   s
            @r0   Údiagonalz_coo_base.diagonal§  s  ø€ Ø�9‰9˜Š>ÜÐ?Ó@Ð@Ø—Z‘Z‰
ˆˆdØ��Š:˜˜dšÜ—8‘8˜A T§Y¡Y§_¡_Ô5Ð5Ü�x‰xœ˜D¤3 q¨!£9Ñ,¨d´S¸¸A³YÑ.>Ó?Ø"Ÿj™jô*ˆà—X‘X ‘\ d§h¡hÑ.ˆ	à×$Ò$Ø—(‘(˜9Ñ%ˆCØ—9‘9˜YÑ'‰DäÓ?°4·;±;Ô?Ó?ˆDØ!×1Ñ1°$¸¿	¹	À)Ñ8LÓM‰N‰HˆS�!�dØ $ˆˆS”3�q˜!“9‰_Ñàˆrn   c                 óx  — | j                   dk7  rt        d«      ‚| j                  \  }}|j                   rt        |«      sy | j                  j
                  }| j                  | j                  z
  |k7  }|dk  rˆt        ||z   |«      }|j                   rt        |t        |«      «      }t        j                  || j                  |k\  «      }t        j                  | | |z   |¬«      }	t        j                  ||¬«      }
n…t        |||z
  «      }|j                   rt        |t        |«      «      }t        j                  || j                  |k\  «      }t        j                  ||¬«      }	t        j                  |||z   |¬«      }
|j                   r|d | }n&t        j                  || j
                  ¬«      }||d d  t        j                  | j                  |   |	f«      t        j                  | j                  |   |
f«      f| _        t        j                  | j                  |   |f«      | _        d| _        y )Nr   z*setting a diagonal requires two dimensionsr   r(   F)r[   rT   rV   r5   rm   r)   rj   r™   r+   Ú
logical_orÚarangerÙ   ÚconcatenaterP   rQ   rR   )r^   Úvaluesró   rd   rÄ   r/   Ú	full_keepÚ	max_indexÚkeeprq   ru   rƒ   s               r0   Ú_setdiagz_coo_base._setdiag½  sÆ  € Ø�9‰9˜Š>ÜÐIÓJÐJØ�z‰z‰ˆˆ1Ø�;Š;œs 6œ{ØØ—H‘H—N‘Nˆ	ð —H‘H˜tŸx™xÑ'¨1Ñ,ˆ	ØˆqŠ5Ü˜A˜a™C ›ˆIØ�{Š{Ü 	¬3¨v«;Ó7�	Ü—=‘= ¨D¯H©H¸	Ñ,AÓBˆDÜ—i‘i   Q B¨¡N¸)ÔDˆGÜ—i‘i 	°Ô;‰Gä˜A˜q ™s›ˆIØ�{Š{Ü 	¬3¨v«;Ó7�	Ü—=‘= ¨D¯H©H¸	Ñ,AÓBˆDÜ—i‘i 	°Ô;ˆGÜ—i‘i  1 y¡=¸	ÔBˆGð �;Š;Ø˜j˜yÐ)‰Hä—x‘x 	°·±Ô<ˆHØ ˆH‘QˆKô —~‘~ t§x¡x°¡~°wÐ&?Ó@Ü—~‘~ t§x¡x°¡~°wÐ&?Ó@ðBˆŒä—N‘N D§I¡I¨d¡O°XÐ#>Ó?ˆŒ	Ø$)ˆÕ!rn   c                 ó¬   — |rt        d„ | j                  D «       «      }n| j                  }| j                  ||f| j                  |j                  ¬«      S )zŒReturns a matrix with the same sparsity structure as self,
        but with different data. By default the index arrays are copied.
        c              3   ó<   K  — | ]  }|j                  «       –— Œ y ­wrB   rC   r6   s     r0   r1   z'_coo_base._with_data.<locals>.<genexpr>é  s   è ø€ Ò=¨#˜3Ÿ8™8Ÿ:Ñ=ùrD   )rV   r)   )rK   rP   r~   rV   r)   )r^   rQ   r@   rP   s       r0   Ú
_with_dataz_coo_base._with_dataä  sE   € ñ ÜÑ=°·±Ô=Ó=‰Fà—[‘[ˆFØ�~‰~˜t V˜n°D·J±JÀdÇjÁjˆ~ÓQÐQrn   c                 ó–   — | j                   ry| j                  | j                  | j                  «      }|\  | _        | _        d| _         y)zeEliminate duplicate entries by adding them together

        This is an *in place* operation
        NT)rR   rò   rP   rQ   )r^   Úsummeds     r0   rÍ   z_coo_base.sum_duplicatesî  s@   € ð
 ×$Ò$ØØ×%Ñ% d§k¡k°4·9±9Ó=ˆØ!'ÑˆŒ�T”YØ$(ˆÕ!rn   c           	      óê  ‡‡— t        |«      dk(  r||fS t        j                  |d d d…   «      Št        ˆfd„|D «       «      }|‰   }t        j                  j                  |D �cg c]  }|dd  |d d k7  ‘Œ c}«      Št        j                  d‰«      Št        ˆfd„|D «       «      }t        j                  ‰«      \  }t        j                  j                  ||| j                  ¬«      }||fS c c}w )Nr   rp   c              3   ó(   •K  — | ]	  }|‰   –— Œ y ­wrB   r¦   )r-   r7   rx   s     €r0   r1   z,_coo_base._sum_duplicates.<locals>.<genexpr>  s   øè ø€ Ò4 c�s˜5•zÑ4ùr¬   r	   Tc              3   ó(   •K  — | ]	  }|‰   –— Œ y ­wrB   r¦   )r-   r7   Úunique_masks     €r0   r1   z,_coo_base._sum_duplicates.<locals>.<genexpr>  s   øè ø€ Ò:¨C�s˜;Õ'Ñ:ùr¬   r(   )r5   r+   ÚlexsortrK   rú   r±   Úappendr\   ÚaddÚreduceatr)   )r^   rP   rQ   r7   Úunique_indsrx   r
  s        @@r0   rò   z_coo_base._sum_duplicatesù  sÞ   ù€ äˆt‹9˜Š>Ø˜4�<Ðô —
‘
˜6¡$ B $™<Ó(ˆÜÓ4¨VÔ4Ó4ˆØ�E‰{ˆÜ—m‘m×*Ñ*Ø+1ö,
Ø$'ˆC��ˆG�s˜3˜B�xÓò,
ó ˆô —i‘i  kÓ2ˆÜÓ:°6Ô:Ó:ˆÜ—z‘z +Ó.‰ˆÜ�v‰v�‰˜t [¸¿
¹
ˆÓCˆØ�tˆ|Ðùò,
s   Á&C0c                 ó’   ‡— | j                   dk7  Š| j                   ‰   | _         t        ˆfd„| j                  D «       «      | _        y)z[Remove zero entries from the array/matrix

        This is an *in place* operation
        r   c              3   ó(   •K  — | ]	  }|‰   –— Œ y ­wrB   r¦   rª   s     €r0   r1   z,_coo_base.eliminate_zeros.<locals>.<genexpr>  s   øè ø€ Ò=¨#˜C �IÑ=ùr¬   N)rQ   rK   rP   )r^   r«   s    @r0   Úeliminate_zerosz_coo_base.eliminate_zeros  s7   ø€ ð
 �y‰y˜A‰~ˆØ—I‘I˜d‘OˆŒ	ÜÓ=°·±Ô=Ó=ˆ�rn   c                 ó,  — |j                   | j                   k7  r&t        d| j                   › d|j                   › d�«      ‚t        | j                  j                  |j                  j                  «      }t        j                  ||d¬«      }t        |j                  j                  «      }| j                  \  }}t        ||| j                  | j                  | j                  | j                  |j!                  d«      |«       | j#                  |d¬«      S )	NzIncompatible shapes (z and r‘   T)r)   r@   rº   FrC   )rV   rT   r   r)   Úcharr+   r,   rŠ   r¼   r½   r¿   r   r‡   rm   rj   rQ   rÀ   Ú
_container)r^   Úotherr)   rl   rÃ   rd   rÄ   s          r0   Ú
_add_densez_coo_base._add_dense  sÎ   € Ø�;‰;˜$Ÿ*™*Ò$ÜÐ4°T·Z±Z°LÀÀeÇkÁkÀ]ÐRSÐTÓUÐUÜ˜DŸJ™JŸO™O¨U¯[©[×-=Ñ-=Ó>ˆÜ—‘˜% u°4Ô8ˆÜ�f—l‘l×/Ñ/Ó0ˆØ× Ñ ‰ˆˆ1Ü�A�q˜$Ÿ(™( D§H¡H¨d¯h©h¸¿	¹	Ø—L‘L Ó% wô	0à�‰˜v¨EˆÓ2Ð2rn   c                 ó<  — | j                   dkD  r| j                  d   nd}t        j                  |t	        | j
                  j                  |j
                  j                  «      ¬«      }| j                   dk(  r| j                  }| j                  }nL| j                   dk(  r%| j                  d   }t        j                  |«      }nt        d| j                   › �«      ‚t        | j                  ||| j                  ||«       t        | t         «      r
|dk(  r|d   S |S )Nr	   r   r(   r   ú$coo_matvec not implemented for ndim=)r[   rV   r+   rã   r   r)   r  rj   rm   rP   ri   r‹   r   r‡   rQ   rJ   r   )r^   r  Úresult_shaperl   rj   rm   s         r0   Ú_matmul_vectorz_coo_base._matmul_vector$  sæ   € Ø(,¯	©	°Aª�t—z‘z !’}¸1ˆÜ—‘˜,Ü +¨D¯J©J¯O©O¸U¿[¹[×=MÑ=MÓ NôPˆð �9‰9˜Š>Ø—(‘(ˆCØ—(‘(‰CØ�Y‰Y˜!Š^Ø—+‘+˜a‘.ˆCÜ—-‘- Ó$‰Cä%Ø6°t·y±y°kÐBóDð Dô 	�4—8‘8˜S # t§y¡y°%¸Ô@ä�dœGÔ$¨¸Ò):Ø˜!‘9ÐØˆrn   c                 ó´  — t        | j                  j                  |j                  j                  «      }| j                  dk(  r7|j                  d   | j                  d   f}| j
                  }| j                  }n\| j                  dk(  r5|j                  d   f}| j                  d   }t        j                  |«      }nt        d| j                  › �«      ‚t        j                  ||¬«      }t        |j                  «      D ]/  \  }}t        | j                  ||| j                   ||||dz    «       Œ1 |j                  j#                  t%        |«      ¬«      S )Nr   r	   r   r  r(   )Útype)r   r)   r  r[   rV   rj   rm   rP   r+   ri   r‹   rã   r–   ÚTr   r‡   rQ   Úviewr  )	r^   r  Úresult_dtyper  rj   rm   rl   r�   Ú	other_cols	            r0   Ú_matmul_multivectorz_coo_base._matmul_multivector9  s  € Ü" 4§:¡:§?¡?°E·K±K×4DÑ4DÓEˆØ�9‰9˜Š>Ø!ŸK™K¨™N¨D¯J©J°q©MÐ:ˆLØ—(‘(ˆCØ—(‘(‰CØ�Y‰Y˜!Š^Ø!ŸK™K¨™NÐ,ˆLØ—+‘+˜a‘.ˆCÜ—-‘- Ó$‰Cä%Ø6°t·y±y°kÐBóDð Dô —‘˜,¨lÔ;ˆÜ% e§g¡gÓ.ò 	R‰LˆAˆyÜ�t—x‘x  c¨4¯9©9°iÀÈÈ!ÈaÉ%ÀÕQð	Rà�x‰x�}‰}¤$ u£+ˆ}Ó.Ð.rn   )NNFrB   )NF)ÚreturnN)NN)F)r   )T)!Ú__name__Ú
__module__Ú__qualname__Ú_formatrI   Úpropertyrm   Úsetterrj   r„   r   Ú__doc__rŽ   r]   r£   r¸   rÅ   rÑ   r×   rË   rX   rè   rî   rø   r   r  r  rÍ   rò   r  r  r  r"  r¦   rn   r0   r   r      s‹  „ Ø€GóHðT ñó ðð 	‡Z�ZñGó ðGð ñó ðð 	‡Z�Zñ4ó ð4òOðB —o‘o×-Ñ-€G„Oó;ð, —o‘o×-Ñ-€G„OòNó2?ð$  ×)Ñ)×1Ñ1€IÔó"ðH —^‘^×+Ñ+€F„Nó%ð —o‘o×-Ñ-€G„OóóBó@1ó6ð —M‘M×)Ñ)€E„MóDð, —M‘M×)Ñ)€E„Mó
ð —M‘M×)Ñ)€E„Móð( $×,Ñ,×4Ñ4€HÔò$*óNRó	)òò&>ò	3òó*/rn   r   c                 óÖ  — t        | «      dk(  r| d   S t        | «      dk(  r±|\  }}| \  }}|dk(  rI|t        d|dz
  «      z  t        d|dz
  «      z   }t        |¬«      }t        j                  |||¬«      |z   S |dk(  rI|t        d|dz
  «      z  t        d|dz
  «      z   }t        |¬«      }t        j                  |||¬«      |z   S t        d«      ‚t        j                  | ||¬	«      S )
z;Like np.ravel_multi_index, but avoids some overflow issues.r	   r   r   ry   r#   r(   ÚFz'order' must be 'C' or 'F'rw   )r5   r<   r   r+   ÚmultiplyrT   Úravel_multi_index)	rP   rV   rx   ÚnrowsÚncolsrm   rj   r$   r/   s	            r0   r{   r{   M  só   € ä
ˆ6ƒ{�aÒØ�a‰yÐä
ˆ6ƒ{�aÒØ‰ˆˆuØ‰ˆˆSØ�CŠ<Øœc ! U¨Q¡YÓ/Ñ/´#°a¸À¹Ó2CÑCˆFÜ'¨vÔ6ˆIÜ—;‘;˜u c°Ô;¸cÑAÐAØ�cŠ\Øœc ! U¨Q¡YÓ/Ñ/´#°a¸À¹Ó2CÑCˆFÜ'¨vÔ6ˆIÜ—;‘;˜u c°Ô;¸cÑAÐAäÐ9Ó:Ð:Ü×Ñ ¨°UÔ;Ð;rn   c                 ó"   — t        | t        «      S )aÒ  Is `x` of coo_matrix type?

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

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

    Examples
    --------
    >>> from scipy.sparse import coo_array, coo_matrix, csr_matrix, isspmatrix_coo
    >>> isspmatrix_coo(coo_matrix([[5]]))
    True
    >>> isspmatrix_coo(coo_array([[5]]))
    False
    >>> isspmatrix_coo(csr_matrix([[5]]))
    False
    )rJ   r   )rÐ   s    r0   r   r   b  s   € ô. �aœÓ$Ð$rn   c                   ó   — e Zd ZdZy)r   a  
    A sparse array in COOrdinate format.

    Also known as the 'ijv' or 'triplet' format.

    This can be instantiated in several ways:
        coo_array(D)
            where D is an ndarray

        coo_array(S)
            with another sparse array or matrix S (equivalent to S.tocoo())

        coo_array(shape, [dtype])
            to construct an empty sparse array with shape `shape`
            dtype is optional, defaulting to dtype='d'.

        coo_array((data, coords), [shape])
            to construct from existing data and index arrays:
                1. data[:]       the entries of the sparse array, in any order
                2. coords[i][:]  the axis-i coordinates of the data entries

            Where ``A[coords] = data``, and coords is a tuple of index arrays.
            When shape is not specified, it is inferred from the index arrays.

    Attributes
    ----------
    dtype : dtype
        Data type of the sparse array
    shape : tuple of integers
        Shape of the sparse array
    ndim : int
        Number of dimensions of the sparse array
    nnz
    size
    data
        COO format data array of the sparse array
    coords
        COO format tuple of index arrays
    has_canonical_format : bool
        Whether the matrix has sorted coordinates and no duplicates
    format
    T

    Notes
    -----

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

    Advantages of the COO format
        - facilitates fast conversion among sparse formats
        - permits duplicate entries (see example)
        - very fast conversion to and from CSR/CSC formats

    Disadvantages of the COO format
        - does not directly support:
            + arithmetic operations
            + slicing

    Intended Usage
        - COO is a fast format for constructing sparse arrays
        - Once a COO array has been constructed, convert to CSR or
          CSC format for fast arithmetic and matrix vector operations
        - By default when converting to CSR or CSC format, duplicate (i,j)
          entries will be summed together.  This facilitates efficient
          construction of finite element matrices and the like. (see example)

    Canonical format
        - Entries and coordinates sorted by row, then column.
        - There are no duplicate entries (i.e. duplicate (i,j) locations)
        - Data arrays MAY have explicit zeros.

    Examples
    --------

    >>> # Constructing an empty sparse array
    >>> import numpy as np
    >>> from scipy.sparse import coo_array
    >>> coo_array((3, 4), dtype=np.int8).toarray()
    array([[0, 0, 0, 0],
           [0, 0, 0, 0],
           [0, 0, 0, 0]], dtype=int8)

    >>> # Constructing a sparse array using ijv format
    >>> row  = np.array([0, 3, 1, 0])
    >>> col  = np.array([0, 3, 1, 2])
    >>> data = np.array([4, 5, 7, 9])
    >>> coo_array((data, (row, col)), shape=(4, 4)).toarray()
    array([[4, 0, 9, 0],
           [0, 7, 0, 0],
           [0, 0, 0, 0],
           [0, 0, 0, 5]])

    >>> # Constructing a sparse array with duplicate coordinates
    >>> row  = np.array([0, 0, 1, 3, 1, 0, 0])
    >>> col  = np.array([0, 2, 1, 3, 1, 0, 0])
    >>> data = np.array([1, 1, 1, 1, 1, 1, 1])
    >>> coo = coo_array((data, (row, col)), shape=(4, 4))
    >>> # Duplicate coordinates are maintained until implicitly or explicitly summed
    >>> np.max(coo.data)
    1
    >>> coo.toarray()
    array([[3, 0, 1, 0],
           [0, 2, 0, 0],
           [0, 0, 0, 0],
           [0, 0, 0, 1]])

    N)r$  r%  r&  r*  r¦   rn   r0   r   r   }  s   „ òkrn   r   c                   ó   — e Zd ZdZd„ Zy)r   a.  
    A sparse matrix in COOrdinate format.

    Also known as the 'ijv' or 'triplet' format.

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

        coo_matrix(S)
            with another sparse array or matrix S (equivalent to S.tocoo())

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

        coo_matrix((data, (i, j)), [shape=(M, N)])
            to construct from three arrays:
                1. data[:]   the entries of the matrix, in any order
                2. i[:]      the row indices of the matrix entries
                3. j[:]      the column indices of the matrix entries

            Where ``A[i[k], j[k]] = data[k]``.  When shape is not
            specified, it is 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
        COO format data array of the matrix
    row
        COO format row index array of the matrix
    col
        COO format column index array of the matrix
    has_canonical_format : bool
        Whether the matrix has sorted indices and no duplicates
    format
    T

    Notes
    -----

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

    Advantages of the COO format
        - facilitates fast conversion among sparse formats
        - permits duplicate entries (see example)
        - very fast conversion to and from CSR/CSC formats

    Disadvantages of the COO format
        - does not directly support:
            + arithmetic operations
            + slicing

    Intended Usage
        - COO is a fast format for constructing sparse matrices
        - Once a COO matrix has been constructed, convert to CSR or
          CSC format for fast arithmetic and matrix vector operations
        - By default when converting to CSR or CSC format, duplicate (i,j)
          entries will be summed together.  This facilitates efficient
          construction of finite element matrices and the like. (see example)

    Canonical format
        - Entries and coordinates sorted by row, then column.
        - There are no duplicate entries (i.e. duplicate (i,j) locations)
        - Data arrays MAY have explicit zeros.

    Examples
    --------

    >>> # Constructing an empty matrix
    >>> import numpy as np
    >>> from scipy.sparse import coo_matrix
    >>> coo_matrix((3, 4), dtype=np.int8).toarray()
    array([[0, 0, 0, 0],
           [0, 0, 0, 0],
           [0, 0, 0, 0]], dtype=int8)

    >>> # Constructing a matrix using ijv format
    >>> row  = np.array([0, 3, 1, 0])
    >>> col  = np.array([0, 3, 1, 2])
    >>> data = np.array([4, 5, 7, 9])
    >>> coo_matrix((data, (row, col)), shape=(4, 4)).toarray()
    array([[4, 0, 9, 0],
           [0, 7, 0, 0],
           [0, 0, 0, 0],
           [0, 0, 0, 5]])

    >>> # Constructing a matrix with duplicate coordinates
    >>> row  = np.array([0, 0, 1, 3, 1, 0, 0])
    >>> col  = np.array([0, 2, 1, 3, 1, 0, 0])
    >>> data = np.array([1, 1, 1, 1, 1, 1, 1])
    >>> coo = coo_matrix((data, (row, col)), shape=(4, 4))
    >>> # Duplicate coordinates are maintained until implicitly or explicitly summed
    >>> np.max(coo.data)
    1
    >>> coo.toarray()
    array([[3, 0, 1, 0],
           [0, 2, 0, 0],
           [0, 0, 0, 0],
           [0, 0, 0, 1]])

    c                 óŒ   — d|vr%|j                  d«      |j                  d«      f|d<   | j                  j                  |«       y )NrP   rm   rj   )ÚpopÚ__dict__Úupdate)r^   Ústates     r0   Ú__setstate__zcoo_matrix.__setstate__]  s>   € Ø˜5Ñ ð  %Ÿy™y¨Ó/°·±¸5Ó1AÐBˆE�(‰OØ�‰×Ñ˜UÕ#rn   N)r$  r%  r&  r*  r9  r¦   rn   r0   r   r   ì  s   „ ñnó`$rn   r   )ry   )(r*  Ú__docformat__Ú__all__r­   Úwarningsr   Únumpyr+   Ú
_lib._utilr   Ú_matrixr
   Ú_sparsetoolsr   r   r   Ú_baser   r   r   r   Ú_datar   r   Ú_sputilsr   r   r   r   r   r   r   r   r   r:   r   r{   r   r   r   r¦   rn   r0   ú<module>rD     s€   ðÙ 8à%€â
7€ã Ý ã å 'Ý ß <Ñ <ß FÓ Fß .÷:÷ :õ :ó ôr/�˜mô r/ój<ò*%ô6l�	˜7ô lô^v$�˜9õ v$rn   