Ë
    çÿæi% ã                   ó^  — 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mZ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%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+ ddl,Z, G d„ dee«      Z-d„ Z.d„ Z/d„ Z0d„ Z1d„ Z2d„ Z3dd„Z4d„ Z5 G d„ de-e«      Z6 G d„ dee-«      Z7y)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_todense_ndÚ
coo_matvecÚcoo_matvec_ndÚcoo_matmat_denseÚcoo_matmat_dense_nd)Ú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_kwargsÚisscalarlikeÚ	isintlikeÚisdense)Ú_validate_indicesÚ_broadcast_arraysc                   óÄ  — e Zd ZdZ edd«      Zd3ddœd„Zed„ «       Zej                  d„ «       Zed	„ «       Z
e
j                  d
„ «       Z
d„ Zej                  j                  e_        d4d„Zej                  j                  e_        d4d„Zej                  j                  e_        d„ Zd5d„Zej"                  j                  e_        d6d„Zej$                  j                  e_        d7d„Zej&                  j                  e_        d8d„Zd8d„Zd8d„Zd8d„Zej.                  j                  e_        d8d„Zej0                  j                  e_        d8d„Zej2                  j                  e_        d9d„Zej4                  j                  e_        d„ Zd:d„Zd„ Zd„ Zd„ Z d6d„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;d+„Z.d,„ Z/d-„ Z0d.„ Z1d8d/„Z2d0„ Z3d1„ Z4d2„ Z5y)<Ú	_coo_baseÚcoor	   éA   N©Úmaxprintc                óú  ‡‡‡— t        j                  | ||¬«       ‰st        Št        |t        «      �rst        || j                  ¬«      r¬t        || j                  ¬«      | _        | 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                  ¬«      | _        | j                  |t        | j.                  «      d¬«      Št	        ˆˆfd„|D «       «      | _        t1        |‰|¬«      | _        d| _        �nht3        |«      �r&|j4                  | j4                  k(  r†‰r„t	        d„ |j                  D «       «      | _        |j$                  j7                  t        ||«      «      | _        t        |j.                  | j                  ¬«      | _        |j&                  | _        �n½|j9                  ‰¬«      }
t	        |
j                  «      | _        |
j$                  j7                  t        ||
«      d¬«      | _        t        |
j.                  | j                  ¬«      | _        d| _        �n6t!        j:                  |«      }t        | t<        «      s=t!        j>                  |«      }|j@                  dk7  rt)        d|j@                  › d�«      ‚t        |j.                  | j                  ¬«      | _        |�At        || j                  ¬«      | j                  k7  rd|› d| j                  › �}t+        |«      ‚| j                  t        | j                  «      ¬«      Š|jC                  «       }t	        ˆfd„|D «       «      | _        t1        ||   ‰|¬«      | _        d| _        t        | j                  «      dkD  r!t	        d„ | j                  D «       «      | _        | jE                  «        y # t(        t*        f$ r}	t)        d«      |	‚d }	~	ww xY w)Nr*   ©Úallow_nd©Úmaxval)Údefaultc              3   óL   •K  — | ]  }t        j                  g ‰¬ «      –— Œ y­w©©ÚdtypeN©ÚnpÚarray)Ú.0Ú_Ú	idx_dtypes     €úf/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/scipy/sparse/_coo.pyÚ	<genexpr>z%_coo_base.__init__.<locals>.<genexpr>*   s(   øè ø€ ð $GÙ.E¨ô %'§H¡H¨R°y×$AÐ$AÙ.Eùó   ƒ!$r4   Tzinvalid input formatc              3   ó8   K  — | ]  }t        |«      d k(  –— Œ y­w)r   N©Úlen©r9   Úidxs     r<   r=   z%_coo_base.__init__.<locals>.<genexpr>5   s   è ø€ Ð;±F¨Sœ3˜s›8 q�=±Fùs   ‚z4cannot infer dimensions from zero sized index arraysc              3   ór   K  — | ]/  }t        j                  t        j                  |«      «      d z   –— Œ1 y­w©r	   N)ÚoperatorÚindexr7   ÚmaxrB   s     r<   r=   z%_coo_base.__init__.<locals>.<genexpr>8   s.   è ø€ ð "5Ù-3 cô #+§.¡.´·±¸³Ó"=ÀÕ"AÙ-3ùs   ‚57)r0   Úcheck_contentsc              3   óN   •K  — | ]  }t        j                  |‰‰¬ «      –— Œ y­w)©Úcopyr5   Nr6   )r9   rC   rL   r;   s     €€r<   r=   z%_coo_base.__init__.<locals>.<genexpr>>   s)   øè ø€ ð $8Ù06¨ô %'§H¡H¨S°tÀ9×$MÐ$MÙ06ùs   ƒ"%rK   Fc              3   ó<   K  — | ]  }|j                  «       –— Œ y ­w©N©rL   rB   s     r<   r=   z%_coo_base.__init__.<locals>.<genexpr>E   s   è ø€ Ð'J¹k°s¨¯©¯
¹kùó   ‚rO   r   z!expected 2D array or matrix, not ÚDzinconsistent shapes: z != c              3   óD   •K  — | ]  }|j                  ‰d ¬«      –— Œ y­w©FrO   N)Úastype)r9   rC   Úindex_dtypes     €r<   r=   z%_coo_base.__init__.<locals>.<genexpr>_   s&   øè ø€ ð $8Ù06¨ð %(§J¡J¨{À J×$GÙ06ùs   ƒ c              3   ó^   K  — | ]%  }|j                  t        j                  d ¬«      –— Œ' y­wrS   )rT   r7   Úint64rB   s     r<   r=   z%_coo_base.__init__.<locals>.<genexpr>e   s"   è ø€ ÐXÉKÀS §
¡
¬2¯8©8¸% 
× @ÉKùs   ‚+-)#r   Ú__init__r   Ú
isinstanceÚtupler   Ú	_allow_ndr   Ú_shapeÚ_get_index_dtyperH   r   ÚfloatÚrangerA   Úcoordsr7   r8   ÚdataÚhas_canonical_formatÚ	TypeErrorÚ
ValueErrorÚanyÚshaper   r   ÚformatrT   ÚtocooÚasarrayr   Ú
atleast_2dÚndimÚnonzeroÚ_check)ÚselfÚarg1rf   r5   rL   r+   Ú
data_dtypeÚobjr`   Úer(   ÚMÚmessager;   rU   s       `        @@r<   rX   z_coo_base.__init__    s�  ú€ Ü×Ñ˜d D°8Õ<ÙÜ!ˆDä�dœEÕ"Ü�t d§n¡nÕ5Ü)¨$¸¿¹ÔH�”Ø ×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ä)¨%¸$¿.¹.ÔI�”Ø ×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Ñ 0´¸%ÀÓ1FÓ G�D”IÜ"-¨d¯j©jÀ4Ç>Á>Ô"R�D”KØ04×0IÑ0I�DÖ-àŸ*™*¨$˜*Ó/�CÜ"'¨¯
©
Ó"3�D”KØ #§¡§¡´¸ÀÓ0DÈ5 Ó Q�D”IÜ"-¨c¯i©iÀ$Ç.Á.Ô"Q�D”KØ05�DÖ-ô —J‘J˜tÓ$�Ü! $¬Ô0ÜŸ™ aÓ(�AØ—v‘v ’{Ü'Ð*KÈAÏFÉFÈ8ÐSTÐ(UÓVÐVä)¨!¯'©'¸D¿N¹NÔK�”ØÐ$Ü" 5°4·>±>ÔBÀdÇkÁkÒQØ$9¸%¸ÀÀTÇ[Á[ÀMÐ"R˜Ü(¨Ó1Ð1à"×3Ñ3¼3¸t¿{¹{Ó;KÐ3ÓL�ØŸ™›�Ü#ó $8Ù06ó$8ó 8�”ä# A f¡I°DÀÔF�”	Ø,0�Ô)äˆt�{‰{Ó˜aÒÜÑXÈDÏKÊKÓXÓXˆDŒKà�‰�øôm "¤:Ð.ò CÜ#Ð$:Ó;ÀÐBûðCús   Ã9Q ÑQ:Ñ)Q5Ñ5Q:c                 ó¤   — | j                   dkD  r| j                  d   S t        j                  | j                  «      }|j                  d¬«       |S )Nr	   éþÿÿÿF)Úwrite)rk   r`   r7   Ú
zeros_likeÚcolÚsetflags)rn   Úresults     r<   Úrowz_coo_base.rowi   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 arrayrv   r4   éÿÿÿÿ)rk   rd   r7   ri   r`   r5   )rn   Únew_rows     r<   r|   z_coo_base.rowr   s`   € à�9‰9�qŠ=ÜÐWÓXÐXÜ—*‘*˜W¨D¯K©K¸©O×,AÑ,AÔBˆØ—k‘k # 2Ð&¨'¨Ñ3°d·k±kÀ"À#Ð6FÑFˆ�r}   c                 ó    — | j                   d   S ©Nr   ©r`   )rn   s    r<   ry   z_coo_base.coly   s   € à�{‰{˜2‰Ðr}   c                 ó�   — t        j                  || j                  d   j                  ¬«      }| j                  d d |fz   | _        y )Nr   r4   )r7   ri   r`   r5   )rn   Únew_cols     r<   ry   z_coo_base.col}   s9   € ä—*‘*˜W¨D¯K©K¸©O×,AÑ,AÔBˆØ—k‘k # 2Ð&¨'¨Ñ3ˆ�r}   c                 ó‚  ‡	— t        || j                  | 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                  |||¬«      }| j                  | j                  t        |«      ¬«      Š	t        ˆ	fd	„|D «       «      }|r| j                  j	                  «       }n| j                  }| j                  ||f|d
¬«      S )Nr-   ©Úorderr   ÚCr	   r   r   r/   c              3   óL   •K  — | ]  }t        j                  |‰¬ «      –— Œ y­wr3   ©r7   ri   )r9   Úcor;   s     €r<   r=   z$_coo_base.reshape.<locals>.<genexpr>š   s    øè ø€ ÐPÁZ¸rœ2Ÿ:™: b°	×:Ð:ÁZùr>   F©rf   rL   )r   rf   r[   r    rL   Ú_ravel_coordsr`   rA   Údivmodr7   Úunravel_indexr]   rH   rZ   ra   Ú	__class__)
rn   ÚargsÚkwargsrf   rˆ   rL   Úflat_coordsÚ
new_coordsÚnew_datar;   s
            @r<   Úreshapez_coo_base.reshape‚   s  ø€ Ü˜D $§*¡*°t·~±~ÔFˆÜ*¨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à×)Ñ)¨$¯+©+¼cÀ%»jÐ)ÓIˆ	ÜÓPÁZÓPÓPˆ
ñ Ø—y‘y—~‘~Ó'‰Hà—y‘yˆHà�~‰~˜x¨Ð4¸EÈˆ~ÓNÐNr}   c                 ó  ‡— |�|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«      ‚t        j                  t        | j                  d|z
     «      | j                  d|z
     ¬«      S )	Nr   r	   c              3   ó:   •K  — | ]  }t        |«      ‰k7  –— Œ y ­wrN   r@   )r9   rC   Únnzs     €r<   r=   z$_coo_base._getnnz.<locals>.<genexpr>ª   s   øè ø€ Ð:©k s”3�s“8˜s•?©kùs   ƒz3all index and data arrays must have the same lengthc              3   ó:   K  — | ]  }|j                   d k7  –— Œ y­wrE   )rk   rB   s     r<   r=   z$_coo_base._getnnz.<locals>.<genexpr>®   s   è ø€ Ð)OÁ;¸C¨#¯(©(°a­-Á;ùó   ‚z'coordinates and data arrays must be 1-Dúaxis out of bounds©Ú	minlength)rk   rA   ra   re   r`   rd   Úintr7   Úbincountr   rf   )rn   Úaxisrš   s     @r<   Ú_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Ü Ð!JÓKÐKä�s“8ˆOà�!Š8Ø�D—I‘IÑˆDØ�4—9‘9ÒÜÐ1Ó2Ð2ä�{‰{Ô.¨t¯{©{¸1¸t¹8Ñ/DÓEØ%)§Z¡Z°°D±Ñ%9ô;ð 	;r}   c                 ór  — | j                  «        |€t        j                  | j                  «      S |dk  r|| j                  z  }|dk  s|| j                  k\  rt        d«      ‚| j                  dk7  }| j                  d|z
     |   }t        j                  t        |«      | j                  d|z
     ¬«      S )Nr   r�   r	   rž   )
Úsum_duplicatesr7   Úcount_nonzerora   rk   rd   r`   r¡   r   rf   )rn   r¢   ÚmaskÚcoords       r<   r¦   z_coo_base.count_nonzero½   s¤   € Ø×ÑÔØˆ<Ü×#Ñ# D§I¡IÓ.Ð.à�!Š8Ø�D—I‘IÑˆDØ�!Š8�t˜tŸy™yÒ(ÜÐ1Ó2Ð2Ø�y‰y˜A‰~ˆØ—‘˜A ™HÑ% dÑ+ˆÜ�{‰{Ô.¨uÓ5ÀÇÁÈAÐPTÉHÑAUÔVÐVr}   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r3   r‹   )r9   rC   r;   s     €r<   r=   z#_coo_base._check.<locals>.<genexpr>Ù   s'   øè ø€ ð 5Ù(3 ô ŸJ™J s°)×<Ð<Ù(3ùr>   r   zaxis z index z exceeds matrix dimension znegative axis z index: N)rk   rA   r`   rd   Ú	enumerater5   Úkindr   Únamer]   rH   rf   rZ   r   ra   rš   Úmin)rn   rª   rC   r;   s      @r<   rm   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‘��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ñ 1ð r}   c                 óÆ  ‡ — |€t        ‰ j                  «      d d d…   }n{t        ‰ t        «      r[t	        |d«      rt        |«      ‰ 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 )
Nr   Ú__len__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rN   )r\   ©r9   rª   rn   s     €r<   r=   z&_coo_base.transpose.<locals>.<genexpr>ò   s   øè ø€ Ð<±t°!˜tŸ{™{¨1�~±tùó   ƒc              3   ó<   •K  — | ]  }‰j                   |   –— Œ y ­wrN   rƒ   r·   s     €r<   r=   z&_coo_base.transpose.<locals>.<genexpr>ó   s   øè ø€ Ð=¹°1 §¡¨A¥¹ùr¸   r�   )r_   rk   rY   r   ÚhasattrrA   rd   ÚsetrZ   r‘   ra   )rn   ÚaxesrL   Úpermuted_shapeÚpermuted_coordss   `    r<   Ú	transposez_coo_base.transposeå   sÏ   ø€ Øˆ<Ü˜Ÿ™Ó#¡D b DÑ)‰DÜ˜œgÔ&Ü˜4 Ô+¬s°4«y¸D¿I¹IÒ/EÜ Ð!EÓFÐFÜ”3�t“9‹~ §¡Ò*Ü Ð!=Ó>Ð>Ø�VŠ^Üð 9ó :ð :ô Ó<±tÓ<Ó<ˆÜÓ=¹Ó=Ó=ˆØ�~‰~˜tŸy™y¨/Ð:Ø$2¸ð ó ?ð 	?r}   c                 ól  ‡	— t        || j                  ¬«      }| j                  dkD  rt        d«      ‚t	        |«      dkD  rt        d«      ‚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   zonly 1-D or 2-D input acceptedz!shape argument must be 1-D or 2-Dr	   )r   ©r	   c              3   ó,   K  — | ]  \  }}||kD  –— Œ y ­wrN   © )r9   ÚoldÚnews      r<   r=   z#_coo_base.resize.<locals>.<genexpr>  s   è ø€ ÐMÑ6L©(¨#¨s˜C #�IÑ6Lùs   ‚c              3   ó(   •K  — | ]	  }|‰   –— Œ y ­wrN   rÃ   ©r9   rC   r§   s     €r<   r=   z#_coo_base.resize.<locals>.<genexpr>  s   øè ø€ Ð#E¹°# C¨¥I¹ùó   ƒ)r   r[   rk   rd   rA   rŽ   r`   rf   ÚmathÚprodr7   r�   ra   r\   r—   re   ÚzipÚlogical_andÚreduceÚallrZ   )
rn   rf   r”   Úmax_sizeÚ	tmp_shapeÚtmpÚis_truncatingrC   Úsizer§   s
            @r<   Úresizez_coo_base.resizeù   sÐ  ø€ Ü˜E¨D¯N©NÔ;ˆØ�9‰9�qŠ=ÜÐ=Ó>Ð>Üˆu‹:˜Š>ÜÐ@ÓAÐAäˆ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ô*Ù,C™y˜s D��d“
Ð,Cò*ó ˆDð —8‘8”:Ü#Ó#E¸¿ºÓ#EÓE�”Ø ŸI™I d™O�”	àˆ�ùó*s   Ç
H0
c                 ó@  — | j                  ||«      }t        |j                  j                  «      }|s!|j                  j                  st        d«      ‚| j                  dk(  rat        t        j                  dg«      | j                  | j                  | j                  d   | j                  |j                  d«      |«       �n@| j                  dk(  rY| j                  \  }}t        ||| j                  | j                   | j"                  | j                  |j                  d«      |«       nØ|r7t        j$                  dt        j&                  | j                  d d «      «      }nBt        j$                  t        j&                  | j                  dd  d d d…   «      d d d…   d«      }t        j(                  | j                  «      }t        || j                  | j                  || j                  |j                  d«      |«       |j+                  | j                  «      S )Nz&Output array must be C or F contiguousr	   r   ÚAr   r   )Ú_process_toarray_argsr    ÚflagsÚf_contiguousÚc_contiguousrd   rk   r   r7   r8   rš   r`   ra   Úravelrf   r   r|   ry   ÚappendÚcumprodÚconcatenater—   )	rn   rˆ   ÚoutÚBÚfortranrs   ÚNÚstridesr`   s	            r<   Útoarrayz_coo_base.toarray!  s‡  € Ø×&Ñ& u¨cÓ2ˆÜ�a—g‘g×*Ñ*Ó+ˆÙ˜qŸw™w×3Ò3ÜÐEÓFÐFð �9‰9˜Š>Üœ2Ÿ8™8 Q C›=¨$¯(©(°D·I±IØŸ;™; q™>¨4¯9©9°a·g±g¸c³lÀGöMà�Y‰Y˜!Š^Ø—:‘:‰DˆAˆqÜ˜˜1˜dŸh™h¨¯©°$·(±(¸D¿I¹IØŸ™ › gõ/ñ ÜŸ)™) A¤r§z¡z°$·*±*¸S¸b°/Ó'BÓC‘äŸ)™)¤B§J¡J¨t¯z©z¸!¸"¨~¹dÀ¸dÑ/CÓ$DÁTÀrÀTÑ$JÈAÓN�Ü—^‘^ D§K¡KÓ0ˆFÜ˜7 D§H¡H¨d¯i©iØ! 4§9¡9¨a¯g©g°c«l¸GôEð �y‰y˜Ÿ™Ó$Ð$r}   c                 ór  — | j                   dk7  rt        d| j                   › 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. CSC format must be 2D. Got rQ   r   r4   r	   )Ú	csc_array©rf   )rk   rd   rš   Ú_csc_containerrf   r5   Ú_cscræ   Ú_coo_to_compressedÚ_swaprb   r¥   )rn   rL   ræ   ÚindptrÚindicesra   rf   Úxs           r<   Útocscz_coo_base.tocsc<  s¨   € ð( �9‰9˜Š>ÜÐJÈ4Ï9É9È+ÐUVÐWÓXÐXØ�8‰8�qŠ=Ø×&Ñ& t§z¡z¸¿¹Ð&ÓDÐDå'Ø+/×+BÑ+BÀ9Ç?Á?Ó+SÑ(ˆF�G˜T 5à×#Ñ# T¨7°FÐ$;À5Ð#ÓIˆAØ×,Ò,Ø× Ñ Ô"ØˆHr}   c                 óŽ  — | j                   dkD  rt        d| j                   › d�«      ‚| 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   z*Cannot convert. CSR must be 1D or 2D. Got rQ   r   r4   r	   )Ú	csr_arrayrO   rç   )rk   rd   rš   Ú_csr_containerrf   r5   Ú_csrrñ   rê   rë   rb   r¥   )	rn   rL   rñ   Úarraysrì   rí   ra   rf   rî   s	            r<   Útocsrz_coo_base.tocsr]  s¶   € ð( �9‰9�qŠ=ÜÐIÈ$Ï)É)ÈÐTUÐVÓWÐWØ�8‰8�qŠ=Ø×&Ñ& t§z¡z¸¿¹Ð&ÓDÐDå'Ø×,Ñ,¨Y¯_©_À4Ð,ÓHˆFØ+1Ñ(ˆF�G˜T 5à×#Ñ# T¨7°FÐ$;À4Ç:Á:Ð#ÓNˆAØ×,Ò,Ø× Ñ Ô"ØˆHr}   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   r4   FrO   )Ú_shape_as_2dr]   r`   rH   rš   rk   rL   rA   r7   r8   ra   rf   rT   ÚemptyÚ
empty_liker5   r   )rn   ÚswaprL   rs   râ   r;   rí   rš   rì   ra   ÚmajorÚminors               r<   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Ð0r}   c                 ó*   — |r| j                  «       S | S rN   rO   )rn   rL   s     r<   rh   z_coo_base.tocooš  s   € ÙØ—9‘9“;ÐàˆKr}   c                 óª  — | j                   dk7  rt        d| j                   › d�«      ‚| j                  «        | j                  | j                  z
  }t        j                  |d¬«      \  }}t        |«      dkD  rt        dt        |«      › d�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. DIA format must be 2D. Got rQ   T)Úreturn_inverseéd   zConstructing a DIA matrix with z diagonals is inefficientr­   r   )r   r   r4   r	   rç   )rk   rd   r¥   ry   r|   r7   ÚuniquerA   r   r   ra   rÓ   Úzerosr5   rH   Ú_dia_containerrf   )rn   rL   ÚksÚdiagsÚdiag_idxra   s         r<   Útodiaz_coo_base.todia¢  s  € Ø�9‰9˜Š>ÜÐJÈ4Ï9É9È+ÐUVÐWÓXÐXØ×ÑÔØ�X‰X˜Ÿ™Ñ ˆÜŸ)™) B°tÔ<‰ˆˆxäˆu‹:˜ÒäÐ2´3°u³:°,ð ?"ð "ä(°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ÐCr}   c                 ón  — | j                   dkD  rt        d| j                   › d�«      ‚| j                  «        | j                  | j                  | j
                  ¬«      }| j                   dk(  r| j                  d   }nt        | j                  Ž }t        t        || j                  «      «      |_
        |S )Nr   z*Cannot convert. DOK must be 1D or 2D. Got rQ   r4   r	   r   )rk   rd   r¥   Ú_dok_containerrf   r5   r`   rË   Údictra   Ú_dict)rn   rL   Údokr`   s       r<   Útodokz_coo_base.todokº  s’   € Ø�9‰9�qŠ=ÜÐIÈ$Ï)É)ÈÐTUÐVÓWÐWØ×ÑÔØ×!Ñ! $§*¡*°D·J±JÐ!Ó?ˆà�9‰9˜Š>Ø—[‘[ ‘^‰Fä˜$Ÿ+™+Ð&ˆFäœ˜V T§Y¡YÓ/Ó0ˆŒ	Øˆ
r}   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   r4   c              3   ó(   •K  — | ]	  }|‰   –— Œ y ­wrN   rÃ   )r9   rC   Ú	diag_masks     €r<   r=   z%_coo_base.diagonal.<locals>.<genexpr>Ø  s   øè ø€ Ð?±;¨C˜˜Y�±;ùrÈ   )rk   rd   rf   r7   rø   ra   r5   r  r³   rH   r|   ry   rb   rZ   r`   Ú_sum_duplicates)
rn   ÚkÚrowsÚcolsÚdiagr|   ra   Úindsr:   r  s
            @r<   Ú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‰_Ñàˆr}   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   r4   F)rk   rd   rf   rA   r|   r5   ry   r³   r7   Ú
logical_orÚarangerø   rÞ   r`   ra   rb   )rn   Úvaluesr  rs   râ   r;   Ú	full_keepÚ	max_indexÚkeepr€   r…   r–   s               r<   Ú_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Ð#>Ó?ˆŒ	Ø$)ˆÕ!r}   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rN   rO   rB   s     r<   r=   z'_coo_base._with_data.<locals>.<genexpr>  s   è ø€ Ð=±¨#˜3Ÿ8™8Ÿ:±ùrP   ©rf   r5   )rZ   r`   r‘   rf   r5   )rn   ra   rL   r`   s       r<   Ú
_with_dataz_coo_base._with_data  sE   € ñ ÜÑ=°·²Ó=Ó=‰Fà—[‘[ˆFØ�~‰~˜t V˜n°D·J±JÀdÇjÁjˆ~ÓQÐQr}   c                 óf  — t        || j                  | j                  «      \  }}}}t        j                  t        | j                  «      t        j                  ¬«      }g }g }g }	t        t        || j                  «      «      D �]  \  }
\  }}t        |t        «      r	|||k(  z  }Œ#t        |t        «      r²|t        d «      k(  r|j                  |«       ŒS|j                  | j                  |
   «      \  }}}|dk7  rD|dk  r||k  ||kD  z  }n||k\  ||k  z  }t        j                   ||z
  |«      \  }}||dk(  |z  z  }n||k\  ||k  z  }||z
  }||z  }|j                  |«       Œå|j                  |«       |	j                  |«       �Œ	 |dk(  r8| j                  |   j#                  «       j%                  | j&                  d¬«      S |D �cg c]  }||   ‘Œ	 }}| j                  |   }|	�rt)        |	Ž }	|	d   j                  }t        j*                  |	«      j-                  t        |	«      dd«      }t        j*                  |D �cg c]  }||   ‘Œ	 c}«      d d …d d …d f   }||k(  j/                  d¬«      }|j1                  «       \  }}||   }|D �cg c]  }||   ‘Œ	 }}t3        t        j4                  ||¬	«      «      }t        |«      |d   |d   z
  dz   k(  r|d   }|d | |z   ||d  z   }n||z   }|r‘|rt        j6                  |d   «      }n7t        j8                  t        |«      | j                  d   j&                  ¬«      }|j;                  |d   |«       |dd  D ]"  }
|j;                  |
|j=                  «       «       Œ$ t?        ||f|| j&                  ¬
«      S c c}w c c}w c c}w )Nr4   r	   r   rÃ   FrO   r   ©r¢   rç   r"  ) r$   rf   rg   r7   ÚonesrA   ra   Úbool_r°   rË   r`   rY   r    ÚslicerÜ   rí   r�   ÚsumrT   r5   r%   r8   r—   rÎ   rl   Úlistr�   rx   r  ÚinsertrL   r   )rn   ÚkeyrG   Ú	new_shapeÚarr_int_posÚnone_posÚ
index_maskÚslice_coordsÚ
arr_coordsÚarr_indicesrª   rC   rŒ   ÚstartÚstopÚstepÚin_rangeÚnew_ixÚmr•   r–   Ú	arr_shapeÚkeyarrÚfoundÚarr_coÚarr_ixÚnew_arr_coordsÚposÚ
coord_likes                                r<   Ú__getitem__z_coo_base.__getitem__  s’  € Ü2CØ�—‘˜TŸ[™[ó3
Ñ/ˆˆy˜+ xô —W‘WœS §¡›^´2·8±8Ô<ˆ
ØˆØˆ
ØˆÜ%¤c¨%°·±Ó&=×>‰LˆA‰y��RÜ˜#œsÔ#Ø˜r S™yÑ)‘
Ü˜C¤Ô'Øœ% ›+Ò%Ø ×'Ñ'¨Õ+à(+¯©°D·J±J¸q±MÓ(BÑ%�E˜4 Ø˜q’yØ !š8Ø(*¨e©¸¸T¹	Ñ'B™Hà(*¨e©¸¸T¹	Ñ'B˜HÜ$&§I¡I¨b°5©j¸$Ó$?™	˜ Ø" q¨A¡v°Ñ&9Ñ9™
à$&¨%¡K°B¸±IÑ#>˜Ø!# e¡˜Ø" hÑ.˜
Ø ×'Ñ'¨Õ/à×!Ñ! "Ô%Ø×"Ñ" 3Ö'ð- ?ð0 ˜Š?Ø—9‘9˜ZÑ(×,Ñ,Ó.×5Ñ5°d·j±jÀuÐ5ÓMÐMá/;Ó<©|¨�b˜“n¨|ˆ
Ð<Ø—9‘9˜ZÑ(ˆò Ü+¨[Ð9ˆKØ# A™×,Ñ,ˆIô —X‘X˜kÓ*×2Ñ2´3°{Ó3CÀQÈÓKˆFÜŸ™¹JÓ"G¹J°b 2 j£>¸JÑ"GÓHÊÊAÈtÈÑTˆJØ˜zÑ)×.Ñ.°AÐ.Ó6ˆEØ"Ÿ]™]›_‰NˆF�FØ Ñ'ˆHÙ/9Ó:©z¨˜"˜V›*¨zˆJÐ:Ü!¤"×"2Ñ"2°6ÀÔ"KÓLˆNô �;Ó ;¨r¡?°[À±^Ñ#CÀaÑ#GÒGà! !‘n�Ø'¨¨Ð-°Ñ>ÀÈCÈDÐAQÑQ‘
ð ,¨jÑ8�
áÙÜŸ]™]¨:°a©=Ó9‘
äŸX™X¤c¨(£m¸4¿;¹;Àq¹>×;OÑ;OÔP�
Ø×Ñ˜h q™k¨:Ô6Ø˜a˜b“\�Ø×!Ñ! ! Z§_¡_Ó%6Õ7ð "ä˜( JÐ/°yÈÏ
É
ÔSÐSùò] =ùò, #Hùò ;s   ÇN$ÉN)ÊN.c           	      óÞ  — t        || j                  | j                  «      \  }}}}|r4t        |«      }|d d d…   D ]  }|j	                  |«       Œ t        |«      }|r[t        |«      }|D �ci c]  }t        ||   x}	«      rŒ||	“Œ }
}t        |
j                  «       Ž }t        |
|«      D ]
  \  }}	|	||<   Œ t        |«      r*d|j                  v ry t        ||| j                  «      \  }}n@t        j                  || j                  ¬«      }|j                  dk(  ry t!        ||«      \  }}| j#                  |«      \  }}t%        |«      dk(  r!t%        |d   «      dk(  r||c| _        | _        y d }d}|rp|D ]k  }t+        |t,        «      rŒt        |«      rŒ |j                  }t%        |«      |d   |d   z
  dz   k(  r|d   }nd}|||t%        |«      z    }t/        ||«      } n d}i }t1        |«      D ]3  \  }}||k(  r|t%        |«      z  }t+        |t,        «      sŒ*|||<   |dz  }Œ5 d g| j2                  z  }t%        |«      }t1        |«      D ]…  \  }}t        |«      rt        j4                  ||f«      ||<   Œ,t+        |t,        «      r4|j7                  | j                  |   «      \  }}}||||      |z  z   ||<   Œp|j9                  «          ||<   Œ‡ |j;                  «       }t        j<                  |«      }t        j>                  |dd¬«      \  }}t        j@                  |||   g«      | _        t        d„ t        ||d d …|f   «      D «       «      | _        d| _!        y c c}w )	Nr   r   r4   r	   T)r¢   Úreturn_indexc              3   óF   K  — | ]  }t        j                  |«      –— Œ y ­wrN   )r7   Úhstack)r9   Úcs     r<   r=   z(_coo_base.__setitem__.<locals>.<genexpr>Ò  s   è ø€ ÐVÑ2U¨QœBŸI™I aŸLÑ2Uùs   ‚!F)"r$   rf   rg   r*  ÚpoprZ   r"   r%   r  rË   r   Ú_get_sparse_data_and_coordsr5   r7   ri   rÓ   Ú_get_dense_data_and_coordsÚ
_zero_manyrA   ra   r`   rY   r(  rŽ   r°   rk   Úbroadcast_torí   rÛ   rL   r8   r  rF  rb   )rn   r,  rî   rG   r-  r.  r/  Újrª   ÚarrÚarr_posr3  Úx_dataÚx_coordsÚold_dataÚ
old_coordsr:  r@  rC   Ú	x_arr_cooÚx_arr_coo_ravelÚx_axÚx_axesr•   Únew_nnzr4  r5  r6  r–   r:   Úinds                                  r<   Ú__setitem__z_coo_base.__setitem__e  sb  € ä2CØ�—‘˜TŸ[™[ó3
Ñ/ˆˆy˜+ xñ Ü˜Y›ˆIØ™d ˜d”^�Ø—‘˜aÕ ð $ä˜iÓ(ˆIñ Ü˜“KˆEÙ'2ÓU¡{ !¼)È5ÐQRÉ8ÀOÀCÕ:T�q˜#‘v {ˆGÐUÜ+¨W¯^©^Ó-=Ð>ˆKÜ˜g {Ö3‘��3Ø��a’ð 4ô �AŒ;Ø�A—G‘G‰|ØÜ:¸1¸iÈÏÉÓTÑˆF‘Hä—
‘
˜1 D§J¡JÔ/ˆAØ�v‰v˜Š{ØÜ9¸!¸YÓGÑˆF�Hð  $Ÿ™¨uÓ5Ñˆ�*äˆx‹=˜AÒ¤# h¨q¡kÓ"2°aÒ"7Ø%-¨zÐ"ˆDŒI�t”{àð ˆ	ØˆÙó �Ü! #¤uÕ-´iÀµnØ #§	¡	�Iô
 ˜;Ó'¨K¸©O¸kÈ!¹nÑ,LÈqÑ,PÒQØ)¨!™n™à˜ð !)¨¨S´3°y³>Ñ-AÐ B�Iä&3°I¸yÓ&I�OÙð# ð( ˆØˆÜ Ö&‰FˆAˆsØ�CŠxØœ˜I›Ñ&�Ü˜#œuÕ%Ø ��q‘	Ø˜‘	‘ð 'ð �V˜dŸi™iÑ'ˆ
Ü�f“+ˆÜ Ö&‰FˆAˆsÜ˜Œ~Ü!#§¡°°w°jÓ!A�
˜1‘ØÜ˜C¤Ô'Ø$'§K¡K°·
±
¸1±Ó$>Ñ!��t˜TØ!&¨°&¸±)Ñ)<¸tÑ)CÑ!C�
˜1’à #§	¡	£¨OÑ <�
˜1’ð 'ð —;‘;“=ˆô —X‘X˜jÓ)ˆ
Ü—‘˜:¨A¸DÔA‰ˆˆ3ô —I‘I˜x¨°#©Ð7Ó8ˆŒ	ÜÑV´#°jÀ*ÊQÐPSÈVÑBTÔ2UÓVÓVˆŒØ$)ˆÕ!ùò{ Vs   Á.M*ÂM*c                 óž  — t        j                  t        | j                  «      t         j                  ¬«      }g }g }t        t        || j                  «      «      D ]ù  \  }\  }}t        |t        «      r	|||k(  z  }Œ"t        |t        «      r‡|t        d «      k7  ry|j                  | j                  |   «      \  }}	}
|
dk7  rA|
dk  r||k  ||	kD  z  }n||k\  ||	k  z  }t        j                  ||z
  |
«      }||dk(  |z  z  }Œ¨||k\  ||	k  z  }||z  }Œ¹t        |t        «      r|t        d «      k(  rŒØ|j                  |«       |j                  |«       Œû |rºt        j                  |«      j!                  t        |«      dd«      }t        j                  |D �cg c]  }||   ‘Œ	 c}«      d d …d d …d f   }||k(  j#                  d¬«      }|j%                  «       \  }}t        j&                  |«      }d||j%                  «       d   |   <   ||z  }| j                  D �cg c]  }||    ‘Œ
 }}| j                  |    }||fS c c}w c c}w )Nr4   r	   r   r   r%  T)r7   r&  rA   ra   r'  r°   rË   r`   rY   r    r(  rí   rf   ÚmodrÜ   r8   r—   rÎ   rl   rx   )rn   rG   r0  r2  r3  rª   rC   rŒ   r4  r5  r6  r7  r9  r;  r<  Úarr_coor:   Úarr_index_maskÚpruned_coordsÚpruned_datas                       r<   rK  z_coo_base._zero_manyÕ  s5  € ô —7‘7œ3˜tŸy™y›>´·±Ô:ˆ
Øˆ
ØˆÜ%¤c¨%°·±Ó&=Ö>‰LˆA‰y��RÜ˜#œsÔ#Ø˜r S™yÑ)‘
Ü˜C¤Ô'¨C´5¸³;Ò,>Ø$'§K¡K°·
±
¸1±Ó$>Ñ!��t˜TØ˜1’9Ø˜a’xØ$&¨%¡K°B¸±IÑ#>™à$&¨%¡K°B¸±IÑ#>˜ÜŸ™˜r E™z¨4Ó0�AØ 1¨¡6¨XÑ"5Ñ5‘Jà " e¡°°T±	Ñ:�HØ (Ñ*‘JÜ˜C¤Ô'¨C´5¸³;Ò,>àà×!Ñ! "Ô%Ø×"Ñ" 3Õ'ð) ?ñ. Ü—X‘X˜kÓ*×2Ñ2´3°{Ó3CÀQÈÓKˆFÜŸ™¹JÓ"G¹J°b 2 j£>¸JÑ"GÓHÊÊAÈtÈÑTˆJØ˜zÑ)×.Ñ.°AÐ.Ó6ˆEØŸ™›‰JˆG�QÜŸ]™]¨:Ó6ˆNØ?CˆN˜:×-Ñ-Ó/°Ñ2°7Ñ;Ñ<Ø˜.Ñ(ˆJð 48·;²;Ó?±;¨R˜˜Z˜K›°;ˆÐ?Ø—i‘i  Ñ,ˆØ˜MÐ)Ð)ùò #Hùò @s   ÆIÈ"I
c                 ó–   — | j                   ry| j                  | j                  | j                  «      }|\  | _        | _        d| _         y)zeEliminate duplicate entries by adding them together

        This is an *in place* operation
        NT)rb   r  r`   ra   )rn   Úsummeds     r<   r¥   z_coo_base.sum_duplicates   s@   € ð
 ×$Ò$ØØ×%Ñ% d§k¡k°4·9±9Ó=ˆØ!'ÑˆŒ�T”YØ$(ˆÕ!r}   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                  |t        |«      | j                  ¬«      }||fS c c}w )Nr   r   c              3   ó(   •K  — | ]	  }|‰   –— Œ y ­wrN   rÃ   )r9   rC   rˆ   s     €r<   r=   z,_coo_base._sum_duplicates.<locals>.<genexpr>  s   øè ø€ Ð4©V c�s˜5•z©VùrÈ   r	   Tc              3   ó(   •K  — | ]	  }|‰   –— Œ y ­wrN   rÃ   )r9   rC   Úunique_masks     €r<   r=   z,_coo_base._sum_duplicates.<locals>.<genexpr>  s   øè ø€ Ð:±6¨C�s˜;Õ'±6ùrÈ   r4   )rA   r7   ÚlexsortrZ   r  rÍ   rÜ   rl   ÚaddÚreduceatr   r5   )rn   r`   ra   rC   Úunique_indsrˆ   rf  s        @@r<   r  z_coo_base._sum_duplicates  sè   ù€ äˆt‹9˜Š>Ø˜4�<Ðô —
‘
˜6¡$ B $™<Ó(ˆÜÓ4©VÓ4Ó4ˆØ�E‰{ˆÜ—m‘m×*Ñ*Ù+1ó,
Ù+1 CˆC��ˆG�s˜3˜B�xÓ¨6ñ,
ó ˆô —i‘i  kÓ2ˆÜÓ:±6Ó:Ó:ˆÜ—z‘z +Ó.‰ˆÜ�v‰v�‰˜tÔ%8¸Ó%EÈTÏZÉZˆÓXˆØ�tˆ|Ðùò,
s   Á&C9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rN   rÃ   rÇ   s     €r<   r=   z,_coo_base.eliminate_zeros.<locals>.<genexpr>%  s   øè ø€ Ð=±¨#˜C �I±ùrÈ   N)ra   rZ   r`   )rn   r§   s    @r<   Úeliminate_zerosz_coo_base.eliminate_zeros  s7   ø€ ð
 �y‰y˜A‰~ˆØ—I‘I˜d‘OˆŒ	ÜÓ=°·²Ó=Ó=ˆ�r}   c                 óÜ  — |j                   | j                   k7  r&t        d| j                   › d|j                   › d�«      ‚t        | j                  j                  |j                  j                  «      }t        j                  ||d¬«      }t        |j                  j                  «      }| j                  dk(  rat        t        j                  dg«      | j                  | j                  | j                  d   | j                  |j                  d«      |«       �n@| j                  d	k(  rY| j                   \  }}t#        ||| j                  | j$                  | j&                  | j                  |j                  d«      |«       nØ|r7t        j(                  dt        j*                  | j                   d d
 «      «      }nBt        j(                  t        j*                  | j                   dd  d d d
…   «      d d d
…   d«      }t        j,                  | j                  «      }t        || j                  | j                  || j                  |j                  d«      |«       | j/                  |d¬«      S )NúIncompatible shapes (ú and r«   T)r5   rL   r	   r   rÖ   r   r   FrO   )rf   rd   r   r5   Úcharr7   r8   r    rØ   rÙ   rk   r   rš   r`   ra   rÛ   r÷   r   r|   ry   rÜ   rÝ   rÞ   Ú
_container)	rn   Úotherr5   r{   rá   rs   râ   rã   r`   s	            r<   Ú
_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ˆØ�9‰9˜Š>Üœ2Ÿ8™8 Q C›=¨$¯(©(°D·I±IØŸ;™; q™>¨4¯9©9°f·l±lÀ3Ó6GÈöRà�Y‰Y˜!Š^Ø×$Ñ$‰DˆAˆqÜ˜˜1˜dŸh™h¨¯©°$·(±(¸D¿I¹IØŸ™ SÓ)¨7õ4ñ ÜŸ)™) A¤r§z¡z°$·*±*¸S¸b°/Ó'BÓC‘äŸ)™)¤B§J¡J¨t¯z©z¸!¸"¨~¹dÀ¸dÑ/CÓ$DÁTÀrÀTÑ$JÈAÓN�Ü—^‘^ D§K¡KÓ0ˆFÜ˜7 D§H¡H¨d¯i©iØ! 4§9¡9¨f¯l©l¸3Ó.?ÀôJà�‰˜v¨EˆÓ2Ð2r}   c                 ó  — | j                   dk  r| j                  «       j                  |«      S |j                  | j                  k7  r&t	        d| j                  › d|j                  › d�«      ‚| j                  |«      }t        j                  | j                  |j                  f«      }t        t        j                  | j                  |j                  fd¬«      «      }| j                  ||f| j                  ¬«      }|S ©Nr¬   ro  rp  r«   r	   r%  rç   )rk   rõ   Ú_add_sparserf   rd   r‘   r7   rÞ   ra   rZ   r`   ©rn   rs  r–   r•   rÖ   s        r<   rw  z_coo_base._add_sparseC  sÃ   € Ø�9‰9�qŠ=Ø—:‘:“<×+Ñ+¨EÓ2Ð2à�;‰;˜$Ÿ*™*Ò$ÜÐ4°T·Z±Z°LÀÀeÇkÁkÀ]ÐRSÐTÓUÐUØ—‘˜uÓ%ˆÜ—>‘> 4§9¡9¨e¯j©jÐ"9Ó:ˆÜœ2Ÿ>™>¨4¯;©;¸¿¹Ð*EÈAÔNÓOˆ
Ø�N‰N˜H jÐ1¸¿¹ˆNÓDˆØˆr}   c                 óø  — | j                   dk  r| j                  «       j                  |«      S |j                  | j                  k7  r&t	        d| j                  › d|j                  › d�«      ‚| j                  |«      }t        j                  | j                  |j                   f«      }t        t        j                  | j                  |j                  fd¬«      «      }t        ||f| j                  ¬«      }|S rv  )rk   rõ   Ú_sub_sparserf   rd   r‘   r7   rÞ   ra   rZ   r`   r   rx  s        r<   rz  z_coo_base._sub_sparseO  s¿   € Ø�9‰9�qŠ=Ø—:‘:“<×+Ñ+¨EÓ2Ð2à�;‰;˜$Ÿ*™*Ò$ÜÐ4°T·Z±Z°LÀÀeÇkÁkÀ]ÐRSÐTÓUÐUØ—‘˜uÓ%ˆÜ—>‘> 4§9¡9¨u¯z©z¨kÐ":Ó;ˆÜœ2Ÿ>™>¨4¯;©;¸¿¹Ð*EÈAÔNÓOˆ
Ü�x Ð,°D·J±JÔ?ˆØˆr}   c           	      óÐ  — | j                   dkD  �r:t        j                  t        j                  | j
                  d d «      t        | j                  j                  |j                  j                  «      ¬«      }t        j                  | j
                  «      }t        j                  t        j                  |d d d d d…   «      d d d…   dd  d«      }t        j                  | j                  «      }t        | j                  t!        | j
                  «      ||| j"                  ||«       |j%                  | j
                  d d «      }|S | 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"                  ||«       t1        | t2        «      r
|dk(  r|d   S |S )Nr   r   r4   r	   r   z$coo_matvec not implemented for ndim=)rk   r7   r  rÉ   rÊ   rf   r   r5   rq  r8   rÜ   rÝ   rÞ   r`   r   rš   rA   ra   r—   ry   r|   rx   ÚNotImplementedErrorr   rY   r   )	rn   rs  r{   rf   rã   r`   Úresult_shapery   r|   s	            r<   Ú_matmul_vectorz_coo_base._matmul_vector[  sÓ  € Ø�9‰9�q‹=Ü—X‘XœdŸi™i¨¯
©
°3°B¨Ó8Ü$/°·
±
·±ÀÇÁ×AQÑAQÓ$RôTˆFä—H‘H˜TŸZ™ZÓ(ˆEÜ—i‘i¤§
¡
¨5°°"¨:±d¸°dÑ+;Ó <¹T¸r¸TÑ BÀ1À2Ð FÈÓJˆGÜ—^‘^ D§K¡KÓ0ˆFÜ˜$Ÿ(™(¤C¨¯
©
£O°W¸fÀdÇiÁiØ ô)ð —^‘^ D§J¡J¨s° OÓ4ˆFØˆMð )-¯	©	°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ÐØˆr}   c                 ó  — t        |«      r| j                  |«      S 	 |j                  }t        t        |«      d d «      t        t        |«      dd  d d d…   «      z   }|j                  |«      }| j                  }t        t        |«      d d «      t        t        |«      dd  d d d…   «      z   }| j                  |«      j                  |«      }|t        u rt        S |dk(  s|dk(  rt        |j                  «      }nIt        t        |j                  «      d d «      t        t        |j                  «      dd  d d d…   «      z   }|j                  |«      S # t        $ r% t	        j
                  |«      }|j                  }Y �Œ\w xY w)Nrv   r   r	   )r!   Ú_mul_scalarrk   ÚAttributeErrorr7   ri   rZ   r_   r¿   Ú_matmul_dispatchÚNotImplemented)rn   rs  Úo_ndimÚpermÚtrÚs_ndimÚrets          r<   Ú_rmatmul_dispatchz_coo_base._rmatmul_dispatch|  s^  € Ü˜ÔØ×#Ñ# EÓ*Ð*ð$ØŸ™�ô œ˜v› s¨Ð+Ó,¬u´U¸6³]À2À3Ð5GÉÈ"ÈÑ5MÓ/NÑNˆDØ—‘ Ó&ˆBà—Y‘YˆFÜœ˜v› s¨Ð+Ó,¬u´U¸6³]À2À3Ð5GÉÈ"ÈÑ5MÓ/NÑNˆDØ—.‘. Ó&×7Ñ7¸Ó;ˆCØ”nÑ$Ü%Ð%à˜Š{˜f¨škÜ˜SŸX™X“‘äœU 3§8¡8›_¨S¨bÐ1Ó2´U¼5ÀÇÁ»?È2È3Ð;OÑPTÐRTÐPTÑ;UÓ5VÑV�Ø—=‘= Ó&Ð&øô! "ò $ÜŸ
™
 5Ó)�ØŸ™“ð$ús   žE Å*FÆFc                 ó¦  — t        |«      r| j                  |«      S t        |«      s_t        |«      sTt	        j
                  |«      }|j                  dk(  r#|j                  t        j                  k(  rt        S 	 |j                   | j                  dk  r%|j                  dk  rt        j                  | |«      S | j                  d   }d}|j                  t        j                  u �r"|j                  |fk(  r| j!                  |«      S |j                  |dfk(  r@| j!                  |j#                  «       «      } |j$                  g | j                  d d ¢d‘­Ž S |j                  dk(  r#|› d|› d|j                  d   › d�}t'        |«      ‚|j                  d	   |k(  rK| j                  d d	 }|j                  d d	 }||k7  r	 t	        j(                  ||«       | j+                  |«      S t'        |› d|› d|j                  d	   › d�«      ‚t        |«      r| j-                  |«      S t        |«      �r]| j                  dk(  }	|j                  dk(  }
|	r| j%                  | j.                  «      } |
r |j%                  |j                  d   df«      }||j                  d	   k7  r!t'        |› d|› d|j                  d	   › d�«      ‚| j                  dkD  s|j                  dkD  r:| j                  d d	 }|j                  d d	 }||k7  r	 t	        j(                  ||«       | j1                  |«      }|	r@|j%                  t3        |j                  d d	 «      t3        |j                  dd  «      z   «      }|
r|j%                  |j                  d d «      }|S y # t        $ r |}Y �Œw xY w# t&        $ r t'        d
«      ‚w xY w# t&        $ r t'        d
«      ‚w xY w)Nr   r¬   r   z)matmul: dimension mismatch with signaturer	   z (n,k=z),(k=z,)->(n,)rv   z&Batch dimensions are not broadcastablez	 (n,..,k=z,..,m)->(n,..,m)r   )r!   Úmultiplyr   r#   r7   Ú
asanyarrayrk   r5   Úobject_rƒ  rf   r�  r   r‚  r‘   Úndarrayr~  rÛ   r—   rd   Úbroadcast_shapesÚ_matmul_multivectorr€  r÷   Ú_matmul_sparserZ   )rn   rs  Úother_arâ   Ú
err_prefixr{   ÚmsgÚbatch_shape_AÚbatch_shape_BÚ
self_is_1dÚother_is_1ds              r<   r‚  z_coo_base._matmul_dispatch•  s¬  € Ü˜ÔØ—=‘= Ó'Ð'ä˜”¤7¨5¤>ä—m‘m EÓ*ˆGà�|‰|˜qÒ  W§]¡]´b·j±jÒ%@ô &Ð%ð Ø—’ð �9‰9�qŠ=˜UŸZ™Z¨!š^Ü×+Ñ+¨D°%Ó8Ð8à�J‰J�r‰NˆØ@ˆ
Ø�?‰?œbŸj™jÒ(Ø�{‰{˜q˜dÒ"Ø×*Ñ*¨5Ó1Ð1Ø�{‰{˜q !˜fÒ$Ø×,Ñ,¨U¯[©[«]Ó;�Ø%�v—~‘~Ð: t§z¡z°#°2 Ð:¸Ò:Ð:Ø�z‰z˜QŠØ#˜ F¨1¨#¨U°5·;±;¸q±>Ð2BÀ(ÐK�Ü  “oÐ%Ø�{‰{˜2‰ !Ò#à $§
¡
¨3¨B �Ø %§¡¨C¨RÐ 0�Ø  MÒ1ðSä×+Ñ+¨M¸=ÔIð ×/Ñ/°Ó6Ð6ä Ø!�l )¨A¨3¨e°E·K±KÀ±OÐ3DÐDTÐUóð ô ˜Ôà×#Ñ# EÓ*Ð*ä�E�?ØŸ™ a™ˆJØŸ*™*¨™/ˆKñ Ø—|‘| D×$5Ñ$5Ó6�áØŸ™ u§{¡{°1¡~°qÐ&9Ó:�ð �E—K‘K ‘OÒ#Ü Ø!�l )¨A¨3¨e°E·K±KÀ±OÐ3DÐDTÐUóð ð �y‰y˜1Š} §
¡
¨Q¢Ø $§
¡
¨3¨B �Ø %§¡¨C¨RÐ 0�Ø  MÒ1ðSä×+Ñ+¨M¸=ÔIð ×(Ñ(¨Ó/ˆFñ àŸ™¬¨f¯l©l¸3¸BÐ.?Ó(@Ü(-¨f¯l©l¸2¸3Ð.?Ó(@ñ)Aó B�áØŸ™¨¯©°S°bÐ(9Ó:�ØˆMðM øôM "ò  Ø“ð ûô2 &ò SÜ(Ð)QÓRÐRðSûôN &ò SÜ(Ð)QÓRÐRðSús*   Á;N ÇN# ÌN; ÎN ÎN Î#N8Î;Oc                 ó8  — t        | j                  j                  |j                  j                  «      }| j                  dk\  s|j                  dk\  �rÌ| j                  dk(  rn| j	                  d| j
                  d   «      j                  |«      }|j	                  t        |j
                  d d «      t        |j
                  dd  «      z   «      S t        j                  | j
                  d d |j
                  d d «      }|| j
                  dd  z   }||j
                  dd  z   }| j                  |«      } t        j                  ||«      }|| j
                  dd z   |j
                  dd  z   }t        j                  ||¬«      }t        | j                  t        | j
                  «      |j
                  d   t        j                   |«      t        j                   |«      t        j"                  | j$                  «      | j&                  |j)                  d«      |«	       |S | j                  dk(  r7| j
                  d   |j
                  d   f}| j*                  }| j,                  }	nC| j                  dk(  r4|j
                  d   f}| j$                  d   }t        j.                  |«      }	t        j                  |¬«      }t1        | j                  |j
                  d   	| j&                  |j)                  d«      |«       |j3                  t5        |«      ¬	«      S )
Nr¬   r	   r   rv   r   r4   r‰   r   )Útype)r   r5   rq  rk   r—   rf   r�  rZ   r7   r�  Ú_broadcast_torL  r  r   rš   rA   r8   rÞ   r`   ra   rÛ   ry   r|   rx   r   Úviewrš  )
rn   rs  Úresult_dtyper{   Úbroadcast_shapeÚ
self_shapeÚother_shaper}  ry   r|   s
             r<   r�  z_coo_base._matmul_multivectorò  sf  € Ü" 4§:¡:§?¡?°E·K±K×4DÑ4DÓEˆØ�9‰9˜Š>˜UŸZ™Z¨1›_à�y‰y˜AŠ~ØŸ™ a¨¯©°A©Ó7×KÑKÈEÓR�Ø—~‘~¤e¨E¯K©K¸¸Ð,<Ó&=ÄÀeÇkÁkÐRTÐRUÐFVÓ@WÑ&WÓXÐXä ×1Ñ1°$·*±*¸S¸b°/À5Ç;Á;ÈsÐPRÐCSÓTˆOØ(¨4¯:©:°b°c¨?Ñ:ˆJØ)¨E¯K©K¸¸Ð,<Ñ<ˆKà×%Ñ% jÓ1ˆDÜ—O‘O E¨;Ó7ˆEØ*¨T¯Z©Z¸¸2Ð->Ñ>ÀÇÁÈRÈSÐAQÑQˆLÜ—X‘X˜l°,Ô?ˆFÜ §¡¬#¨d¯j©j«/¸5¿;¹;Àr¹?Ü "§¡¨Ó 5´r·x±xÀÓ7MÜ "§¡¨t¯{©{Ó ;Ø $§	¡	¨5¯;©;°sÓ+;¸VôEð ˆMà�9‰9˜Š>Ø ŸJ™J q™M¨5¯;©;°q©>Ð:ˆLØ—(‘(ˆCØ—(‘(‰CØ�Y‰Y˜!Š^Ø!ŸK™K¨™NÐ,ˆLØ—+‘+˜a‘.ˆCÜ—-‘- Ó$ˆCÜ—‘˜,¨lÔ;ˆÜ˜Ÿ™ 5§;¡;¨r¡?°C¸ØŸ™ E§K¡K°Ó$4°fô	>à�{‰{¤ U£ˆ{Ó,Ð,r}   c                 óž  — t        |«      s|t        |«      sqt        |«      sft        j                  |«      }|j
                  dk(  r5|j                  t        j                  k(  rt        dt        |«      › d�«      ‚	 |j                   t        |«      r| |z  S | j                  d   |j                  dd d   k7  r&t        d| j                  › d|j                  › d	�«      ‚| j
                  d
k  r|j
                  d
k  r| |z  S t        |«      r| j                  |«      S | j                  |j                  «       «      S # t        $ r |}Y ŒÃw xY w)a°  Return the dot product of two arrays.

        Strictly speaking a dot product involves two vectors.
        But in the sense that an array with ndim >= 1 is a collection
        of vectors, the function computes the collection of dot products
        between each vector in the first array with each vector in the
        second array. The axis upon which the sum of products is performed
        is the last axis of the first array and the second to last axis of
        the second array. If the second array is 1-D, the last axis is used.

        Thus, if both arrays are 1-D, the inner product is returned.
        If both are 2-D, we have matrix multiplication. If `other` is 1-D,
        the sum product is taken along the last axis of each array. If
        `other` is N-D for N>=2, the sum product is over the last axis of
        the first array and the second-to-last axis of the second array.

        Parameters
        ----------
        other : array_like (dense or sparse)
            Second array

        Returns
        -------
        output : array (sparse or dense)
            The dot product of this array with `other`.
            It will be dense/sparse if `other` is dense/sparse.

        Examples
        --------

        >>> import numpy as np
        >>> from scipy.sparse import coo_array
        >>> A = coo_array([[1, 2, 0], [0, 0, 3], [4, 0, 5]])
        >>> v = np.array([1, 0, -1])
        >>> A.dot(v)
        array([ 1, -3, -1], dtype=int64)

        For 2-D arrays it is the matrix product:

        >>> A = coo_array([[1, 0], [0, 1]])
        >>> B = coo_array([[4, 1], [2, 2]])
        >>> A.dot(B).toarray()
        array([[4, 1],
               [2, 2]])

        For 3-D arrays the shape extends unused axes by other unused axes.

        >>> A = coo_array(np.arange(3*4*5*6)).reshape((3,4,5,6))
        >>> B = coo_array(np.arange(3*4*5*6)).reshape((5,4,6,3))
        >>> A.dot(B).shape
        (3, 4, 5, 5, 4, 3)
        r   z"dot argument not supported type: 'Ú'r   rv   Nzshapes rp  z are not aligned for n-D dotr¬   )r   r#   r!   r7   rŒ  rk   r5   r�  rc   rš  rf   r�  rd   Ú
_dense_dotÚ_sparse_dotrh   )rn   rs  Úo_arrays      r<   Údotz_coo_base.dot  s+  € ôl ˜”¤7¨5¤>´\À%Ô5Hä—m‘m EÓ*ˆGà�|‰|˜qÒ  W§]¡]´b·j±jÒ%@ÜÐ"DÄTÈ%Ã[ÀMÐQRÐ SÓTÐTð Ø—’ô
 ˜ÔØ˜%‘<Ðð �:‰:�b‰>˜UŸ[™[¨¨Ð-¨aÑ0Ò0Ü˜w t§z¡z l°%¸¿¹°}Ø;ð<ó =ð =ð �9‰9�qŠ=˜UŸZ™Z¨!š^Ø˜%‘<ÐÜ�5Œ>Ø—?‘? 5Ó)Ð)Ø×Ñ §¡£Ó.Ð.øô! "ò  Ø’ð ús   Á<D> Ä>EÅEc                 ó   — t        | | j                  dz
  g«      \  }}t        |t        d|j                  dz
  «      g«      \  }}||j                  z  }|j	                  «       }||z   }g }|r||fn|f}	t        |j                  |	«      D ]*  \  }
}|j                  t        j                  |
|«      «       Œ, t        |j                  |f|¬«      S )Nr	   r   r   rç   )Ú_convert_to_2drk   rH   ÚTrh   rË   r`   Úextendr7   r�   r   ra   )rn   rs  Úself_2dÚs_new_shapeÚother_2dÚo_new_shaperÊ   Úcombined_shaper`   Ú
new_shapesrG  Úss               r<   r¤  z_coo_base._sparse_dote  sÈ   € ô  .¨d°T·Y±YÀ±]°OÓDÑˆ�Ü .¨u´s¸1¸e¿j¹jÈ1¹nÓ7MÐ6NÓ OÑˆ�+à˜Ÿ™Ñ#ˆØ�z‰z‹|ˆð % {Ñ2ˆð ˆÙ3>�k ;Ñ/À[ÀNˆ
Ü˜Ÿ™ ZÖ0‰DˆAˆqØ�M‰Mœ"×*Ñ*¨1¨aÓ0Õ1ð 1ô ˜$Ÿ)™) VÐ,°NÔCÐCr}   c                 ó"  — | j                   }|dk  r|dk(  rdn| j                  d   f}| }nt        | | j                   dz
  g«      \  }}|j                   }|dk  r|dk(  rdn|j                  d   f}|}n‚|j                  d d |j                  dd  z   }|dz
  gt        |dz
  «      ¢|dz
  ‘­}t	        j
                  ||«      }	|	j                  |j                  d   t        j                  |«      f«      }||z  }
||z   }|
j                  |«      S )Nr   r	   rÃ   r   r   rv   )	rk   rf   r¨  r_   r7   r¿   r—   rÉ   rÊ   )rn   rs  r‡  r¬  r«  r„  r®  r­  Úreorder_dimsÚo_reorgrÊ   r¯  s               r<   r£  z_coo_base._dense_dotz  s  € ð —‘ˆØ�QŠ;Ø &¨!¢™"°$·*±*¸Q±-Ð1AˆKØ‰Gä#1°$¸¿¹ÀQ¹¸Ó#HÑ ˆG�[à—‘ˆØ�QŠ;Ø &¨!¢™"°%·+±+¸b±/Ð1CˆKØ‰HàŸ+™+ c rÐ*¨U¯[©[¸¸Ð-=Ñ=ˆKØ" Q™JÐG¬¨v¸©zÓ):ÐG¸FÀQ¹JÑGˆLÜ—l‘l 5¨,Ó7ˆGØ—‘¨¯©°B©¼¿¹À;Ó9OÐ'PÓQˆHà˜Ñ!ˆð % {Ñ2ˆØ�|‰|˜NÓ+Ð+r}   c                 ó  ‡ ‡— t        ‰«      sqt        ‰«      sft        j                  ‰«      }|j                  dk(  r5|j
                  t        j                  k(  rt        dt        ‰«      › d�«      ‚	 ‰j                   t        ‰ j                  ‰j                  |«      \  }}t        ˆˆ fd„t        ||«      D «       «      rt        d«      ‚t        ‰«      r‰ j                  ‰||«      S ‰ j!                  ‰||«      S # t        $ r |ŠY ŒŒw xY w)aŒ  Return the tensordot product with another array along the given axes.

        The tensordot differs from dot and matmul in that any axis can be
        chosen for each of the first and second array and the sum of the
        products is computed just like for matrix multiplication, only not
        just for the rows of the first times the columns of the second. It
        takes the dot product of the collection of vectors along the specified
        axes.  Here we can even take the sum of the products along two or even
        more axes if desired. So, tensordot is a dot product computation
        applied to arrays of any dimension >= 1. It is like matmul but over
        arbitrary axes for each matrix.

        Given two tensors, `a` and `b`, and the desired axes specified as a
        2-tuple/list/array containing two sequences of axis numbers,
        ``(a_axes, b_axes)``, sum the products of `a`'s and `b`'s elements
        (components) over the axes specified by ``a_axes`` and ``b_axes``.
        The `axes` input can be a single non-negative integer, ``N``;
        if it is, then the last ``N`` dimensions of `a` and the first
        ``N`` dimensions of `b` are summed over.

        Parameters
        ----------
        a, b : array_like
            Tensors to "dot".

        axes : int or (2,) array_like
            * integer_like
              If an int N, sum over the last N axes of `a` and the first N axes
              of `b` in order. The sizes of the corresponding axes must match.
            * (2,) array_like
              A 2-tuple of sequences of axes to be summed over, the first applying
              to `a`, the second to `b`. The sequences must be the same length.
              The shape of the corresponding axes must match between `a` and `b`.

        Returns
        -------
        output : coo_array
            The tensor dot product of this array with `other`.
            It will be dense/sparse if `other` is dense/sparse.

        See Also
        --------
        dot

        Examples
        --------
        >>> import numpy as np
        >>> import scipy.sparse
        >>> A = scipy.sparse.coo_array([[[2, 3], [0, 0]], [[0, 1], [0, 5]]])
        >>> A.shape
        (2, 2, 2)

        Integer axes N are shorthand for (range(-N, 0), range(0, N)):

        >>> A.tensordot(A, axes=1).toarray()
        array([[[[ 4,  9],
                 [ 0, 15]],
        <BLANKLINE>
                [[ 0,  0],
                 [ 0,  0]]],
        <BLANKLINE>
        <BLANKLINE>
               [[[ 0,  1],
                 [ 0,  5]],
        <BLANKLINE>
                [[ 0,  5],
                 [ 0, 25]]]])
        >>> A.tensordot(A, axes=2).toarray()
        array([[ 4,  6],
               [ 0, 25]])
        >>> A.tensordot(A, axes=3)
        array(39)

        Using tuple for axes:

        >>> a = scipy.sparse.coo_array(np.arange(60).reshape(3,4,5))
        >>> b = np.arange(24).reshape(4,3,2)
        >>> c = a.tensordot(b, axes=([1,0],[0,1]))
        >>> c.shape
        (5, 2)
        >>> c
        array([[4400, 4730],
               [4532, 4874],
               [4664, 5018],
               [4796, 5162],
               [4928, 5306]])

        r   z#tensordot arg not supported type: 'r¢  c              3   ób   •K  — | ]&  \  }}‰j                   |   ‰j                   |   k7  –— Œ( y ­wrN   rç   )r9   ÚaxÚbxrs  rn   s      €€r<   r=   z&_coo_base.tensordot.<locals>.<genexpr>ü  s2   øè ø€ ð 9Ù7‘6�2�rð �z‰z˜"‰~ §¡¨R¡Õ0Ù7ùs   ƒ,/z*sizes of the corresponding axes must match)r#   r   r7   rŒ  rk   r5   r�  rc   rš  rf   r�  Ú_process_axesre   rË   rd   Ú_dense_tensordotÚ_sparse_tensordot)rn   rs  r¼   Úother_arrayÚ	axes_selfÚ
axes_others   ``    r<   Ú	tensordotz_coo_base.tensordot•  sô   ù€ ôr �uŒ~¤h¨u¤oäŸ-™-¨Ó.ˆKà×Ñ 1Ò$¨×):Ñ):¼b¿j¹jÒ)HÜÐ"EÄdÈ5ÃkÀ]ÐRSÐ TÓUÐUð$Ø—’ô !.¨d¯i©i¸¿¹ÀTÓ JÑˆ	�:ô ô 9Ü  ¨JÔ7ó9ô 9äÐIÓJÐJä�5Œ>Ø×(Ñ(¨°	¸:ÓFÐFà×)Ñ)¨%°¸JÓGÐGøô "ò $Ø#’ð$ús   Á3C> Ã>DÄDc                 ót  — t        | |«      \  }}t        ||«      \  }}||j                  z  }t        |«      s|S |j                  «       }||z   }	g }
|r||fn|f}t	        |j
                  |«      D ]-  \  }}|sŒ	|
j                  t        j                  ||«      «       Œ/ t        |j                  |
f|	¬«      S )Nrç   )r¨  r©  r   rh   rË   r`   rª  r7   r�   r   ra   )rn   rs  Ús_axesÚo_axesr«  r¬  r­  r®  rÊ   r¯  r`   r°  rG  r±  s                 r<   r»  z_coo_base._sparse_tensordot  s½   € ô  .¨d°FÓ;Ñˆ�Ü .¨u°fÓ =Ñˆ�+ð ˜Ÿ™Ñ#ˆä˜Œ~ØˆKØ�z‰z‹|ˆð % {Ñ2ˆð ˆÙ3>�k ;Ñ/À[ÀNˆ
Ü˜Ÿ™ ZÖ0‰DˆAˆqÚØ—‘œb×.Ñ.¨q°!Ó4Õ5ð 1ô
 ˜$Ÿ)™) VÐ,°NÔCÐCr}   c                 ó(  — t        | j                  «      }t        |j                  «      }t        |«      D �cg c]	  }||vsŒ|‘Œ }}|D �cg c]  }| j                  |   ‘Œ }}|D �cg c]  }| j                  |   ‘Œ }	}t        |«      D �cg c]	  }||vsŒ|‘Œ }
}|D �cg c]  }|j                  |   ‘Œ }}|
D �cg c]  }|j                  |   ‘Œ }}| j                  ||z   «      }t	        j                  ||
d d |z   |
dd  z   «      }g |	¢t        j                  |«      ‘­}g |d d ¢t        j                  |«      ‘|dd  ¢­}|j                  |«      j                  |j                  |«      «      S c c}w c c}w c c}w c c}w c c}w c c}w r‚   )	rA   rf   r_   r¿   r7   rÉ   rÊ   r—   r¦  )rn   rs  rÁ  rÂ  r‡  r„  rª   Ú
s_non_axesÚs_axes_shapeÚs_non_axes_shapeÚ
o_non_axesÚo_axes_shapeÚo_non_axes_shapeÚleftÚrightÚreshape_leftÚreshape_rights                    r<   rº  z_coo_base._dense_tensordot  sŒ  € Ü�T—Z‘Z“ˆÜ�U—[‘[Ó!ˆä!& v¤ÓB¡˜A°!¸6²/’a ˆ
ÐBÙ/5Ó6©v¨!˜Ÿ
™
 1›¨vˆÐ6Ù3=Ó>±:¨a˜DŸJ™J q›M°:ÐÐ>ä!& v¤ÓB¡˜A°!¸6²/’a ˆ
ÐBÙ06Ó7±¨1˜Ÿ™ A›°ˆÐ7Ù4>Ó?±J¨q˜EŸK™K¨›N°JÐÐ?à�~‰~˜j¨6Ñ1Ó2ˆÜ—‘˜U J¨s° O°fÑ$<¸zÈ"È#¸Ñ$NÓOˆàCÐ)ÐC¬4¯9©9°\Ó+BÑCˆð1Ð*¨3¨BÐ/ð 1´·±¸<Ó1Hð 1Ø*¨2¨3Ð/ñ1ˆð �|‰|˜LÓ)×-Ñ-¨e¯m©m¸MÓ.JÓKÐKùò CùÚ6ùÚ>ùâBùÚ7ùÚ?s/   ¸	E6ÁE6ÁE;Á(F Â	FÂFÂ!F
Â=Fc                 ó  — | j                   dk  r%|j                   dk  rt        j                  | |«      S | j                  }|j                  }t	        j
                  |dd |dd «      }t        |«      |dd z   }t        |«      |dd z   }| j                  |«      }|j                  |«      }t        |«      }	t        |«      }
|	|
z  j                  «       }t        |g |¢| j                  d   ‘|j                  d   ‘­¬«      S )añ  
        Perform sparse-sparse matrix multiplication for two n-D COO arrays.
        The method converts input n-D arrays to 2-D block array format,
        uses csr_matmat to multiply them, and then converts the
        result back to n-D COO array.

        Parameters:
        self (COO): The first n-D sparse array in COO format.
        other (COO): The second n-D sparse array in COO format.

        Returns:
        prod (COO): The resulting n-D sparse array after multiplication.
        r¬   Nrv   r   rç   )rk   r   r‘  rf   r7   r�  rZ   r›  Ú_block_diagrh   Ú_extract_block_diag)rn   rs  rŸ  r   rž  Úself_new_shapeÚother_new_shapeÚself_broadcastedÚother_broadcastedÚself_block_diagÚother_block_diagÚprod_block_diags               r<   r‘  z_coo_base._matmul_sparse4  s  € ð �9‰9�qŠ=˜UŸZ™Z¨!š^Ü×)Ñ)¨$°Ó6Ð6ð —Z‘Zˆ
Ø—k‘kˆô ×-Ñ-¨j¸¸"¨o¸{È3ÈBÐ?OÓPˆÜ˜Ó/°*¸R¸S°/ÑAˆÜ Ó0°;¸r¸sÐ3CÑCˆà×-Ñ-¨nÓ=ÐØ!×/Ñ/°Ó@Ðô &Ð&6Ó7ˆÜ&Ð'8Ó9Ðð +Ð-=Ñ=×DÑDÓFˆô #ØØE�OÐE T§Z¡Z°¡^ÐE°U·[±[À±_ÑEô
ð 	
r}   c                 ób  — | j                   |k(  r|r| j                  «       S | S | j                   }t        |«      t        |«      k  rt        d«      ‚dt        |«      t        |«      z
  z  t	        |«      z   }t        d„ t        ||«      D «       «      rt        d|› d�«      ‚| j                  |«      } t        | j                  t        |«      ¬«      }| j                  }| j                  }|dd  }d}	|d   |d   k7  rY|d   }
|	|
z  }	t        j                  ||
«      }t        j                  t        j                  d	|
|¬
«      | j                   «      }|f}t#        dt        |«      dz    d«      D ]¯  }||   ||   k7  rƒ||   }
|	|
z  }	t        |«      }t        j                  ||
«      }t	        t        j                  ||dz   d  |
«      «      }t        j                  t        j                  d	|
|¬
«      |«      }|f|z   }Œ‘t        j                  ||   |	«      }|f|z   }Œ± t%        ||f|«      S )NzDNew shape must have at least as many dimensions as the current shaperÁ   c              3   ó:   K  — | ]  \  }}|d k7  xr ||k7  –— Œ y­wrE   rÃ   )r9   ÚoÚns      r<   r=   z*_coo_base._broadcast_to.<locals>.<genexpr>m  s'   è ø€ ÐEÑ/D¡t q¨!��Q‘Ò!˜1 ™6Ó!Ñ/Dùrœ   zcurrent shape z- cannot be broadcast to new shape {new_shape}r/   r   r	   r   r4   rv   )rf   rL   rA   rd   rZ   re   rË   r—   r   r`   rH   ra   r7   ÚtileÚrepeatr  rš   r_   r   )rn   r-  rL   Ú	old_shaperf   r;   r`   r–   r•   Ú
cum_repeatÚrepeat_countÚnew_dimrª   rš   s                 r<   r›  z_coo_base._broadcast_to^  s'  € Ø�:‰:˜Ò"Ù"&�4—9‘9“;Ð0¨DÐ0à—J‘Jˆ	ô ˆy‹>œC 	›NÒ*Üð 5ó 6ð 6ð œ˜I›¬¨Y«Ñ7Ñ8¼5ÀÓ;KÑKˆô ÑE¬s°5¸)Ô/DÓEÔEÜ˜~¨i¨[ð 9Bð Bó Cð Cð �|‰|˜EÓ"ˆä# D§K¡K¼¸I»ÔGˆ	Ø—‘ˆØ—9‘9ˆØ˜B˜C�[ˆ
Øˆ
à�‰9˜	 "™Ò%Ø$ R™=ˆLØ˜,Ñ&ˆJÜ—w‘w˜x¨Ó6ˆHÜ—i‘i¤§	¡	¨!¨\ÀÔ KÈTÏXÉXÓVˆGØ!˜ˆJä�rœS ›Z¨™\˜?¨BÖ/ˆAØ�Q‰x˜9 Q™<Ò'Ø(¨™|�Ø˜lÑ*�
Ü˜(“m�ô Ÿ7™7 8¨\Ó:�Ü"¤2§7¡7¨:°a¸±c°dÐ+;¸\Ó#JÓK�
ô Ÿ)™)¤B§I¡I¨a°ÀYÔ$OÐQTÓU�Ø%˜Z¨*Ñ4‘
ô Ÿ'™' &¨¡)¨ZÓ8�Ø%˜Z¨*Ñ4‘
ð! 0ô$ ˜( JÐ/°Ó;Ð;r}   c                 óž   — t        | |«      \  }}t        j                  |j                  d   df|¬«      }||z  j	                  |«      |d<   |S )Nr	   r4   .)r¨  r7   r&  rf   r—   )rn   r¢   Ú	res_dtyperß   ÚA2dr-  r&  s          r<   Ú_sum_ndz_coo_base._sum_nd•  sL   € ä'¨¨dÓ3‰ˆˆYÜ�w‰w˜Ÿ	™	 !™ aÐ(°	Ô:ˆà˜$‘J×'Ñ'¨	Ó2ˆˆC‰Øˆ
r}   c                 ó¼   — t        | |«      \  }}|j                  d||«      }t        j                  |j                  d   |«      }t        |j                  |f|«      S )Nr	   r   )r¨  Ú_min_or_max_axisr7   r�   r`   r   ra   )rn   r¢   Ú
min_or_maxÚexpliciträ  r-  ÚresÚunraveled_coordss           r<   Ú_min_or_max_axis_ndz_coo_base._min_or_max_axis_nd�  sX   € Ü'¨¨dÓ3‰ˆˆYØ×"Ñ" 1 j°(Ó;ˆÜ×+Ñ+¨C¯J©J°q©M¸9ÓEÐä˜#Ÿ(™(Ð$4Ð5°yÓAÐAr}   c                 ój   — t        | |«      \  }}|j                  d|||«      }|j                  |«      S )Nr	   )r¨  Ú_argminmax_axisr—   )rn   r¢   Ú	argminmaxÚcompareré  rä  r-  Úres_flats           r<   Ú_argminmax_axis_ndz_coo_base._argminmax_axis_nd¤  s9   € Ü'¨¨dÓ3‰ˆˆYØ×&Ñ& q¨)°W¸hÓGˆØ×Ñ 	Ó*Ð*r}   )NNFrN   )NF)ÚreturnN)NN)F)r   )T)r   )6Ú__name__Ú
__module__Ú__qualname__Ú_formatr_   r[   rX   Úpropertyr|   Úsetterry   r—   r   Ú__doc__r£   r¦   rm   r¿   rÔ   rä   rï   rõ   rê   rh   r  r  r  r   r  r#  rB  rZ  rK  r¥   r  rm  rt  rw  rz  r~  r‰  r‚  r�  r¦  r¤  r£  r¿  r»  rº  r‘  r›  rå  rì  rò  rÃ   r}   r<   r'   r'      s)  „ Ø€GÙ�a˜“€IðGÈTô GðR ñó ðð 	‡Z�ZñGó ðGð ñó ðð 	‡Z�Zñ4ó ð4ò!OðF —o‘o×-Ñ-€G„Oó;ð( —o‘o×-Ñ-€G„OóWð $×1Ñ1×9Ñ9€MÔòNó2?ð$  ×)Ñ)×1Ñ1€IÔó$ðL —^‘^×+Ñ+€F„Nó%ð2 —o‘o×-Ñ-€G„OóóB óD1ó6ð —M‘M×)Ñ)€E„MóDð, —M‘M×)Ñ)€E„Móð —M‘M×)Ñ)€E„Móð( $×,Ñ,×4Ñ4€HÔò$*óNRòRTòhn*ò`)*óV	)òò&>ò3ò0
ò
òòB'ò2[òz!-òFN/ò`Dò*,ó6nHò`Dò4Lò*(
óT5<ònòBó+r}   r'   c                 óò  — | j                   dk  rt        d«      ‚t        j                  | j                  dd «      }| j                  d   }| j                  d   }| j                  |||f«      }|j                  d   |j                  d   |j                  d   z  z   |j                  d   |j                  d   |j                  d   z  z   f}||z  ||z  f}t        | j                  t        |«      f|¬«      S )	zð
    Converts an N-D COO array into a 2-D COO array in block diagonal form.

    Parameters:
    self (coo_array): An N-Dimensional COO sparse array.

    Returns:
    coo_array: A 2-Dimensional COO sparse array in block diagonal form.
    r   zarray must have atleast dim=2Nrv   r   r	   r   rç   )
rk   rd   rÉ   rÊ   rf   r—   r`   r   ra   rZ   )rn   Ú
num_blocksÚn_colÚn_rowÚres_arrr•   r-  s          r<   rÏ  rÏ  ª  sê   € ð ‡y�y�‚{ÜÐ8Ó9Ð9Ü—‘˜4Ÿ:™: c r˜?Ó+€JØ�J‰J�r‰N€EØ�J‰J�r‰N€EØ�l‰l˜J¨¨uÐ5Ó6€Gà�‰�qÑ˜GŸN™N¨1Ñ-°·±¸aÑ0@Ñ@Ñ@Ø�‰�qÑ˜GŸN™N¨1Ñ-°·±¸aÑ0@Ñ@Ñ@ð€Jð
 ˜eÑ# Z°%Ñ%7Ð8€IÜ�d—i‘i¤ zÓ!2Ð3¸9ÔEÐEr}   c                 óx  — |d   |d   }}| j                   }| j                  | j                  }}t        j                  t        |«      | j                  ft        ¬«      }||z  |d<   ||z  |d<   ||z  }t        t        |«      dz
  dd«      D ]  }	||	   }
||
z  ||	<   ||
z  }Œ t        |t        |«      f|¬«      S )Nrv   r   r4   r¬   rç   )ra   r|   ry   r7   rø   rA   rš   r    r_   r   rZ   )rn   rf   rþ  rý  ra   r|   ry   r•   Útemp_block_idxrª   rÓ   s              r<   rÐ  rÐ  Ã  sÊ   € Ø˜‘9˜e B™iˆ5€Eð �9‰9€DØ�x‰x˜Ÿ™ˆ€Cô —‘œ3˜u›: t§x¡xÐ0¼Ô<€Jð ˜5‘[€Jˆr�NØ˜5‘[€Jˆr�Nð ˜E‘\€NÜ”3�u“: ‘> 2 rÖ*ˆØ�Q‰xˆØ&¨Ñ-ˆ
�1‰Ø'¨4Ñ/‰ð +ô �dœE *Ó-Ð.°eÔ<Ð<r}   c                 ó®  — | j                  «       } | j                  «        t        | j                  «      }| j                  j                  |d¬«      }| j                  }||k(  r||fS t        |«      t        |«      z
  }|dkD  r<dg|z  t        |«      z   }t        j                  |d   «      }t        |g|z  |z   «      }|dk  rAt        | «      D ]2  }|d   dk(  r|dd  }|dd  }Œ|d   dk(  r|d d }|d d }Œ)t        d«      ‚ d}	t        t        ||«      «      D ]�  \  }
\  }}||k(  rŒ|dk7  rt        d«      ‚t        |d   «      }t        j                  t        j                   |«      |«      ||
<   t        |«      D ]$  \  }}||
k(  rŒt        j"                  ||«      ||<   Œ& |	|z  }	Œ‘ t        j"                  |j%                  «       |	«      }||fS )NFrO   r   r	   r   zshape mismatch in assignment)rh   r¥   r*  r`   ra   rT   rf   rA   r7   Ú	zeroslikerZ   r_   rd   r°   rË   rÝ  r  rÜ  rÛ   )rî   r-  r5   rQ  rP  Úx_shapeÚlen_diffÚcoord_zerosr:   Ú
tot_expandrª   ÚnnÚnxÚx_nnzrM  rŒ   s                   r<   rI  rI  Ü  sã  € Ø	�‰‹	€AØ×ÑÔä�A—H‘H‹~€HØ�V‰V�]‰]˜5 uˆ]Ó-€FØ�g‰g€Gà�GÒØ�xÐÐô �9‹~¤ G£Ñ,€HØ�!‚|à�#˜‘.¤4¨£=Ñ0ˆÜ—l‘l 8¨A¡;Ó/ˆÜ˜+˜¨Ñ1°HÑ<Ó=ˆð �!‚|Ü˜�yÖ!ˆAØ�q‰z˜QŠØ! ! "˜+�Ø# A B˜<‘Ø˜‘ Ò!Ø! # 2˜,�Ø# C R˜=‘ä Ð!?Ó@Ð@ð "ð €JÜ ¤ Y°Ó!8Ö9‰ˆ‰8ˆB�Ø�Š8ØØ�Š7ÜÐ;Ó<Ð<Ü�H˜Q‘KÓ ˆÜ—i‘i¤§	¡	¨"£¨uÓ5ˆ�‰Ü˜xÖ(‰EˆAˆrØ�AŠvØÜŸ'™' " b›/ˆH�QŠKð )ð 	�bÑ‰
ð :ô �W‰W�V—\‘\“^ ZÓ0€FØ�8ÐÐr}   c                 ó$  — | j                   |k7  r$t        j                  | j                  «       |«      } |dk(  r@t	        t        j
                  dg«      gt        |«      z  «      }| j                  «       }||fS | j                  «       }| |   }||fS )NrÃ   r   )	rf   r7   rL  ÚsqueezerZ   r8   rA   rÛ   rl   )rî   r-  rQ  rP  s       r<   rJ  rJ    sƒ   € Ø‡w�w�)ÒÜ�O‰O˜AŸI™I›K¨Ó3ˆà�B‚Üœ"Ÿ(™( A 3›-˜¬3¨y«>Ñ9Ó:ˆØ—‘“ˆð �8ÐÐð —9‘9“;ˆØ�8‘ˆØ�8ÐÐr}   c                 óh  ‡ ‡— t        |t        «      rL|dk  s|t        ‰ ‰«      kD  rt        d«      ‚t	        t        ‰ |z
  ‰ «      «      }t	        t        |«      «      }n•t        |t        t        z  «      rst        |«      dk7  rt        d«      ‚|\  }}t        |«      t        |«      k7  rt        d«      ‚t        ˆ fd„|D «       «      st        ˆfd„|D «       «      rt        d«      ‚t        d	«      ‚|D �cg c]  }|d
k  r|‰ z   n|‘Œ }}|D �cg c]  }|d
k  r|‰z   n|‘Œ }}||fS c c}w c c}w )Nr	   z.axes integer is out of bounds for input arraysr   z%axes must be a tuple/list of length 2z,axes lists/tuples must be of the same lengthc              3   ó8   •K  — | ]  }|‰k\  xs |‰ k  –— Œ y ­wrN   rÃ   )r9   r·  Úndim_as     €r<   r=   z _process_axes.<locals>.<genexpr>&  ó$   øè ø€ Ð=±f°ˆr�V‰|Ò+˜r V G™|Ó+±fùó   ƒc              3   ó8   •K  — | ]  }|‰k\  xs |‰ k  –— Œ y ­wrN   rÃ   )r9   r¸  Úndim_bs     €r<   r=   z _process_axes.<locals>.<genexpr>'  r  r  z/axes indices are out of bounds for input arraysz3axes must be an integer or a tuple/list of integersr   )
rY   r    r³   rd   r*  r_   rZ   rA   re   rc   )r  r  r¼   Úaxes_aÚaxes_br¢   s   ``    r<   r¹  r¹    s(  ù€ Ü�$œÔØ�!Š8�tœc &¨&Ó1Ò1ÜÐMÓNÐNÜ”e˜F T™M¨6Ó2Ó3ˆÜ”e˜D“kÓ"‰Ü	�Dœ%¤$™,Ô	'Üˆt‹9˜Š>ÜÐDÓEÐEØ‰ˆ�Üˆv‹;œ#˜f›+Ò%ÜÐKÓLÐLÜÓ=±fÓ=Ô=ÜÓ=±fÓ=Ô=ÜÐNÓOÐOäÐMÓNÐNá>DÓE¹f°d˜t ašxˆd�VŠm¨TÑ1¸f€FÐEÙ>DÓE¹f°d˜t ašxˆd�VŠm¨TÑ1¸f€FÐEØ�6ˆ>Ðùò FùÚEs   Ã8D*ÄD/c                 ó  ‡ ‡— t        ˆ fd„‰D «       «      }t        ˆ fd„‰D «       «      }t        ||«      }t        ‰ j                  «      }t        ˆfd„t	        |«      D «       «      }|rct        ˆ fd„|D «       «      }t        ˆ fd„|D «       «      }t        ||«      }	|	|f}
t        j                  |«      t        j                  |«      f}n|f}
t        j                  |«      f}d}t        ‰ j                  |
f|¬«      }||fS )Nc              3   ó<   •K  — | ]  }‰j                   |   –— Œ y ­wrN   rƒ   ©r9   rª   r(   s     €r<   r=   z!_convert_to_2d.<locals>.<genexpr>2  s   øè ø€ Ð4©t¨!˜Ÿ
™
 1�©tùr¸   c              3   ó<   •K  — | ]  }‰j                   |   –— Œ y ­wrN   rç   r  s     €r<   r=   z!_convert_to_2d.<locals>.<genexpr>3  s   øè ø€ Ð2©T¨�s—y‘y •|©Tùr¸   c              3   ó,   •K  — | ]  }|‰vsŒ|–— Œ y ­wrN   rÃ   )r9   rª   r¢   s     €r<   r=   z!_convert_to_2d.<locals>.<genexpr>7  s   øè ø€ Ð=¡˜1¨q¸ª}”Q¡ùs   ƒ	�c              3   ó<   •K  — | ]  }‰j                   |   –— Œ y ­wrN   rƒ   r  s     €r<   r=   z!_convert_to_2d.<locals>.<genexpr>9  s   øè ø€ Ð@±x°! §
¡
¨1¥±xùr¸   c              3   ó<   •K  — | ]  }‰j                   |   –— Œ y ­wrN   rç   r  s     €r<   r=   z!_convert_to_2d.<locals>.<genexpr>:  s   øè ø€ Ð>±X°˜sŸy™y¨�|±Xùr¸   rÃ   rç   )	rZ   rŽ   rA   r`   r_   rÉ   rÊ   r   ra   )r(   r¢   Úaxis_coordsÚ
axis_shapeÚ
axis_ravelrk   Únon_axisÚnon_axis_coordsÚnon_axis_shapeÚnon_axis_ravelÚ	coords_2dÚshape_2dÚnew_coos   ``           r<   r¨  r¨  1  sâ   ù€ ÜÓ4©tÓ4Ó4€KÜÓ2©TÓ2Ó2€JÜ˜{¨JÓ7€Jäˆs�z‰z‹?€DÜÓ=¤ d¤Ó=Ó=€HÙÜÓ@±xÓ@Ó@ˆÜÓ>±XÓ>Ó>ˆÜ& ¸ÓGˆØ# ZÐ0ˆ	Ü—I‘I˜nÓ-¬t¯y©y¸Ó/DÐE‰à�Mˆ	Ü—I‘I˜jÓ)Ð+ˆØˆä˜Ÿ™ 9Ð-°XÔ>€GØ�NÐ"Ð"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   r‰   r/   r4   ÚFz'order' must be 'C' or 'F'r‡   )rA   rH   r   r7   r‹  rd   Úravel_multi_index)	r`   rf   rˆ   ÚnrowsÚncolsr|   ry   r0   r;   s	            r<   rŽ   rŽ   G  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Ô;Ð;r}   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
    )rY   r   )rî   s    r<   r   r   \  s   € ô. �aœÓ$Ð$r}   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Ã   r}   r<   r   r   w  s   „ òkr}   r   c                   ó"   — e Zd Zd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 )Nr`   r|   ry   )rH  Ú__dict__Úupdate)rn   Ústates     r<   Ú__setstate__zcoo_matrix.__setstate__W  s>   € Ø˜5Ñ ð  %Ÿy™y¨Ó/°·±¸5Ó1AÐBˆE�(‰OØ�‰×Ñ˜UÕ#r}   c                 ó   — t        d«      ‚)Nz('coo_matrix' object is not subscriptable©rc   )rn   r,  s     r<   rB  zcoo_matrix.__getitem__^  s   € ÜÐBÓCÐCr}   c                 ó   — t        d«      ‚)Nz4'coo_matrix' object does not support item assignmentr5  )rn   r,  rî   s      r<   rZ  zcoo_matrix.__setitem__a  s   € ÜÐNÓOÐOr}   N)rô  rõ  rö  rú  r3  rB  rZ  rÃ   r}   r<   r   r   æ  s   „ ñnò`$òDóPr}   r   )r‰   )8rú  Ú__docformat__Ú__all__rÉ   Úwarningsr   Únumpyr7   Ú
_lib._utilr   Ú_matrixr
   Ú_sparsetoolsr   r   r   r   r   r   r   Ú_baser   r   r   r   Ú_datar   r   Ú_sputilsr   r   r   r   r   r   r   r   r    r!   r"   r#   Ú_indexr$   r%   rF   r'   rÏ  rÐ  rI  rJ  r¹  r¨  rŽ   r   r   r   rÃ   r}   r<   Ú<module>rB     s¶   ðÙ 8à%€â
7€ã Ý ã å 'Ý ÷0÷ 0ñ 0÷ GÓ Fß .÷+÷ +÷ +ó +÷ 9ã ôK+�˜mô K+ò\,Fò2=ò2.òb
òò.#ó,<ò*%ô6l�	˜7ô lô^|P�˜9õ |Pr}   