
    Cpjl                         S r Sr/ SQrSSKrSSKrSSKJr  SSKJ	r	J
r
Jr  SSKJr  SS	KJrJrJrJrJrJrJrJr  \" 5       r " S
 S\	\\5      rS r " S S\\
5      r " S S\\5      rg)zDictionary Of Keys based matrixzrestructuredtext en)	dok_array
dok_matrixisspmatrix_dok    N   )spmatrix)_spbasesparrayissparse)
IndexMixin)isdensegetdtypeisshape	isintlikeisscalarlikeupcastupcast_scalarcheck_shapec                     ^  \ rS rSrSrSrS>SS.S jjrS rS?S jrS?S	 jr	\
R                  R                  \l        \
R                  R                  \	l        S
 rS rS?S jrS rS r\4S jrS rS rS rS rS rS rS rS rS@S jrS rS rS rS rS r S r!S r"S  r#S! r$S" r%S# r&S$ r'S% r(S& r)S' r*S( r+S) r,S* r-S+ r.S, r/S- r0S. r1S/ r2S0 r3S1 r4S2 r5S3 r6SAU 4S4 jjr7\
Rn                  R                  \7l        SBS5 jr8\
Rp                  R                  \8l        S6 r9\
Rr                  R                  \9l        \:SCS7 j5       r;SDS8 jr<\
Rx                  R                  \<l        SDS9 jr=\
Rz                  R                  \=l        SDS: jr>\
R|                  R                  \>l        S; r?\
R~                  R                  \?l        SES< jr@\
R                  R                  \@l        S=rAU =rB$ )F	_dok_base   dok)r      Nmaxprintc                   [         R                  " XUS9  [        U[        5      (       aK  [	        XR
                  S9(       a3  [        XR
                  S9U l        0 U l        [        U[        S9U l        g [        U5      (       a  UR                  U R                  :X  a  U(       a  UR                  5       OUnOUR                  5       nUb  UR!                  USS9nUR                  U l        [        UR"                  U R
                  S9U l        [        UR                  5      U l        g  [$        R&                  " U5      nUR,                  S:  a  [/        SUR,                   S	35      eUR,                  S
:X  a[  Ub  UR!                  USS9n[1        U5       VVs0 s H  u  pxUS:w  d  M  Xx_M     snnU l        [        UR                  5      U l        OIU R3                  XUS9R                  5       n	U	R                  U l        [        U	R                  5      U l        [        UR"                  U R
                  S9U l        g ! [(         a  n[+        S5      UeS nAff = fs  snnf )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
             M/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/scipy/sparse/_dok.pyr$   _dok_base.__init__   s   h7dE""wtnn'M%d^^DDKDJ!%7DJd^^{{dkk)&*tyy{zz| {{5u{5DJ%djj4>>JDK!$**-DJ@zz$' yy1} #@8!TUUyyA~$;;u5;9D/8Itq!q&dadI
%djj1
'''GMMOWW
%agg.
%djj4>>JDK  @ 78a?@ Js$   -I I"-I"
IIIc                 N   [        U[        5      (       a  UR                  5       nOUnU H  u  p4[        U5      (       a  U4O
[	        U5      n[        U5      U R                  :w  a  [        SU S35      e[        S [        XPR                  5       5       5      (       a  Mw  [        XPR                  5       HL  u  pg[        U5      (       d  [        SU 35      eUS:  a  [        SU S35      eXg:  d  M?  [        SU S	35      e   M     U R                  R                  U5        g
)a  Update values from a dict, sparse dok or iterable of 2-tuples like
``.items()``.

Parameters
----------
val : dict, dok_array, iterable of 2-tuples
    The values to update in the dok_array. If a dict or dok_array is
    provided, the keys and values will be taken from it. If an iterable
    of 2-tuples is provided, each tuple should contain a key and a value.
    Keys of the input must be sequences of nonnegative integers less than
    the shape for each axis.
Index ! length needs to match self.shapec              3   t   #    U  H.  u  p[        U5      =(       a    S Us=:*  =(       a    U:  Os  v   M0     g7fr   N)r   ).0idxmax_idxs      r<   	<genexpr>#_dok_base.update.<locals>.<genexpr>U   s2      $:LC #51#5#5g#55$:s   68z&integer keys required for update. Got r   znegative index z not allowed in updatezindex z is too large for self.shapeN)r%   dictitemsr   r&   lenr2   
IndexErrorallzipr"   r)   update)r6   valinputskeyvalueindexrD   rE   s           r<   rN   _dok_base.update?   s	    c4  YY[FF JC'nnSF%*E5zTYY& 6#.O!PQQ $'zz$:  
 %(zz$:LC$S>>(+QRUQV)WXXQw(?3%?U)VWW~(6#6R)STT %; !" 	

&!    c                 H    Ub  [        S5      e[        U R                  5      $ )Nz7_getnnz over an axis is not implemented for DOK format.)NotImplementedErrorrJ   r)   r6   axiss     r<   _getnnz_dok_base._getnnzd   s(    %I  4::rU   c                     Ub  U R                  5       R                  US9$ [        S U R                  5        5       5      $ )N)rY   c              3   *   #    U  H	  oS :g  v   M     g7frB    )rC   xs     r<   rF   *_dok_base.count_nonzero.<locals>.<genexpr>n   s     1=a6=s   )tocoocount_nonzerosumvaluesrX   s     r<   rb   _dok_base.count_nonzerok   s9    ::<--4-8814;;=111rU   c                 ,    [        U R                  5      $ N)rJ   r)   r6   s    r<   __len___dok_base.__len__s   s    4::rU   c                     XR                   ;   $ rg   r)   r6   rQ   s     r<   __contains___dok_base.__contains__v   s    jj  rU   c                8    U R                   R                  X5      $ )aQ  Insert key with a value of default if key is not in the dictionary.

Parameters
----------
key : int or tuple of int
    The key to look for in the dok_array.
default : optional
    The value to insert if `key` is not found. Default is None.

Returns
-------
scalar
    The value for `key` if `key` is in the dictionary, else `default`.
)r)   
setdefaultr6   rQ   r   s      r<   rq   _dok_base.setdefaulty   s     zz$$S22rU   c                    U R                   U	 g rg   rl   rm   s     r<   __delitem___dok_base.__delitem__   s    JJsOrU   c                 8    U R                   R                  5         g)z$Remove all items from the dok_array.N)r)   clearrh   s    r<   rx   _dok_base.clear   s    

rU   c                    U[         L a  U R                  R                  U5      $ U R                  R                  X5      $ )a  Remove specified key and return the corresponding value.

Parameters
----------
key : tuple
    The key to remove from the dok_array.
default : optional
    The value to return if `key` is not found. If not provided and
    `key` is not found, a KeyError is raised.

Returns
-------
scalar
    The value associated with the removed key.

Raises
------
KeyError
    If the key is not found and default is not provided.
)_NoValuer)   poprr   s      r<   r|   _dok_base.pop   s2    * h::>>#&&::>>#//rU   c                     [        S5      e)Nz*reversed is not defined for dok_array type)r1   rh   s    r<   __reversed___dok_base.__reversed__   s    DEErU   c                 x    [        U 5      R                   S[        U5      R                   3n[        SU 35      eNz and z unsupported operand type for |: type__name__r1   r6   other
type_namess      r<   __or___dok_base.__or__   ;    T
++,E$u+2F2F1GH
::,GHHrU   c                 x    [        U 5      R                   S[        U5      R                   3n[        SU 35      er   r   r   s      r<   __ror___dok_base.__ror__   r   rU   c                 x    [        U 5      R                   S[        U5      R                   3n[        SU 35      er   r   r   s      r<   __ior___dok_base.__ior__   r   rU   c                 6    U R                   R                  5       $ )a  
Remove and return a (key, value) pair as a 2-tuple, returned in LIFO (last-in,
first-out) order.

Returns
-------
key : tuple
    The key of the removed item.
value : scalar
    The value of the removed item.

Raises
------
KeyError
    If the dict is empty.
)r)   popitemrh   s    r<   r   _dok_base.popitem   s    " zz!!##rU   c                 6    U R                   R                  5       $ )z
Return a set-like object providing a view on the array's items.

Returns
-------
dict_items
    A view object displaying a list of a array's key-value tuple pairs.
)r)   rI   rh   s    r<   rI   _dok_base.items   s     zz!!rU   c                 6    U R                   R                  5       $ )z
Return a set-like object providing a view on the dict's keys.

Returns
-------
dict_keys
    A view object displaying a list of all the keys in the dictionary.
)r)   keysrh   s    r<   r   _dok_base.keys   s     zz  rU   c                 6    U R                   R                  5       $ )z
Return an object providing a view on the dict's values.

Returns
-------
dict_values
    A view object displaying a list of all the values in the dictionary.
)r)   rd   rh   s    r<   rd   _dok_base.values   s     zz  ""rU   c                 r   XR                   ;   a  U R                   U   $ [        U5      (       a  U R                  S:X  a  U4nU R                  [        U5      :w  a  [	        SU S35      e U H  n[        U5      (       a  M   e   [        S [        XR                  5       5       5      n[        S [        XR                  5       5       5      (       a  [	        S5      eU R                  S:X  a  US	   nU R                   R                  X5      $ ! [
        [        [        4 a  n[	        S5      UeSnAff = f)
aK  This provides dict.get method functionality with type checking.

Parameters
----------
key : int or tuple of int
    The key to look for in the dok_array.
default : optional
    The value to return if `key` is not found. Default is 0.0.

Returns
-------
value
    The value associated with `key` if it exists, otherwise `default`.
r   r?   r@   z%Index must be or consist of integers.Nc              3   >   #    U  H  u  pUS :  a  X-   OUv   M     g7frB   r^   rC   r9   Ms      r<   rF    _dok_base.get.<locals>.<genexpr>  s!     K6JdaQUAE)6J   c              3   F   #    U  H  u  pUS :  =(       d    X:  v   M     g7frB   r^   r   s      r<   rF   r   	  s      @+?41q1u+?s   !zIndex out of bounds.r   )r)   r   r2   rJ   rK   AssertionErrorr1   r3   r&   rM   r"   anyget)r6   rQ   r   r9   r8   s        r<   r   _dok_base.get   s
    **::c?"S>>dii1n&C99C vcU*KLMM	M ||#|  Kc#zz6JKK@3sJJ+?@@@34499>a&Czz~~c++ 	:6 	MDE1L	Ms   +D D D6%D11D6c                 j    U R                   R                  XR                  R                  S5      5      $ Nr   r)   r   r#   r   )r6   rD   s     r<   _get_int_dok_base._get_int  s"    zz~~c::??1#566rU   c                 ~    [        UR                  U R                  S   5      6 nU R                  [	        U5      5      $ r   )rangeindicesr"   
_get_arraylist)r6   rD   i_ranges      r<   
_get_slice_dok_base._get_slice  s0    TZZ]34tG}--rU   c                 p   [         R                  " U5      nUR                  S:X  a\  U R                  R	                  [        U5      U R                  R                  S5      5      n[         R                  " X R                  S9$ U R                  UR                  U R                  S9nUR                  5        Vs/ s H  o@R                  R	                  US5      PM      nnU(       a  [        UR                  5      S:X  a-  [        U5       H  u  pFU(       d  M  XcR                  U'   M     U$ [         R                  " [         R                  " [        U5      5      UR                  5      n[        U5      S:X  a  US   O[!        U6 n[!        XuSS9 H  u  pFU(       d  M  XcR                  U'   M     U$ s  snf )Nr   )styper#   r   T)strict)r.   r/   r2   r)   r   intr#   r   array_dok_containerr"   ravelrJ   r4   unravel_indexarangerM   )r6   rD   rO   new_dokr9   dok_valsr:   new_idxs           r<   r   _dok_base._get_array  sB   jjo88q=**..S4::??1+=>C88Czz22%%ciitzz%B25))+>+QJJNN1a(+>399~"%h/DAq+,a( 0  **299S]+CSYYO(+G(9'!*sG}$?DAq+,a( @  ?s   9%F3c                 n    U R                   R                  X4U R                  R                  S5      5      $ r   r   r6   rowcols      r<   _get_intXint_dok_base._get_intXint,  s&    zz~~sj$**//!*<==rU   c                 >    U R                  [        XS-   5      U5      $ Nr   _get_sliceXsliceslicer   s      r<   _get_intXslice_dok_base._get_intXslice/  s    $$U3a%8#>>rU   c                 >    U R                  U[        X"S-   5      5      $ r   r   r   s      r<   _get_sliceXint_dok_base._get_sliceXint2  s    $$S%1W*=>>rU   c                    UR                  U R                  S   5      u  p4nUR                  U R                  S   5      u  pgn[        X4U5      n	[        XgU5      n
[        U	5      [        U
5      4n[        U 5      SUS   -  US   -  :  a  U R	                  X5      $ U R                  XR                  S9nU R                  5        H  n[        [        US   5      U-
  U5      u  pUS:w  d  US:  d  XS   :  a  M6  [        [        US   5      U-
  U5      u  nnUS:w  d  US:  d	  UUS   :  a  Mk  U R                  U   UR                  UU4'   M     U$ )Nr   r   r   r   )r   r"   r   rJ   _get_columnXarrayr   r#   r   divmodr   r)   )r6   r   r   	row_startrow_stoprow_step	col_startcol_stopcol_step	row_range	col_ranger"   newdokrQ   r9   rijrjs                     r<   r   _dok_base._get_sliceXslice5  sD   (+DJJqM(B%	X(+DJJqM(B%	X)x8	)x8	YY0 t9E!HuQx//)))??$$U**$=99;C3s1v;2H=EAQw!a%1a=3s1v;2H=EArQw!a%1a=!%CFLLA  rU   c                 D    U R                  U/UR                  5       5      $ rg   )r   r   r   s      r<   _get_intXarray_dok_base._get_intXarrayL  s    %%seSYY[99rU   c                     U R                  UR                  5       U/5      nUR                  S:  a  UR                  UR                  5      $ U$ r   )r   r   r2   reshaper"   )r6   r   r   ress       r<   _get_arrayXint_dok_base._get_arrayXintO  s?    $$SYY[3%888a<;;syy))
rU   c                 ~    [        [        UR                  U R                  S   5      6 5      nU R	                  X5      $ r   r   r   r   r"   r   r   s      r<   _get_sliceXarray_dok_base._get_sliceXarrayU  3    5#++djjm456%%c//rU   c                 ~    [        [        UR                  U R                  S   5      6 5      nU R	                  X5      $ r   r   r   s      r<   _get_arrayXslice_dok_base._get_arrayXsliceY  r   rU   c                    U R                  [        U5      [        U5      4U R                  S9n[        U5       HN  u  pE[        U5       H:  u  pgU R                  R                  XW4S5      nU(       d  M+  XR                  XF4'   M<     MP     U$ )Nr   r   )r   rJ   r#   r4   r)   r   )	r6   r   r   r   r9   rr   cr:   s	            r<   r   _dok_base._get_columnXarray]  sx    $$c#hC%9$LcNDA!#JJNNA61-1)*LL& ' #
 rU   c                    [        [        R                  [        R                  " X5      5      u  p4U R	                  UR
                  U R                  S9n[        R                  " [        UR
                  S   5      [        UR
                  S   5      5       H<  nU R                  R                  X6   XF   4S5      nU(       d  M.  XuR                  U'   M>     U$ )Nr   r   r   )mapr.   
atleast_2dbroadcast_arraysr   r"   r#   	itertoolsproductr   r)   r   )r6   r   r   r9   r   r   rQ   r:   s           r<   _get_arrayXarray_dok_base._get_arrayXarrayh  s    2==""5"5c"?@$$QWWDJJ$?$$U1771:%6aggaj8IJC

/3Aq$%S! K rU   c                 j    U(       a  X R                   U'   g XR                   ;   a  U R                   U	 g g rg   rl   )r6   rD   r_   s      r<   _set_int_dok_base._set_intt  s*    JJsOJJ

3 rU   c                    UR                  5       nUR                  5       n[        U5      [        U5      :w  aG  [        U5      S:X  a-  [        R                  " [        U5      US   U R                  S9nO[        S5      e[        X45       H:  u  pVU(       a  X`R                  U'   M  XPR                  ;   d  M-  U R                  U	 M<     g )Nr   r   r   z*Need len(index)==len(data) or len(data)==1)r   rJ   r.   fullr#   r3   rM   r)   )r6   rD   r_   idx_setx_setr9   r:   s          r<   
_set_array_dok_base._set_arrayz  s    ))+	w<3u:%5zQGeAhdjjIKLL'DA !

1jjJJqM	 (rU   c                 p    X4nU(       a  X0R                   U'   g X@R                   ;   a  U R                   U	 g g rg   rl   )r6   r   r   r_   rQ   s        r<   _set_intXint_dok_base._set_intXint  s1    jJJsOJJ

3 rU   c                    [        [        [        UR                  5       5      5      n[        [        [        UR                  5       5      5      nUR                  5       nU R                  R                  [        [        X5      U5      5        [        R                  " US:H  5      S    H-  nX   X$   4nU R                  U   S:X  d  M   U R                  U	 M/     g r   )	r   r   r   r   r)   rN   rM   r.   nonzero)r6   r   r   r_   r9   rQ   s         r<   _set_arrayXarray_dok_base._set_arrayXarray  s    3sCIIK()3sCIIK()GGI

#c#mQ/0AF#A&A636"Czz#!#JJsO	 'rU   c                   ^ [        U5      (       a  [        U R                  U5      nU R                  U R                  US9m[
        R                  " U R                   Vs/ s H  n[        U5      PM     sn6  H0  nU R                  R                  US5      U-   nU(       d  M+  UTU'   M2     T$ [        U5      (       GaM  UR                  U R                  :w  a  [        S5      e[        U R                  UR                  5      nU R                  U R                  US9mU R                  R                  5       Tl        UR                  S:X  a  UR                  5       nOjUR!                  5       nU R"                  S:X  a$  [%        UR&                  S   UR(                  5      nO&[%        [%        UR&                  6 UR(                  5      n[*        R,                  " SS9   TR                  R/                  U4S jU 5       5        S S S 5        T$ [1        U5      (       a  U R3                  5       U-   mT$ [4        $ s  snf ! , (       d  f       T$ = f)	Nr   r   z Matrix dimensions are not equal.r   r   ignore)overc              3   <   >#    U  H  u  pUTU   U-   4v   M     g 7frg   r^   )rC   kr:   news      r<   rF   $_dok_base.__add__.<locals>.<genexpr>  s      EWTQ!SVaZWs   )r   r   r#   r   r"   r   r   r   r)   r   r
   r3   r   r    r+   rI   ra   r2   rM   coordsdatar.   errstaterN   r   todenseNotImplemented)r6   r   	res_dtyper;   rQ   aijo_itemsr  s          @r<   __add___dok_base.__add__  s   %djj%8I%%djj	%BC ((TZZ*HZ58Z*HIjjnnS!,u43"CH J0 
) e__{{djj( !CDDtzz5;;7I%%djj	%BC

)CI||u$++-99>!%,,q/5::>G!#u||"4ejjAG(+		   EW EE , 
	 U^^,,.5(C 
 "!/ +I$ ,+ 
s    H8&H==
Ic                 
    X-   $ rg   r^   r6   r   s     r<   __radd___dok_base.__radd__  s
    |rU   c                     U R                   R                  S:X  a  [        S5      eU R                  U R                  U R                   S9nUR
                  R                  S U R                  5        5       5        U$ )Nbz2Negating a sparse boolean matrix is not supported.r   c              3   .   #    U  H  u  pX* 4v   M     g 7frg   r^   )rC   r  r:   s      r<   rF   $_dok_base.__neg__.<locals>.<genexpr>  s     :\TQ!R\s   )r#   kindrW   r   r"   r)   rN   rI   r6   r  s     r<   __neg___dok_base.__neg__  sd    ::??c!%D  !!$**DJJ!?		:TZZ\::
rU   c                    ^ [        U R                  T5      nU R                  U R                  US9nUR                  R                  U4S jU R                  5        5       5        U$ )Nr   c              3   4   >#    U  H  u  pXT-  4v   M     g 7frg   r^   rC   r  r:   r   s      r<   rF   (_dok_base._mul_scalar.<locals>.<genexpr>  s     B\TQ1%i.\   )r   r#   r   r"   r)   rN   rI   r6   r   r  r  s    `  r<   _mul_scalar_dok_base._mul_scalar  sO    !$**e4	!!$**I!>		BTZZ\BC
rU   c                   ^ ^ [        T R                  TR                  5      nT R                  S:X  a  [        T5      (       a|  TR                  S:X  a"  T R                  5       TR                  5       -  nO.T R                  5       TR                  5       R                  S   -  nU" [        UU 4S jU 5       5      5      $ [        T5      (       a)  U" [        U4S jT R                  5        5       5      5      $ [        $ [        R                  " T R                  S   US9nT R                  5        H  u  u  pVnXE==   UTU   -  -  ss'   M     U$ )Nr   r   r   c              3   b   >#    U  H$  nTR                   U   TR                   U   -  v   M&     g 7frg   rl   )rC   r  r   r6   s     r<   rF   +_dok_base._matmul_vector.<locals>.<genexpr>  s&     $RTTZZ]U[[^%CTs   ,/c              3   8   >#    U  H  u  pTU   U-  v   M     g 7frg   r^   r-  s      r<   rF   r5    s     $KldaU1X\l   r   )r   r#   r2   r
   r+   r   ra   r  rc   r   rI   r  r.   zerosr"   )r6   r   r  r   resultr9   r   r:   s   ``      r<   _matmul_vector_dok_base._matmul_vector  s    4::u{{3	 99><<5(99;5D99;)=)=a)@@D $RT$R!RSS $Kdjjl$K!KLL%% $**Q-y9IFQAIU1X%I &rU   c                   ^ [        U R                  TR                  5      nU R                  S:X  a-  [        U4S jU R                  R                  5        5       5      $ U R                  S   nTR                  S:X  a  U4OUTR                  S   4n[        R                  " XBS9nU R                  5        H  u  u  pgnXV==   UTU   -  -  ss'   M     U$ )Nr   c              3   8   >#    U  H  u  pUTU   -  v   M     g 7frg   r^   )rC   r   r:   r   s      r<   rF   0_dok_base._matmul_multivector.<locals>.<genexpr>  s     C0Bq58|0Br7  r   r   )	r   r#   r2   rc   r)   rI   r"   r.   r8  )	r6   r   result_dtyper   	new_shaper9  r9   r   r:   s	    `       r<   _matmul_multivector_dok_base._matmul_multivector  s    djj%++699>C

0@0@0BCCC JJqM!JJ!OQD!U[[^1D	)8IFQAIU1X%I &rU   c                    ^ [        T5      (       a5  U R                  R                  U4S jU R                  5        5       5        U $ [        $ )Nc              3   4   >#    U  H  u  pXT-  4v   M     g 7frg   r^   r-  s      r<   rF   %_dok_base.__imul__.<locals>.<genexpr>       Fqe)nr/  r   r)   rN   rI   r  r   s    `r<   __imul___dok_base.__imul__  7    JJFFFKrU   c                   ^ [        T5      (       ae  [        U R                  T5      nU R                  U R                  US9nUR
                  R                  U4S jU R                  5        5       5        U$ U R                  5       T-  $ )Nr   c              3   4   >#    U  H  u  pXT-  4v   M     g 7frg   r^   r-  s      r<   rF   (_dok_base.__truediv__.<locals>.<genexpr>  rF  r/  )	r   r   r#   r   r"   r)   rN   rI   tocsrr0  s    `  r<   __truediv___dok_base.__truediv__  sk    %djj%8I%%djj	%BCIIFFGJzz|e##rU   c                    ^ [        T5      (       a5  U R                  R                  U4S jU R                  5        5       5        U $ [        $ )Nc              3   4   >#    U  H  u  pXT-  4v   M     g 7frg   r^   r-  s      r<   rF   )_dok_base.__itruediv__.<locals>.<genexpr>  rF  r/  rG  r   s    `r<   __itruediv___dok_base.__itruediv__  rJ  rU   c                 ,    [         R                  U 5      $ rg   )rH   
__reduce__rh   s    r<   rW  _dok_base.__reduce__  s     t$$rU   c                 X   > U R                   S:X  a  [        TU ]	  U5      $ [        S5      e)Nr   z diagonal requires two dimensions)r2   superdiagonalr3   )r6   r  	__class__s     r<   r[  _dok_base.diagonal  s*    99>7#A&&;<<rU   c                 "   U R                   S:X  a  U R                  5       $ Ub  US:w  a  [        S5      eU R                  u  p4U R	                  XC4U R
                  US9nUR                  R                  S U R                  5        5       5        U$ )Nr   )r   r   zvSparse arrays/matrices do not support an 'axes' parameter because swapping dimensions is the only logical permutation.)r#   r    c              3   6   #    U  H  u  u  po2U4U4v   M     g 7frg   r^   )rC   leftrightrO   s       r<   rF   &_dok_base.transpose.<locals>.<genexpr>!  s     V3E=D#4=#.s   )	r2   r    r3   r"   r   r#   r)   rN   rI   )r6   axesr    r   Nr  s         r<   	transpose_dok_base.transpose  s    99>99;>  zz!!1&

!F		VVW
rU   c                     U R                  U R                  U R                  S9nUR                  R	                  U R                  5        U$ Nr   )r   r"   r#   r)   rN   r(  s     r<   r    _dok_base.copy&  s:    !!$**DJJ!?		$
rU   c                    [         R                  X5      n[        [        [	        U5      5      [
        5      (       a  [        S [        U6  5       5      nO[        U5      S-   4nU " U[        U5      S9nX5l	        U$ )Nc              3   >   #    U  H  n[        U5      S -   v   M     g7f)r   N)max)rC   rD   s     r<   rF   %_dok_base.fromkeys.<locals>.<genexpr>1  s     <)3#c(Q,)r   r   r   )
rH   fromkeysr%   nextiterr&   rM   rl  r   r)   )clsiterablerR   tmpr"   r9  s         r<   rn  _dok_base.fromkeys-  sb    mmH,d49ou--<#s)<<EX\OEU$u+.rU   c                 
  ^^ U R                   mTS:X  a$  U R                  U R                  U R                  S9$ U R	                  [        U R                  5      S9m[        R                  " U R                  5       U R                  TS9nU R                  S:  a  [        U R                  5       6 OU R                  5       4n[        UU4S jU 5       5      nU R                  X$4U R                  U R                  S9nSUl        U$ )	Nr   r   )maxvalr#   countr   c              3   P   >#    U  H  n[         R                  " UTTS 9v   M     g7f)rw  N)r.   fromiter)rC   ix	idx_dtypennzs     r<   rF   "_dok_base.tocoo.<locals>.<genexpr>A  s     RTrr{{2YcBTs   #&r!   T)r}  r5   r"   r#   _get_index_dtyperl  r.   rz  rd   r2   rM   r   r&   has_canonical_format)r6   r    r  indsr  Ar|  r}  s         @@r<   ra   _dok_base.tocoo8  s    hh!8&&tzz&DD))TZZ)A	{{4;;=

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

S!%rU   c                 4    U(       a  U R                  5       $ U $ rg   r   r6   r    s     r<   r,   _dok_base.todokH  s    99;rU   c                 p    U R                   S:X  a  [        S5      eU R                  SS9R                  US9$ )Nr   z%tocsr() not valid for 1d sparse arrayFr   )r2   rW   ra   tocscr  s     r<   r  _dok_base.tocscO  s8    99>%&MNNzzuz%+++66rU   c                    [        XR                  S9n[        U5      [        U R                  5      :w  a  [        eU R
                  S:X  a<  US   n[        U R                  5       H  nX2:  d  M
  U R                  U	 M     Xl        g Uu  pBU R                  u  pVXE:  d  X&:  a<  [        U R                  5       5       H  u  p7X4:  d  Xr:  d  M  U R                  X74	 M!     Xl        g )Nr   r   )
r   r'   rJ   r"   rW   r2   r   r)   r(   r   )r6   r"   newNr9   newMr   rd  r   s           r<   resize_dok_base.resizeV  s    ENN;u:TZZ(%%99>9D$**%9

1 &  K
zz8txTYY[)9	

14( * rU   c                 l   [         R                  " U5      nU R                  U:w  av  U R                  U R                  US9n[         R                  " [        U R                  R                  5       5      US9n[        [        U R                  U5      5      Ul        U$ U(       a  U R                  5       $ U $ rh  )r.   r#   r   r"   r   r   r)   rd   rH   rM   r    )r6   r#   castingr    r9  r  s         r<   r-   _dok_base.astypep  s    ::((5(AF88D!2!2!45UCDDJJ 56FLM99;rU   )r)   r(   r#   )NNFrg   )g        )r   )NF)r   )F)unsafeT)Cr   
__module____qualname____firstlineno___formatr'   r$   rN   rZ   rb   r   __doc__ri   rn   rq   ru   rx   r{   r|   r   r   r   r   r   rI   r   rd   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r!  r)  r1  r:  rA  rH  rO  rT  rW  r[  re  r    classmethodrn  ra   r,   r  r  r-   __static_attributes____classcell__)r\  s   @r<   r   r      s	   GI%KT %KN#"J2
 oo--GO#1199M!3"  ( 04FIII$&	"	!	#,D7.*>??.:00		 " 
$>,$%=
 ''//H   ))11I
 <<''DL  MM))EM
 MM))EM7
 MM))EM. ^^++FN	 ^^++FNNrU   r   c                 "    [        U [        5      $ )a/  Is `x` of dok_array type?

.. warning::

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

Parameters
----------
x
    object to check for being a 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   )r_   s    r<   r   r   ~  s    @ a$$rU   c                       \ rS rSrSrSrg)r   i  aw  
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)
format : str
    Three letter code for the format of the array storage, e.g. 'dok'
nnz : int
    Number of values stored in the array
size : int
    Number of values stored in the array
T : dok_array
    The transpose of the array
mT : dok_array
    The matrix transpose of the array

Notes
-----

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

- 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

r^   N)r   r  r  r  r  r  r^   rU   r<   r   r     s    7rU   r   c                   J    \ rS rSrSrS rS r\" \\S9rS r	S r
S rS	 rS
rg)r   i  a$  
Dictionary Of Keys based sparse matrix.

This is an efficient structure for constructing sparse
matrices incrementally.

.. warning::

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

This can be instantiated in several ways:
    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)
format : str
    Three letter code for the format of the matrix storage, e.g. 'dok'
nnz : int
    Number of values stored in the matrix
size : int
    Number of values stored in the matrix
T : dok_matrix
    The transpose of the matrix
mT : dok_matrix
    The matrix transpose

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                 x    U R                  USS9R                  U R                  5      nUR                  U l        g )NFr   )r   asformatr+   __dict__)r6   r"   
new_matrixs      r<   	set_shapedok_matrix.set_shape   s0    \\%e\4==dkkJ
"++rU   c                     U R                   $ )zGet shape of a sparse matrix.)r(   rh   s    r<   	get_shapedok_matrix.get_shape$  s    {{rU   )fgetfsetc                 6    U R                   R                  5       $ rg   )r)   r   rh   s    r<   r   dok_matrix.__reversed__*  s    zz&&((rU   c                 |    [        U[        5      (       a  U R                  UR                  -  $ U R                  U-  $ rg   r%   r   r)   r   s     r<   r   dok_matrix.__or__-  1    eY''::++zzE!!rU   c                 |    [        U[        5      (       a  U R                  UR                  -  $ U R                  U-  $ rg   r  r   s     r<   r   dok_matrix.__ror__2  r  rU   c                     [        U[        5      (       a!  U =R                  UR                  -  sl        U $ U =R                  U-  sl        U $ rg   r  r   s     r<   r   dok_matrix.__ior__7  s=    eY''JJ%++%J  JJ%JrU   )r  N)r   r  r  r  r  r  r  propertyr"   r   r   r   r   r  r^   rU   r<   r   r     s5    @D, ))4E)"
"
rU   r   )r  __docformat____all__r   numpyr.   _matrixr   _baser   r	   r
   _indexr   _sputilsr   r   r   r   r   r   r   r   objectr{   rH   r   r   r   r   r^   rU   r<   <module>r     st    %%
7    - - ; ; ; 8g	,T g	,T %H8	7 8v_9 _rU   