
    e!hY                         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mZmZ dd	lmZ dd
lmZmZmZmZmZmZmZmZ  G d deee      Zd Z G d dee      Z G d de	e      Zy)zDictionary Of Keys based matrixzrestructuredtext en)	dok_array
dok_matrixisspmatrix_dok    N)warn   )spmatrix)_spbasesparrayissparse)
IndexMixin)isdensegetdtypeisshape	isintlikeisscalarlikeupcastupcast_scalarcheck_shapec                   H    e Zd ZdZdZd=dddZd Zd>dZd>dZe	j                  j                  e_
        e	j                  j                  e_
        d	 Zd
 Zd>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 Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1d0 Z2d1 Z3d2 Z4d@ fd3	Z5dAd4Z6e	jl                  j                  e6_
        d5 Z7d6 Z8e	jp                  j                  e8_
        e9dBd7       Z:dCd8Z;e	jv                  j                  e;_
        dCd9Z<e	jx                  j                  e<_
        dCd:Z=e	jz                  j                  e=_
        d; Z>e	j|                  j                  e>_
        dDd<Z? xZ@S )E	_dok_basedok)r      Nmaxprintc                   t        j                  | ||       t        |t              rQt	        || j
                        r:t        || j
                        | _        i | _        t        |t              | _        y t        |      r|j                  | j                  k(  r|r|j                         n|}n|j                         }||j!                  |d      }|j                  | _        t        |j"                  | j
                        | _        t        |j                        | _        y 	 t%        j&                  |      }|j,                  dkD  rt/        d|j,                   d	      |j,                  d
k(  rX||j!                  |      }t1        |      D ci c]  \  }}|dk7  s|| c}}| _        t        |j                        | _        nM| j3                  |||      j                         }	|	j                  | _        t        |	j                        | _        t        |j"                  | j
                        | _        y # t(        $ r}t+        d      |d }~ww xY wc c}}w )Nr   allow_nd)defaultFcopyzInvalid input format.r   zDOK arrays don't yet support zD input.r   r   shapedtype)r	   __init__
isinstancetupler   	_allow_ndr   _shape_dictr   floatr#   r   formatr    todokastyper"   npasarray	Exception	TypeErrorndim
ValueError	enumerate_coo_container)
selfarg1r"   r#   r    r   eivds
             Y/var/www/html/diagnosisapp-backend/venv/lib/python3.12/site-packages/scipy/sparse/_dok.pyr$   z_dok_base.__init__   s   th7dE"wtdnn'M%dT^^DDKDJ!%7DJd^{{dkk)&*tyy{zz| {{5u{5DJ%djj4>>JDK!$**-DJ@zz$' yy1} #@8!TUUyyA~$;;u-D/8Itq!!q&adI
%djj1
''E'GMMOWW
%agg.
%djj4>>JDK  @ 78a?@ Js$   +I I &I 	IIIc                     t        d      )Nz2Direct update to DOK sparse format is not allowed.)NotImplementedError)r6   vals     r<   updatez_dok_base.update=   s    !"VWW    c                 F    |t        d      t        | j                        S )Nz7_getnnz over an axis is not implemented for DOK format.)r>   lenr)   r6   axiss     r<   _getnnzz_dok_base._getnnzA   s(    %I  4::rA   c                 \    |t        d      t        d | j                         D              S )Nz=count_nonzero over an axis is not implemented for DOK format.c              3   &   K   | ]	  }|d k7    ywr   N ).0xs     r<   	<genexpr>z*_dok_base.count_nonzero.<locals>.<genexpr>M   s     1a161s   )r>   sumvaluesrD   s     r<   count_nonzeroz_dok_base.count_nonzeroH   s1    %O  14;;=111rA   c                 ,    t        | j                        S N)rC   r)   r6   s    r<   __len__z_dok_base.__len__R   s    4::rA   c                     || j                   v S rR   r)   r6   keys     r<   __contains__z_dok_base.__contains__U   s    djj  rA   c                :    | j                   j                  ||      S rR   )r)   
setdefault)r6   rX   r   s      r<   r[   z_dok_base.setdefaultX   s    zz$$S'22rA   c                    | j                   |= y rR   rV   rW   s     r<   __delitem__z_dok_base.__delitem__[   s    JJsOrA   c                 6    | j                   j                         S rR   )r)   clearrS   s    r<   r_   z_dok_base.clear^       zz!!rA   c                4     | j                   j                  | S rR   )r)   pop)r6   argss     r<   rb   z_dok_base.popa   s    tzz~~t$$rA   c                     t        d      )Nz*reversed is not defined for dok_array type)r1   rS   s    r<   __reversed__z_dok_base.__reversed__d   s    DEErA   c                 x    t        |       j                   dt        |      j                   }t        d|       Nz and z unsupported operand type for |: type__name__r1   r6   other
type_namess      r<   __or__z_dok_base.__or__g   ;    T
++,E$u+2F2F1GH
::,GHHrA   c                 x    t        |       j                   dt        |      j                   }t        d|       rg   rh   rk   s      r<   __ror__z_dok_base.__ror__k   ro   rA   c                 x    t        |       j                   dt        |      j                   }t        d|       rg   rh   rk   s      r<   __ior__z_dok_base.__ior__o   ro   rA   c                 6    | j                   j                         S rR   )r)   popitemrS   s    r<   ru   z_dok_base.popitems   s    zz!!##rA   c                 6    | j                   j                         S rR   )r)   itemsrS   s    r<   rw   z_dok_base.itemsv   r`   rA   c                 6    | j                   j                         S rR   )r)   keysrS   s    r<   ry   z_dok_base.keysy   s    zz  rA   c                 6    | j                   j                         S rR   )r)   rO   rS   s    r<   rO   z_dok_base.values|   s    zz  ""rA   c                 N   || j                   v r| j                   |   S t        |      r| j                  dk(  r|f}| j                  t        |      k7  rt	        d| d      	 |D ]  }t        |      rJ  	 t        d t        || j                        D              }t        d t        || j                        D              rt	        d      | j                  dk(  r|d	   }| j                   j                  ||      S # t
        t        t        f$ r}t	        d      |d}~ww xY w)
z>This provides dict.get method functionality with type checkingr   zIndex z! length needs to match self.shapez%Index must be or consist of integers.Nc              3   :   K   | ]  \  }}|d k  r||z   n|  ywrI   rJ   rK   r9   Ms      r<   rM   z _dok_base.get.<locals>.<genexpr>   s#     KdaQUAE)K   c              3   :   K   | ]  \  }}|d k  xs ||k\    ywrI   rJ   r}   s      r<   rM   z _dok_base.get.<locals>.<genexpr>   s"     @41aq1uQ@r   zIndex out of bounds.r   )r)   r   r2   rC   
IndexErrorAssertionErrorr1   r3   r&   zipr"   anyget)r6   rX   r   r9   r8   s        r<   r   z_dok_base.get   s   $**::c?"S>dii1n&C99C vcU*KLMM	M $ |#|$ Kc#tzz6JKK@3sDJJ+?@@34499>a&Czz~~c7++ 	:6 	MDE1L	Ms   #C? 4C? ?D$DD$c                 l    | j                   j                  || j                  j                  d            S Nr   r)   r   r#   ri   )r6   idxs     r<   _get_intz_dok_base._get_int   s$    zz~~c4::??1#566rA   c                 ~    t        |j                  | j                  d          }| j                  t	        |            S r   )rangeindicesr"   
_get_arraylist)r6   r   i_ranges      r<   
_get_slicez_dok_base._get_slice   s0    TZZ]34tG}--rA   c                 R   t        j                  |      }|j                  dk(  r_| j                  j	                  t        |      | j                  j                  d            }t        j                  || j                        S | j                  |j                  | j                        }|j                         D cg c]  }| j                  j	                  |d        }}|rt        |j                        dk(  r't        |      D ]  \  }}|s	||j                  |<    |S t        j                  t        j                  t        |            |j                        }t        |      dk(  r|d   nt!        | }t!        ||d      D ]  \  }}|s	||j                  |<    |S c c}w )Nr   )styper#   r   T)strict)r.   r/   r2   r)   r   intr#   ri   array_dok_containerr"   ravelrC   r4   unravel_indexaranger   )r6   r   r?   new_dokr9   dok_valsr:   new_idxs           r<   r   z_dok_base._get_array   sT   jjo88q=**..S4::??1+=>C88Ctzz22%%ciitzz%B25))+>QDJJNN1a(>>399~"%h/ -DAq+,a(-  **299S]+CSYYO(+G(9'!*sG}$? -DAq+,a(-  ?s   =#F$c                 p    | j                   j                  ||f| j                  j                  d            S r   r   r6   rowcols      r<   _get_intXintz_dok_base._get_intXint   s(    zz~~sCj$**//!*<==rA   c                 @    | j                  t        ||dz         |      S Nr   _get_sliceXsliceslicer   s      r<   _get_intXslicez_dok_base._get_intXslice   s     $$U3a%8#>>rA   c                 @    | j                  |t        ||dz               S r   r   r   s      r<   _get_sliceXintz_dok_base._get_sliceXint   s     $$S%S1W*=>>rA   c                    |j                  | j                  d         \  }}}|j                  | j                  d         \  }}}t        |||      }	t        |||      }
t        |	      t        |
      f}t        |       d|d   z  |d   z  k\  r| j	                  |	|
      S | j                  || j                        }| j                         D ]  }t        t        |d         |z
  |      \  }}|dk7  s|dk  s||d   k\  r4t        t        |d         |z
  |      \  }}|dk7  s|dk  s||d   k\  re| j                  |   |j                  ||f<    |S )Nr   r   r   r   )r   r"   r   rC   _get_columnXarrayr   r#   ry   divmodr   r)   )r6   r   r   	row_startrow_stoprow_step	col_startcol_stopcol_step	row_range	col_ranger"   newdokrX   r9   rijrjs                     r<   r   z_dok_base._get_sliceXslice   sY   (+DJJqM(B%	8X(+DJJqM(B%	8X)Xx8	)Xx8	YY0 t9E!HuQx//)))Y??$$U$**$=99; 	1C3s1v;2H=EArQw!a%1a=3s1v;2H=EArQw!a%1a=!%CFLLA	1 rA   c                 D    | j                  |g|j                               S rR   )r   r   r   s      r<   _get_intXarrayz_dok_base._get_intXarray   s    %%seSYY[99rA   c                     | j                  |j                         |g      }|j                  dkD  r|j                  |j                        S |S r   )r   r   r2   reshaper"   )r6   r   r   ress       r<   _get_arrayXintz_dok_base._get_arrayXint   s?    $$SYY[3%888a<;;syy))
rA   c                     t        t        |j                  | j                  d                }| j	                  ||      S r   r   r   r   r"   r   r   s      r<   _get_sliceXarrayz_dok_base._get_sliceXarray   5    5#++djjm456%%c3//rA   c                     t        t        |j                  | j                  d                }| j	                  ||      S r   r   r   s      r<   _get_arrayXslicez_dok_base._get_arrayXslice   r   rA   c                    | j                  t        |      t        |      f| j                        }t        |      D ]J  \  }}t        |      D ]7  \  }}| j                  j                  ||fd      }|s'||j                  ||f<   9 L |S )Nr   r   )r   rC   r#   r4   r)   r   )	r6   r   r   r   r9   rr   cr:   s	            r<   r   z_dok_base._get_columnXarray   s    $$c#hC%9$LcN 	+DAq!# +1JJNNAq61-)*FLLA&+	+
 rA   c                    t        t        j                  t        j                  ||            \  }}| j	                  |j
                  | j                        }t        j                  t        |j
                  d         t        |j
                  d               D ]8  }| j                  j                  ||   ||   fd      }|s*||j                  |<   : |S )Nr   r   r   )mapr.   
atleast_2dbroadcast_arraysr   r"   r#   	itertoolsproductr   r)   r   )r6   r   r   r9   r   r   rX   r:   s           r<   _get_arrayXarrayz_dok_base._get_arrayXarray   s    2==""5"5c3"?@1$$QWWDJJ$?$$U1771:%6aggaj8IJ 	&C

##/3A$%S!	& rA   c                 `    |r|| j                   |<   y || j                   v r| j                   |= y y rR   rV   )r6   r   rL   s      r<   _set_intz_dok_base._set_int   s.    DJJsODJJ

3 rA   c                    |j                         }|j                         }t        |      t        |      k7  rHt        |      dk(  r/t        j                  t        |      |d   | j                        }nt        d      t        ||      D ]3  \  }}|r|| j                  |<   || j                  v s'| j                  |= 5 y )Nr   r   r   z*Need len(index)==len(data) or len(data)==1)r   rC   r.   fullr#   r3   r   r)   )r6   r   rL   idx_setx_setr9   r:   s          r<   
_set_arrayz_dok_base._set_array   s    ))+	w<3u:%5zQGeAhdjjIKLL' 	"DAq !

1djjJJqM		"rA   c                 h    ||f}|r|| j                   |<   y || j                   v r| j                   |= y y rR   rV   )r6   r   r   rL   rX   s        r<   _set_intXintz_dok_base._set_intXint  s7    CjDJJsODJJ

3 rA   c                    t        t        t        |j                                     }t        t        t        |j                                     }|j                         }| j                  j                  t        t        ||      |             t        j                  |dk(        d   D ],  }||   ||   f}| j                  |   dk(  s | j                  |= . y r   )	r   r   r   r   r)   r@   r   r.   nonzero)r6   r   r   rL   r9   rX   s         r<   _set_arrayXarrayz_dok_base._set_arrayXarray  s    3sCIIK()3sCIIK()GGI

#c#smQ/0AF#A& 	$Aq63q6"Czz#!#JJsO		$rA   c                 f   t        |      rt        | j                  |      }| j                  | j                  |      t        j                  | j                  D cg c]  }t        |       c} D ])  }| j                  j                  |d      |z   }|s%||<   + S t        |      rN|j                  | j                  k7  rt        d      t        | j                  |j                        }| j                  | j                  |      | j                  j                         _        |j                  dk(  r|j                         }ni|j!                         }| j"                  dk(  r$t%        |j&                  d   |j(                        }n&t%        t%        |j&                   |j(                        }t+        j,                  d      5  j                  j/                  fd|D               d d d        S t1        |      r| j3                         |z   S t4        S c c}w # 1 sw Y   S xY w)	Nr   r   z Matrix dimensions are not equal.r   r   ignore)overc              3   8   K   | ]  \  }}||   |z   f  y wrR   rJ   )rK   kr:   news      r<   rM   z$_dok_base.__add__.<locals>.<genexpr>8  s!      ETQ!SVaZ Es   )r   r   r#   r   r"   r   r   r   r)   r   r   r3   r   r    r+   rw   tocoor2   r   coordsdatar.   errstater@   r   todenseNotImplemented)r6   rl   	res_dtyper;   rX   aijo_itemsr   s          @r<   __add__z_dok_base.__add__   s   %djj%8I%%djj	%BC ((TZZ*H58*HI #jjnnS!,u4"CH#0 
) e_{{djj( !CDDtzz5;;7I%%djj	%BC

)CI||u$++-99>!%,,q/5::>G!#u||"4ejjAG(+ F		   EW EEF 
	 U^,,.5(C 
 "!/ +I$F 
s   H!%H&&H0c                     | |z   S rR   rJ   r6   rl   s     r<   __radd__z_dok_base.__radd__?  s    e|rA   c                     | j                   j                  dk(  rt        d      | j                  | j                  | j                         }|j
                  j                  d | j                         D               |S )Nbz2Negating a sparse boolean matrix is not supported.r   c              3   ,   K   | ]  \  }}|| f  y wrR   rJ   )rK   r   r:   s      r<   rM   z$_dok_base.__neg__.<locals>.<genexpr>H  s     :TQ!aR:s   )r#   kindr>   r   r"   r)   r@   rw   r6   r   s     r<   __neg__z_dok_base.__neg__B  sd    ::??c!%D  !!$**DJJ!?		:TZZ\::
rA   c                     t        | j                        }| j                  | j                  |      }|j                  j                  fd| j                         D               |S )Nr   c              3   2   K   | ]  \  }}||z  f  y wrR   rJ   rK   r   r:   rl   s      r<   rM   z(_dok_base._mul_scalar.<locals>.<genexpr>O  s     BTQ1a%i.B   )r   r#   r   r"   r)   r@   rw   r6   rl   r   r   s    `  r<   _mul_scalarz_dok_base._mul_scalarK  sO    !$**e4	!!$**I!>		BTZZ\BC
rA   c                     t         j                  j                        } j                  dk(  rt              rzj                  dk(  r" j                         j                         z  }n. j                         j                         j                  d   z  } |t         fd|D                    S t              r( |t        fd j                         D                    S t        S t        j                   j                  d   |      } j                         D ]  \  \  }}}||xx   ||   z  z  cc<    |S )Nr   r   r   c              3   \   K   | ]#  }j                   |   j                   |   z   % y wrR   rV   )rK   r   rl   r6   s     r<   rM   z+_dok_base._matmul_vector.<locals>.<genexpr>\  s&     $RTZZ]U[[^%C$Rs   ),c              3   4   K   | ]  \  }}|   |z    y wrR   rJ   r   s      r<   rM   z+_dok_base._matmul_vector.<locals>.<genexpr>^  s     $KdaU1X\$K   r   )r   r#   r2   r   r+   ry   r   r   rN   r   rw   r   r.   zerosr"   )r6   rl   r   ry   resultr9   r   r:   s   ``      r<   _matmul_vectorz_dok_base._matmul_vectorR  s    4::u{{3	 99><<5(99;5D99;)=)=a)@@D $RT$R!RSS $Kdjjl$K!KLL%% $**Q-y9 	&IFQA1IU1X%I	&rA   c                    t        | j                  j                        }| j                  dk(  r,t        fd| j                  j                         D              S | j                  d   }j                  dk(  r|fn|j                  d   f}t        j                  ||      }| j                         D ]  \  \  }}}||xx   ||   z  z  cc<    |S )Nr   c              3   4   K   | ]  \  }}||   z    y wrR   rJ   )rK   r   r:   rl   s      r<   rM   z0_dok_base._matmul_multivector.<locals>.<genexpr>m  s     C1q58|Cr   r   r   )	r   r#   r2   rN   r)   rw   r"   r.   r   )	r6   rl   result_dtyper~   	new_shaper  r9   r   r:   s	    `       r<   _matmul_multivectorz_dok_base._matmul_multivectorh  s    djj%++699>C

0@0@0BCCC JJqM!JJ!OQD!U[[^1D	)<8 	&IFQA1IU1X%I	&rA   c                     t              r4| j                  j                  fd| j                         D               | S t        S )Nc              3   2   K   | ]  \  }}||z  f  y wrR   rJ   r   s      r<   rM   z%_dok_base.__imul__.<locals>.<genexpr>y       FAq!e)nFr   r   r)   r@   rw   r   r   s    `r<   __imul__z_dok_base.__imul__w  4    JJFFFKrA   c                    t              rgt        | j                        }| j                  | j                  |      }|j
                  j                  fd| j                         D               |S | j                         z  S )Nr   c              3   2   K   | ]  \  }}||z  f  y wrR   rJ   r   s      r<   rM   z(_dok_base.__truediv__.<locals>.<genexpr>  r
  r   )	r   r   r#   r   r"   r)   r@   rw   tocsrr   s    `  r<   __truediv__z_dok_base.__truediv__}  sh    %djj%8I%%djj	%BCIIFFGJzz|e##rA   c                     t              r4| j                  j                  fd| j                         D               | S t        S )Nc              3   2   K   | ]  \  }}||z  f  y wrR   rJ   r   s      r<   rM   z)_dok_base.__itruediv__.<locals>.<genexpr>  r
  r   r  r   s    `r<   __itruediv__z_dok_base.__itruediv__  r  rA   c                 ,    t         j                  |       S rR   )dict
__reduce__rS   s    r<   r  z_dok_base.__reduce__  s     t$$rA   c                 V    | j                   dk(  rt        | 	  |      S t        d      )Nr   z diagonal requires two dimensions)r2   superdiagonalr3   )r6   r   	__class__s     r<   r  z_dok_base.diagonal  s*    99>7#A&&;<<rA   c                 &   | j                   dk(  r| j                         S ||dk7  rt        d      | j                  \  }}| j	                  ||f| j
                  |      }|j                  j                  d | j                         D               |S )Nr   )r   r   zvSparse arrays/matrices do not support an 'axes' parameter because swapping dimensions is the only logical permutation.)r#   r    c              3   4   K   | ]  \  \  }}}||f|f  y wrR   rJ   )rK   leftrightr?   s       r<   rM   z&_dok_base.transpose.<locals>.<genexpr>  s"     V3E=D%#E4=#.Vs   )	r2   r    r3   r"   r   r#   r)   r@   rw   )r6   axesr    r~   Nr   s         r<   	transposez_dok_base.transpose  s    99>99;>  zz1!!1a&

!F		VVW
rA   c           	         d}t        |t        d       | j                  dk(  r1| j                         }|j                  j                         |_        |S | j                  \  }}| j                  ||f| j                        }| j                         D ci c]   \  \  }}}||ft        j                  |      " c}}}|_        |S c c}}}w )zDEPRECATED: Return the conjugate transpose.

        .. deprecated:: 1.14.0

            `conjtransp` is deprecated and will be removed in v1.16.0.
            Use ``.T.conj()`` instead.
        zS`conjtransp` is deprecated and will be removed in v1.16.0. Use `.T.conj()` instead.r   )
stacklevelr   r   )r   DeprecationWarningr2   r   r   	conjugater"   r   r#   rw   r.   conjr)   )r6   msgr   r~   r!  r  r  r?   s           r<   
conjtranspz_dok_base.conjtransp  s    .S$399>**,Cxx))+CHJzz1!!1a&

!;KO::<XX5G]dECeT]BGGCL0X	
 Ys   %Cc                     | j                  | j                  | j                        }|j                  j	                  | j                         |S Nr   )r   r"   r#   r)   r@   r   s     r<   r    z_dok_base.copy  s:    !!$**DJJ!?		$
rA   c                    t         j                  ||      }t        t        t	        |            t
              rt        d t        | D              }nt        |      dz   f} | |t        |            }||_	        |S )Nc              3   8   K   | ]  }t        |      d z     yw)r   N)max)rK   r   s     r<   rM   z%_dok_base.fromkeys.<locals>.<genexpr>  s     <3#c(Q,<s   r   r   )
r  fromkeysr%   nextiterr&   r   r.  ri   r)   )clsiterablevaluetmpr"   r  s         r<   r/  z_dok_base.fromkeys  sc    mmHe,d49ou-<#s)<<EX\OEU$u+.rA   c                    | j                   dk(  r'| j                  | j                  | j                        S | j	                  t        | j                              t        j                  | j                         | j                        }| j                  dkD  rt        | j                          n| j                         f}t        fd|D              }| j                  ||f| j                  | j                        }d|_        |S )	Nr   r   )maxvalr#   countr   c              3   N   K   | ]  }t        j                  |         yw)r8  N)r.   fromiter)rK   ix	idx_dtypennzs     r<   rM   z"_dok_base.tocoo.<locals>.<genexpr>  s!     Rrr{{2YcBBRs   "%r!   T)r>  r5   r"   r#   _get_index_dtyper.  r.   r;  rO   r2   r   ry   r&   has_canonical_format)r6   r    r   indsr   Ar=  r>  s         @@r<   r   z_dok_base.tocoo  s    hh!8&&tzz&DD))TZZ)A	{{4;;=

#F$(IIMsDIIK 		~RTRRvdjj

S!%rA   c                 *    |r| j                         S | S rR   r   r6   r    s     r<   r,   z_dok_base.todok  s    99;rA   c                 z    | j                   dk(  rt        d      | j                  d      j                  |      S )Nr   z%tocsr() not valid for 1d sparse arrayFr   )r2   r>   r   tocscrD  s     r<   rF  z_dok_base.tocsc  s8    99>%&MNNzzuz%+++66rA   c                    t        || j                        }t        |      t        | j                        k7  rt        | j
                  dk(  r:|d   }t        | j                        D ]  }||k\  s	| j                  |=  || _        y |\  }}| j                  \  }}||k  s||k  r;t        | j                               D ]  \  }}||k\  s||k\  s| j                  ||f= ! || _        y )Nr   r   )
r   r'   rC   r"   r>   r2   r   r)   r(   ry   )r6   r"   newNr9   newMr~   r!  r   s           r<   resizez_dok_base.resize  s    EDNN;u:TZZ(%%99>9D$**% &9

1&  DK
dzz1!8taxTYY[) )19T	

1a4() rA   c                 h   t        j                  |      }| j                  |k7  r{| j                  | j                  |      }t        j                  t        | j                  j                               |      }t        t        | j                  |            |_        |S |r| j                         S | S r+  )r.   r#   r   r"   r   r   r)   rO   r  r   r    )r6   r#   castingr    r  r   s         r<   r-   z_dok_base.astype  s    ::((5(AF88D!2!2!45UCDDJJ 56FLM99;rA   )NNFrR   )g        )r   )NF)r   )F)unsafeT)Arj   
__module____qualname___formatr'   r$   r@   rF   rP   r	   __doc__rT   rY   r[   r]   r_   rb   re   rn   rq   rs   ru   rw   ry   rO   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r"  r)  r    classmethodr/  r   r,   rF  rK  r-   __classcell__)r  s   @r<   r   r      s   GI%KT %KNX2 oo--GO#1199M!3"%FIII$"!#,*7.*>??.:00		 " 
$>,$%=
   ))11I,
 <<''DL  MM))EM
 MM))EM7
 MM))EM. ^^++FN	rA   r   c                 "    t        | t              S )a  Is `x` of dok_array type?

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

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

    Examples
    --------
    >>> from scipy.sparse import dok_array, dok_matrix, coo_matrix, isspmatrix_dok
    >>> isspmatrix_dok(dok_matrix([[5]]))
    True
    >>> isspmatrix_dok(dok_array([[5]]))
    False
    >>> isspmatrix_dok(coo_matrix([[5]]))
    False
    )r%   r   )rL   s    r<   r   r     s    . a$$rA   c                       e Zd ZdZy)r   a!  
    Dictionary Of Keys based sparse array.

    This is an efficient structure for constructing sparse
    arrays incrementally.

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

        dok_array(S)
            with another sparse array or matrix S (equivalent to S.todok())

        dok_array((M,N), [dtype])
            create the array with initial shape (M,N)
            dtype is optional, defaulting to dtype='d'

    Attributes
    ----------
    dtype : dtype
        Data type of the array
    shape : 2-tuple
        Shape of the array
    ndim : int
        Number of dimensions (this is always 2)
    nnz
        Number of nonzero elements
    size
    T

    Notes
    -----

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

    - Allows for efficient O(1) access of individual elements.
    - Duplicates are not allowed.
    - Can be efficiently converted to a coo_array once constructed.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.sparse import dok_array
    >>> S = dok_array((5, 5), dtype=np.float32)
    >>> for i in range(5):
    ...     for j in range(5):
    ...         S[i, j] = i + j    # Update element

    N)rj   rO  rP  rR  rJ   rA   r<   r   r   /  s    1rA   r   c                   H    e Zd ZdZd Zd Z eee      Zd Zd Z	d Z
d Zy	)
r   a/  
    Dictionary Of Keys based sparse matrix.

    This is an efficient structure for constructing sparse
    matrices incrementally.

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

        dok_matrix(S)
            with another sparse array or matrix S (equivalent to S.todok())

        dok_matrix((M,N), [dtype])
            create the matrix with initial shape (M,N)
            dtype is optional, defaulting to dtype='d'

    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
        Number of nonzero elements
    size
    T

    Notes
    -----

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

    - Allows for efficient O(1) access of individual elements.
    - Duplicates are not allowed.
    - Can be efficiently converted to a coo_matrix once constructed.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.sparse import dok_matrix
    >>> S = dok_matrix((5, 5), dtype=np.float32)
    >>> for i in range(5):
    ...     for j in range(5):
    ...         S[i, j] = i + j    # Update element

    c                 ~    | j                  |d      j                  | j                        }|j                  | _        y )NFr   )r   asformatr+   __dict__)r6   r"   
new_matrixs      r<   	set_shapezdok_matrix.set_shape  s0    \\%e\4==dkkJ
"++rA   c                     | j                   S )zGet shape of a sparse matrix.)r(   rS   s    r<   	get_shapezdok_matrix.get_shape  s    {{rA   )fgetfsetc                 6    | j                   j                         S rR   )r)   re   rS   s    r<   re   zdok_matrix.__reversed__  s    zz&&((rA   c                 r    t        |t              r| j                  |j                  z  S | j                  |z  S rR   r%   r   r)   r   s     r<   rn   zdok_matrix.__or__  .    eY'::++zzE!!rA   c                 r    t        |t              r| j                  |j                  z  S | j                  |z  S rR   rc  r   s     r<   rq   zdok_matrix.__ror__  rd  rA   c                     t        |t              r!| xj                  |j                  z  c_        | S | xj                  |z  c_        | S rR   rc  r   s     r<   rs   zdok_matrix.__ior__  s:    eY'JJ%++%J  JJ%JrA   N)rj   rO  rP  rR  r\  r^  propertyr"   re   rn   rq   rs   rJ   rA   r<   r   r   d  s4    1f, ))4E)"
"
rA   r   )rR  __docformat____all__r   warningsr   numpyr.   _matrixr   _baser	   r
   r   _indexr   _sputilsr   r   r   r   r   r   r   r   r  r   r   r   r   rJ   rA   r<   <module>rp     sm    %%
7     - - ; ; ;T D%62	7 2jP9 PrA   