
    doiG                     t    S r SSKrSSKJr  SSKJrJr  \\R                  4r
S r " S S5      rS	 rS
 rS rg)z0Indexing mixin for sparse array/matrix classes.
    N   )	isintlike)sparrayissparsec                      [         R                  " U 6 n[        X5       H*  u  p#UR                  R                  UR                  l        M,     U$ )a  
Same as np.broadcast_arrays(a, b) but old writeability rules.

NumPy >= 1.17.0 transitions broadcast_arrays to return
read-only arrays. Set writeability explicitly to avoid warnings.
Retain the old writeability rules, as our Cython code assumes
the old behavior.
)npbroadcast_arrayszipflags	writeable)arraysr	   xas       O/var/www/html/land-ocr/venv/lib/python3.13/site-packages/scipy/sparse/_index.py_broadcast_arraysr   
   sC     **F3$-GG-- .    c                       \ 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 rS rS rS rS rSrg)
IndexMixin   zK
This class provides common dispatching and validation logic for indexing.
c                 
   [        XR                  U R                  5      u  p#  n[        U5      S:  a  [	        SU R                   S35      e[        U5      S:X  Ga6  US   n[        U[        R                  5      (       a   UR                  S:X  a  UR                  5       n[        U[        5      (       a  U R                  U5      nO8[        U[        5      (       a  U R                  U5      nOU R                  U5      n[        U [        5      (       d  U$ UR                  S:X  a[  US:w  aU  [        U5      S:X  a  U R                  U/X0R                   S9$ [        U5      S:X  a  U R                  U//X0R                   S9$ UR#                  U5      $ Uu  px[        U[        5      (       a  [        U[        5      (       a  U R%                  Xx5      nGO{[        U[        5      (       a  U R'                  Xx5      nGOSUR(                  S:X  a  U R+                  Xx5      nGO0UR(                  S:X  a  U R+                  Xx5      nGO[	        S5      e[        U[        5      (       a  [        U[        5      (       a  U R-                  Xx5      nGO[        U[        5      (       a9  U[        S 5      :X  a  Xx:X  a  U R/                  5       nGOU R1                  Xx5      nGOwUR(                  S:X  a  U R3                  Xx5      nGOT[	        S5      e[        U[        5      (       a  U R5                  Xx5      nGO![        U[        5      (       a  U R7                  Xx5      nOUR(                  S:X  a^  UR                  S   S:X  aK  UR(                  S:X  d  UR                  S   S:X  a(  U R9                  US S 2S4   UR;                  5       5      nO[=        Xx5      u  pxUR                  UR                  :w  a  [	        S	5      eUR>                  S:X  a9  U R                  [        R@                  " U5      R                  U R                   S
9nOU RC                  Xx5      n[        U [        5      (       d]  US:X  d  [        U5      S:X  a  UR(                  S:w  a  U$ [        U5      S:X  a  SU-   nX6R                  :X  a  U$ UR#                  U5      $ UR                  U:w  ap  U R                  S:X  aO  [        U5      S:w  a@  UR                  S:X  a  U RE                  U/US9$ URG                  5       R#                  U5      $ UR#                  U5      $ U$ )N   z/Indexing that leads to >2D is not supported by z% format. Try converting to COO formatr   r    )shapedtypezindex results in >2 dimensions'number of row and column indices differr   )r   lilr   )$_validate_indicesr   formatlen
IndexError
isinstancer   ndarrayitem	INT_TYPES_get_intslice
_get_slice
_get_arrayr   	__class__r   reshape_get_intXint_get_intXslicendim_get_intXarray_get_sliceXintcopy_get_sliceXslice_get_sliceXarray_get_arrayXint_get_arrayXslice_get_columnXarrayravelr   size
atleast_2d_get_arrayXarray_coo_containertocoo)	selfkeyindex	new_shape_idxresrowcols	            r   __getitem__IndexMixin.__getitem__   s9   !23

DKK!P!Qy>AN $},QS T T u:?(C#rzz**99?((*C#y))mmC(C''ooc*ooc* dG,,
yyB9?y>Q&>>3%y

>SSy>Q&>>C5'**>UU;;y))  c9%%#y))''1C''))#3Q))#3Q))#3 !ABBU###y))))#3C''%+%#*))+C//9CQ++C5 !ABB#y))))#3C''++C5((a-CIIaLA$5XX]ciila&7,,SAY		D -S699		)$%NOO88q=..s);)A)A.TC//9C $((B3y>Q#6388q=
9~" 9,	#yy03Lckk)6LL 99	!{{e#I!(;99?..ui.HHyy{**955;;y))
r   c                 4   [        XR                  U R                  5      u  p4  n[        U5      S:X  Ga  US   n[	        U5      (       a  UR                  5       nO[        R                  " X R                  S9n[        U[        5      (       a:  UR                  S:w  a  [        S5      eU R                  XbR                  S   5        g [        U[        5      (       a  [!        UR#                  U R                  S   5      6 n[        U5      nUS:X  a3  UR                  S:X  a#  U R                  US   UR                  S   5        g [        R$                  " UR#                  U R                  S   5      6 nUR                  n	OUR'                  5       R                  n	UR'                  5       R                  U	:w  a   [        R(                  " X&R                  5      nUR                  S:w  a  U R+                  Xb5        g Uu  p[        U
[        5      (       a  [        U[        5      (       az  [	        U5      (       a  UR                  5       nO[        R                  " X R                  S9nUR                  S:w  a  [        S5      eU R-                  XUR                  S   5        g [        U
[        5      (       a7  [        R$                  " U
R#                  U R                  S   5      6 S S 2S 4   n
O[        R.                  " U
5      n
[        U[        5      (       aP  [        R$                  " UR#                  U R                  S   5      6 S S S 24   nU
R0                  S:X  a	  U
S S 2S 4   n
O[        R.                  " U5      n[3        X5      u  pUR                  UR                  :w  a  [5        S5      e[	        U5      (       Ga$  SUR                  ;   a  g UR0                  S:X  a
  US    nUS    nUR7                  SS9R9                  UR:                  SS9nUR                  S   S:H  =(       a    UR                  S   S:g  nUR                  S   S:H  =(       a    UR                  S   S:g  nU(       d   UR                  S   UR                  S   :X  a'  U(       d+  UR                  S   UR                  S   :X  d  [        S	5      eUR=                  5         U R?                  XU5        g [        R                  " X R                  S9nUR'                  5       R                  UR'                  5       R                  :w  a   [        R(                  " X,R                  5      nUR                  S:X  a  g UR9                  UR                  5      nU RA                  XU5        g )
Nr   r   r   z&Trying to assign a sequence to an itemr   F)r2   Tzshape mismatch in assignment)!r   r   r    r!   r   toarrayr   asarrayr   r#   r&   r9   
ValueError_set_intflatr(   rangeindicesarangesqueezebroadcast_to
_set_array_set_intXint
atleast_1dr/   r   r"   r=   r,   _shape_as_2dsum_duplicates_set_arrayXarray_sparse_set_arrayXarray)r>   r?   r   r@   rA   rB   rC   	idx_rangeN	idx_shaperE   rF   ijbroadcast_rowbroadcast_cols                   r   __setitem__IndexMixin.__setitem__   s   !23

DKK!P!Q u:?(C{{IIKJJq

3#y))66Q;$%MNNc66!9-#u%% "3;;tzz!}#=>		N6affkMM)A,q	:iiTZZ]!;<II	KKM//	yy{  I-OOAyy1vv{' c9%%*S)*D*D{{IIKJJq

3vv{ !IJJcq	2c5!!))S[[A78DAC--$Cc5!!))S[[A78qACxx1}!T'l--$C *77aggFGGA;;AGG|vv{dGdGU#++ANN+FAGGAJ!O?
aMGGAJ!O?
aM"aggajAGGAJ&>"aggajAGGAJ&> !?@@((q1 

1JJ/Ayy{  AIIK$5$55OOAww/vv{		!''"A!!!*r   c                     U R                   u  p#[        U5      nX* :  d  X:  a  [        SU S35      eUS:  a  X-  nU R                  U[	        S5      5      $ )zGReturn a copy of row i of the matrix, as a (1 x n) row vector.
        index () out of ranger   N)r   intr"   r.   r(   r>   r^   Mr\   s       r   _getrowIndexMixin._getrow   s\     zzFr6QVwqc899q5FA""1eDk22r   c                     U R                   u  p#[        U5      nX* :  d  X:  a  [        SU S35      eUS:  a  X-  nU R                  [	        S5      U5      $ )zMReturn a copy of column i of the matrix, as a (m x 1) column vector.
        re   rf   r   N)r   rg   r"   r1   r(   rh   s       r   _getcolIndexMixin._getcol   s\     zzFr6QVwqc899q5FA""5;22r   c                     [        5       eNNotImplementedErrorr>   rC   s     r   r'   IndexMixin._get_int       !##r   c                     [        5       erp   rq   rs   s     r   r)   IndexMixin._get_slice   ru   r   c                     [        5       erp   rq   rs   s     r   r*   IndexMixin._get_array   ru   r   c                     [        5       erp   rq   r>   rE   rF   s      r   r-   IndexMixin._get_intXint   ru   r   c                     [        5       erp   rq   r{   s      r   r0   IndexMixin._get_intXarray   ru   r   c                     [        5       erp   rq   r{   s      r   r.   IndexMixin._get_intXslice   ru   r   c                     [        5       erp   rq   r{   s      r   r1   IndexMixin._get_sliceXint  ru   r   c                     [        5       erp   rq   r{   s      r   r3   IndexMixin._get_sliceXslice  ru   r   c                     [        5       erp   rq   r{   s      r   r4   IndexMixin._get_sliceXarray  ru   r   c                     [        5       erp   rq   r{   s      r   r5   IndexMixin._get_arrayXint  ru   r   c                     [        5       erp   rq   r{   s      r   r6   IndexMixin._get_arrayXslice  ru   r   c                     [        5       erp   rq   r{   s      r   r7   IndexMixin._get_columnXarray  ru   r   c                     [        5       erp   rq   r{   s      r   r;   IndexMixin._get_arrayXarray  ru   r   c                     [        5       erp   rq   r>   rC   r   s      r   rM   IndexMixin._set_int  ru   r   c                     [        5       erp   rq   r   s      r   rT   IndexMixin._set_array  ru   r   c                     [        5       erp   rq   r>   rE   rF   r   s       r   rU   IndexMixin._set_intXint  ru   r   c                     [        5       erp   rq   r   s       r   rZ   IndexMixin._set_arrayXarray   ru   r   c                     [         R                  " UR                  5       U R                  S9n[	        X15      u  p4U R                  XU5        g )Nr   )r   rK   rJ   r   r   rZ   )r>   rE   rF   r   rB   s        r   rY   "IndexMixin._set_arrayXarray_sparse#  s8    JJqyy{$**5 (c*r   r   N)__name__
__module____qualname____firstlineno____doc__rG   rb   rj   rm   r'   r)   r*   r-   r0   r.   r1   r3   r4   r5   r6   r7   r;   rM   rT   rU   rZ   rY   __static_attributes__r   r   r   r   r      sy    `DY+v	3	3$$$$$$$$$$$$$$$$$+r   r   c           	      	  ^^ [        U5      nU [        L a  [        S5      4U-  U/ / 4$ [        U [        5      (       d  U /n Sn/ nSn[        U 5       H  u  pxU[        L a  Ub  [        S5      eUnM   Uc  UR                  U5        M6  [        U[        5      (       d  [        U5      (       a  UR                  U5        US-  nMs  [        X5      =n	b!  UR                  U	5        XiR                  -  nM  [        U5      (       a  [        S5      eUR                  [        R                  " U5      5        US-  nM     Xc:  a  [        SU  SU SU S	35      eX6-
  [        S5      /-  n
U
(       a"  Uc  UR                  U
5        OUSU U
-   XTS -   n/ nSn/ m/ n/ n/ n[        U5       GH  u  pxUc-  UR                  [        U5      5        UR                  S5        M6  [        U[        5      (       aM  TR                  U5        X   n[        [        UR!                  U5      6 5      nUR                  U5        US-  nM  [        U5      (       ac  X   nU* Us=::  a  U:  d  O  [        S
U S35      e[#        US:  a  UU-   OU5      nTR                  U5        UR                  U5        US-  nGM  UR$                  R&                  S:X  a  XR                  -   nXU nUR(                  U:w  a  [        SU SU SUR(                   35      eTR                  UR+                  5       5        UR                  [        UU5      5        UR                  [        UU5      5        UnGM  X   n[-        UUU5      nTR                  U5        UR                  U5        UR                  U5        US-  nGM     [        U5      S:  a  [/        U4S jU 5       6 m[1        U4S jTSS  5       5      (       a(  SR3                  S T 5       5      nSU 3n[        U5      e[5        UT5       H  u  nnUTU'   M     TS   R(                  n[        U5      US   US   -
  S-   :w  a  [7        U5      U-   nOZUS   nUSU [7        U5      -   UUS -   nO=[        U5      S:X  a.  TUS      R(                  nUS   nUSU [7        U5      -   UUS -   n[	        T5      [	        U5      X4$ )a  Returns four sequences: (index, requested shape, arrays, nones)

index : tuple of validated idx objects. bool arrays->nonzero(),
        arrays broadcast, ints and slices as they are, Nones removed
requested shape : the shape of the indexed space, including Nones
arr_pos : position within index of all arrays or ints (for array fancy indexing)
none_pos : insert positions to put newaxis coords in indexed space.
Nr   z(an index can only have a single ellipsisr   zoIndexing with sparse matrices is not supported except boolean indexing where matrix and index are equal shapes.z<Too many indices for array or tuple index out of range. Key z needs zD. Array is Dre   rf   bzbool index z has shape z instead of c              3   .   >#    U  H
  nTU   v   M     g 7frp   r   ).0r^   r@   s     r   	<genexpr>$_validate_indices.<locals>.<genexpr>  s     (I=aq=s   c              3   \   >#    U  H!  nTS    R                   UR                   :g  v   M#     g7f)r   Nr   )r   ix
idx_arrayss     r   r   r     s$     H2z!}""bhh.s   ), c              3   L   #    U  H  n[        UR                  5      v   M     g 7frp   )strr   )r   r   s     r   r   r     s     Ajc"((mmjs   "$zLshape mismatch: indexing arrays could not be broadcast together with shapes )r!   Ellipsisr(   r#   tuple	enumerater"   appendr   _compatible_boolean_indexr/   r   r   rK   extendrO   rP   rg   r   kindr   nonzero
_asindicesr   anyjoinr
   list)r?   
self_shapeself_format	self_ndim	ellps_pos	index_1stprelim_ndimr^   rC   r   ellip_slicesr]   
index_ndimarray_indicesnone_positionsarr_int_posMs	len_slicer\   tmp_ndim	mid_shapeshapesmsgarr	arr_shapearr_posr   r@   s                             @@r   r   r   *  s    JI
hd~	):r2==c5!!e IIKC.(?$ !KLLI[S!U##y~~S!1K-c==bJR 77"Kc]]$% %
 RZZ_-1K- !. %w{m<	{!E
 	
 +d}<L\*!*9-<y?TTI IJEMNKI&;!!#i.1QU##LL'BE3;;r?34IY'!OJs^^&AB#MM 73%~!>??qcAgc2CLLz*!OJYY^^s"!HH,H"h7IyyI% !!K	{,syykR  LL'  z8!<=uZ:;!J&AS![1CLLz*  ,!OJI 'J =A&(I=(IJ
HABHHHXXAjAAF++1(4CS/!-4FAsE!H 5qM''	 {B+a. @1 DEY)3I!!nG!(7+d9o=	'(@SSI	]	q	 -*+11	a.hw'$y/9Igh<OO	<y);FFr   c                 0    [         R                  " U 5      nUS:w  a(  UR                  S;  a  [        SUR                   35      eUS:X  a  U$ UR                  S:X  a  U$ UR                  5       nXQ:  a  [        SU S	35      eUR                  5       nUS:  aS  Xa* :  a  [        SU S	35      eX0L d  UR                  R                  (       d  UR                  5       nX3S:  ==   U-  ss'   U$ ! [        [        [        4 a  n[        S5      UeSnAff = f)
zConvert `idx` to a valid index for an axis with a given length.

Subclasses that need special validation can override this method.
zinvalid indexNcoo)r   r   z$Index dimension must be 1 or 2. Got r   r   re   rf   )r   rK   rL   	TypeErrorMemoryErrorr"   r/   r9   maxminr   owndatar2   )rC   lengthr    r   emax_indxmin_indxs          r   r   r     s	   
1ZZ_ 277&0?yIJJ 		ww!|	 vvxH78*N;<<vvxH!|gwxj?@@9BHH,,B
6
f
I3 	;/ 1)q01s   C/ /DDDc                 T   [        U S5      (       dk   [        [        U 5      S5      n[        U5       H/  n[	        U[
        5      (       a    O[        [        U5      S5      nM1     g[        R                  " U 5      n U R                  R                  S:X  a  U $ g! [         a     gf = f)zICheck for boolean array or array-like. peek before asarray for array-liker/   Nr   )hasattrnextiterrO   r#   boolr   r   
asanyarrayr   r   )rC   desired_ndimr   rB   s       r   r   r     s     3		d3i&B<(b$''$r(D) )
  mmC 
yy~~
  		s   9B B 
B'&B')r   numpyr   _sputilsr   _baser   r   rg   integerr&   r   r   r   r   r   r   r   r   <module>r      sF      $"**	N+ N+bHGV Fr   