
    Ji(G                     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       U/var/www/html/dynamic-report/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OTUR(                  S:X  a  U R+                  Xx5      nGO1U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OxUR(                  S:X  a  U R3                  Xx5      nGOU[	        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  aL  UR(                  S:X  d  UR                  S   S:X  a)  U R9                  US S 2S4   UR#                  S	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 RA                  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 RC                  U/US9$ URE                  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_columnXarrayr   size
atleast_2d_get_arrayXarray_coo_containertocoo)	selfkeyindex	new_shape_idxresrowcols	            r   __getitem__IndexMixin.__getitem__   s;   !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xx1}		!(9,,SAYBH -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&   r8   
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?   r@   rA   rB   	idx_rangeN	idx_shaperD   rE   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.
        rd   re   r   N)r   rf   r"   r1   r(   rg   s       r   _getcolIndexMixin._getcol   s\     zzFr6QVwqc899q5FA""5;22r   c                     [        5       eNNotImplementedErrorr=   rB   s     r   r'   IndexMixin._get_int       !##r   c                     [        5       ero   rp   rr   s     r   r)   IndexMixin._get_slice   rt   r   c                     [        5       ero   rp   rr   s     r   r*   IndexMixin._get_array   rt   r   c                     [        5       ero   rp   r=   rD   rE   s      r   r-   IndexMixin._get_intXint   rt   r   c                     [        5       ero   rp   rz   s      r   r0   IndexMixin._get_intXarray   rt   r   c                     [        5       ero   rp   rz   s      r   r.   IndexMixin._get_intXslice   rt   r   c                     [        5       ero   rp   rz   s      r   r1   IndexMixin._get_sliceXint  rt   r   c                     [        5       ero   rp   rz   s      r   r3   IndexMixin._get_sliceXslice  rt   r   c                     [        5       ero   rp   rz   s      r   r4   IndexMixin._get_sliceXarray  rt   r   c                     [        5       ero   rp   rz   s      r   r5   IndexMixin._get_arrayXint  rt   r   c                     [        5       ero   rp   rz   s      r   r6   IndexMixin._get_arrayXslice  rt   r   c                     [        5       ero   rp   rz   s      r   r7   IndexMixin._get_columnXarray  rt   r   c                     [        5       ero   rp   rz   s      r   r:   IndexMixin._get_arrayXarray  rt   r   c                     [        5       ero   rp   r=   rB   r   s      r   rL   IndexMixin._set_int  rt   r   c                     [        5       ero   rp   r   s      r   rS   IndexMixin._set_array  rt   r   c                     [        5       ero   rp   r=   rD   rE   r   s       r   rT   IndexMixin._set_intXint  rt   r   c                     [        5       ero   rp   r   s       r   rY   IndexMixin._set_arrayXarray   rt   r   c                     [         R                  " UR                  5       U R                  S9n[	        X15      u  p4U R                  XU5        g )Nr   )r   rJ   rI   r   r   rY   )r=   rD   rE   r   rA   s        r   rX   "IndexMixin._set_arrayXarray_sparse#  s8    JJqyy{$**5 (c*r   r   N)__name__
__module____qualname____firstlineno____doc__rF   ra   ri   rl   r'   r)   r*   r-   r0   r.   r1   r3   r4   r5   r6   r7   r:   rL   rS   rT   rY   rX   __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/ n/ n/ n/ n[        U5       GH  u  pxUc-  UR                  [        U5      5        UR                  S5        M6  [        U[        5      (       aM  U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U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U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UR                  U5        UR                  U5        UR                  U5        US-  nGM     [        U5      S:  ay  U Vs/ s H  o}U   R(                  PM     nn [        R.                  " U6 n[        U5      US   US   -
  S-   :w  a  [5        U5      U-   nOYUS   nUSU [5        U5      -   UUS -   nO<[        U5      S:X  a-  XS      R(                  nUS   nUSU [5        U5      -   UUS -   n[	        U5      [	        U5      UU4$ s  snf ! [0         a)    SR3                  S U 5       5      nSU 3n[        U5      ef = f)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 Drd   re   bzbool index z has shape z instead of  c              3   8   #    U  H  n[        U5      v   M     g 7fro   )str).0shps     r   	<genexpr>$_validate_indices.<locals>.<genexpr>  s     =*3c#hh*s   zLshape mismatch: indexing arrays could not be broadcast together with shapes r   )r!   Ellipsisr(   r#   tuple	enumerater"   appendr   _compatible_boolean_indexr/   r   r   rJ   extendrN   rO   rf   r   kindr   nonzero
_asindicesbroadcast_shapesrK   joinlist)r>   
self_shapeself_format	self_ndim	ellps_pos	index_1stprelim_ndimr]   rB   ixellip_slicesr\   
index_ndimr?   array_indicesnone_positionsarr_int_posMs	len_slicer[   tmp_ndim	mid_shape
arr_shapes	arr_shapeshapesmsgarr_poss                              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.;<mAhnnm
<	"++Z8I {B+a. @1 DEY)3I!!nG!(7+d9o=	'(@SSI	]	q	 *+11	a.hw'$y/9Igh<OO	<y);FF' =  	"XX=*==F++1(4CS/!		"s   R"R 3Sc                 \    [         R                  " U 5      nUS:w  a  UR                  S;  d  US:X  a(  UR                  S:X  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   r   z$Index dimension must be 1 or 2. Got r   rd   re   )r   rJ   rK   	TypeErrorMemoryErrorr"   r/   r8   maxminr   owndatar2   )rB   lengthr    r   emax_indxmin_indxs          r   r   r     s   
1ZZ_ 277&0FeOST?yIJJ 		ww!|	 vvxH78*N;<<vvxH!|gwxj?@@9BHH,,B
6
f
I3 	;/ 1)q01s   D 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iterrN   r#   boolr   r   
asanyarrayr   r   )rB   desired_ndimr   rA   s       r   r   r     s     3		d3i&B<(b$''$r(D) )
  mmC 
yy~~
  		s   9B B 
B'&B')r   numpyr   _sputilsr   _baser   r   rf   integerr&   r   r   r   r   r   r   r   r   <module>r      sF      $"**	N+ N+bFGR Fr   