
    tfh                         d Z g ZddlmZ ddlZddlZddlmZm	Z	 ddl
mZmZmZmZ ddlmZmZ ddlmZ dd	lmZmZmZmZmZ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&m'Z'm(Z(m)Z)m*Z*  G d deee      Z+d Z,y)z>Base class for sparse matrix formats using compressed storage.    )warnN)_prune_arraycopy_if_needed   )_spbaseissparseSparseEfficiencyWarningsparray)_data_matrix_minmax_mixin)_sparsetools)get_csr_submatrixcsr_sample_offsetscsr_todensecsr_sample_valuescsr_row_indexcsr_row_slicecsr_column_index1csr_column_index2)
IndexMixin)upcastupcast_char	to_nativeisdenseisshapegetdtypeisscalarlike	isintlikedowncast_intp_indexget_sum_dtypecheck_shapeis_pydata_spmatrixc                      e Zd ZdZd=dZd>dZej
                  j                  e_        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@dZej.                  j                  e_        d Zd Zej2                  j                  e_        d Zej4                  j                  e_        dAdZej6                  j                  e_        d>dZd Zd Zd Zd Z d Z!dBd Z"d! Z#dBd"Z$d=d#Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d?d,Z.ej\                  j                  e._        dCd-Z/ej^                  j                  e/_        d. Z0e1d/e2fd0       Z3e3jh                  d1e2fd2       Z3d3 Z5e1d/e2fd4       Z6e6jh                  d1e2fd5       Z6d6 Z7d7 Z8d8 Z9d9 Z:ejt                  j                  e:_        d?d:Z;d; Z<d< Z=y)D
_cs_matrixzY
    base array/matrix class for compressed row- and column-oriented arrays/matrices
    Nc                 v   t        j                  |        t        |      r|j                  | j                  k(  r|r|j	                         }n|j                  | j                        }|j                  |j                  |j                  |j                  f\  | _        | _        | _        | _	        nt        |t              rt        |      rt        |      | _	        | j                  \  }}| j                  t!        ||            }t#        j$                  dt'        |t(                    | _        t#        j$                  d|      | _        t#        j$                  | j+                  ||f      d   dz   |      | _        nt-        |      dk(  r\| j/                  |||      }|j1                  | j*                        }	|	\  | _        | _        | _        | _	        | j3                          nXt-        |      dk(  r|\  }
}}d }|t!        |      }| j                  ||f|d	
      }|st4        }t#        j6                  |||      | _        t#        j6                  |||      | _        t#        j6                  |
||      | _        nt9        d| j                   d      	 t#        j:                  |      }t        | t>              r7|j@                  dk  r(| j                  dk(  rt9        d|j@                   d      | j/                  ||      }|j1                  | j*                        }	|	\  | _        | _        | _        | _	        |t        |      | _	        nc| j                  W	 t-        | j                        dz
  }| j                  j!                         dz   }t        | j+                  ||f            | _	        |"| j                  jC                  |d      | _        | jE                  d       y # t<        $ r!}d| j                   d}t9        |      |d }~ww xY w# t<        $ r}t9        d      |d }~ww xY w)Nmaxvalr   )defaultr   dtype   shaper*      T)r'   check_contentscopyr*   zunrecognized z_matrix constructor usagecsczCSC arrays don't support zD input. Use 2Dz!unable to infer matrix dimensionsFr1   
full_check)#r   __init__r   formatr1   asformatindptrindicesdata_shape
isinstancetupler   r!   r-   _get_index_dtypemaxnpzerosr   float_swaplen_coo_container_coo_to_compressedsum_duplicatesr   array
ValueErrorasarray	Exceptionr
   ndimastypecheck_format)selfarg1r-   r*   r1   MN	idx_dtypecooarraysr;   r:   r9   r'   emsg	major_dim	minor_dims                     b/var/www/html/software/conda/envs/higlass/lib/python3.12/site-packages/scipy/sparse/_compressed.pyr6   z_cs_matrix.__init__   s   d#D>{{dkk)dyy{}}T[[1T\\499dkkA=DKty$+ e$t} *$/zz1 !11Q1C	HHQ(FG	!xx95 hhtzz1a&'9!'<q'@-68 t9>--d%u-MC 33DJJ?FHNEDKty$+'')Y!^.2+T7F "F(!$U $ 5 5w6G7=?C !6 !EI  -#%88G$i#PDL"$((6I"NDK "D FDI$}T[[M B9 &9 : :
-zz$' $(TYY]t{{e?S /		{/J  %%d%%8C++DJJ7F@F=DKty$+ %e,DKzz!R #DKK 01 4I $ 0 0 2Q 6I #.djj)Y9O.P"QDK		((U(;DIU+9  -%dkk]2KL o1,-( ! Q$%HIqPQs0   O1 $5P 1	P:PP	P8'P33P8c                 t   |t        | j                  d         S |dk  r|dz  }| j                  |d|z
  f      \  }}| j                  | j                        \  }}|dk(  r*t	        j
                  t        | j                        |      S |dk(  rt	        j                  | j                        S t        d      )Nr   r+   r   )	minlengthzaxis out of bounds)
intr9   rD   r-   rA   bincountr   r:   diffrJ   )rP   axis_rS   s       r[   _getnnzz_cs_matrix._getnnzs   s    <t{{2''ax	jj$D!12GD!::djj)DAqqy{{#6t||#D-.0 0wwt{{++122    c                    | j                  d      \  }}| j                  | j                        \  }}| j                  j                  j                  dk7  r/t        d| j                  j                  j                   dd       | j                  j                  j                  dk7  r/t        d| j                  j                  j                   dd       | j                  j                  | j                  j                  | j                  j                  fD ]  }|dk7  s	t        d	       t        | j                        |dz   k7  r1t        d
j                  t        | j                        |dz               | j                  d   dk7  rt        d      t        | j                        t        | j                        k7  rt        d      | j                  d   t        | j                        kD  rt        d      | j                          |r0| j                  dkD  r| j                  j                         |k\  rt        | d|       | j                  j!                         dk  rt        | d      t#        j$                  | j                        j!                         dk  rt        d      | j'                  | j                  | j                  f      }t#        j(                  | j                  |      | _        t#        j(                  | j                  |      | _        t+        | j                        | _        yy)a  Check whether the array/matrix respects the CSR or CSC format.

        Parameters
        ----------
        full_check : bool, optional
            If `True`, run rigorous check, scanning arrays for valid values.
            Note that activating those check might copy arrays for casting,
            modifying indices and index pointers' inplace.
            If `False`, run basic checks on attributes. O(1) operations.
            Default is `True`.
        )rowcolumniz$indptr array has non-integer dtype ()r.   
stacklevelz%indices array has non-integer dtype (r   z'data, indices, and indptr should be 1-Dz&index pointer size ({}) should be ({})r   z!index pointer should start with 0z*indices and data should have the same sizer]   zQLast value of index pointer should be less than the size of index and data arraysz index values must be < z index values must be >= 0z8index pointer values must form a non-decreasing sequencer)   N)rD   r-   r9   r*   kindr   namer:   r;   rM   rJ   rE   r7   prunennzr@   minrA   ra   r?   rK   r   )rP   r5   
major_name
minor_namerY   rZ   xrT   s           r[   rO   z_cs_matrix.check_format   s    "&,=!>
J#zz$**5	9 ;;!!S(78I8I8N8N7OqQ<<""c)89K9K9P9P8QQRS ))..$,,"3"3T[[5E5EF 	LAAv !JKK	L
 	A-   &s4;;'7Q GI IKKNa@AA TYY/IJJKKOc$,,// A B B 	

xx!|<<##%2$
|3KI;%WXX<<##%)$
|3M%NOO774;;'++-1$ &? @ @ --t{{DLL.IJI**T[[	BDK::dll)DDL!$)),DI re   c                     | j                          | j                   || j                  |      d      }|j                          |S )zScalar version of self._binopt, for cases in which no new nonzeros
        are added. Produces a new sparse array in canonical form.
        Tr3   )rH   
_with_datar;   eliminate_zeros)rP   otheropress       r[   _scalar_binoptz_cs_matrix._scalar_binopt   s>     	oobE2o>
re   c                    t        |      rt        j                  |      r+| j                  | j                  t        j
                        S |dk(  rut        dt        d       | j                  t        j                  | j                  t        j
                              }| j                  |t        j                        }||z
  S | j                  |t        j                        S t        |      r| j                         |k(  S t        |      rt         S t#        |      rt        dt        d       | j                  |j                  k7  ry| j$                  |j$                  k7  r|j'                  | j$                        }| j)                  |d      }| j                  t        j                  | j                  t        j
                              }||z
  S t         S )	Nr)   r   zOComparing a sparse matrix with 0 using == is inefficient, try using != instead.r.   rk   zHComparing sparse matrices using == is inefficient, try using != instead.F_ne_)r   rA   isnan	__class__r-   bool_r   r	   onesr{   operatorneeqr   todenser"   NotImplementedr   r7   r8   _binopt)rP   rx   all_trueinvrz   s        r[   __eq__z_cs_matrix.__eq__   s\   xx~~djj~AAz /0G !#  >>"''$**BHH*MN))%=#~%**5(++>>U^<<>U**&!!e_  !8QH zzU[[(,t{{3,,uf-C~~bggdjj&IJHc>!!!re   c                 \   t        |      rt        j                  |      rRt        dt        d       | j                  t        j                  | j                  t        j                              }|S |dk7  rut        dt        d       | j                  t        j                  | j                        t        j                        }| j                  |t        j                        }||z
  S | j                  |t        j                        S t        |      r| j                         |k7  S t        |      rt         S t#        |      r`| j                  |j                  k7  ry| j$                  |j$                  k7  r|j'                  | j$                        }| j)                  |d      S t         S )	Nz:Comparing a sparse matrix with nan using != is inefficientr.   rk   r)   r   z^Comparing a sparse matrix with a nonzero scalar using != is inefficient, try using == instead.Tr}   )r   rA   r~   r   r	   r   r   r-   r   r{   r   r   r   r   r   r"   r   r   r7   r8   r   )rP   rx   r   r   s       r[   __ne__z_cs_matrix.__ne__   s<   xx $%<L>>"''$**BHH*MN! >,<  >>"''$***=RXX>N))%=#~%**5(++>>U^<<>U**&!!e_zzU[[(,t{{3<<v..!!re   c                    t        |      rd|k(  r|dv rt        d       |d|      rzt        |t        d       t	        j
                  | j                  t	        j                  |            }|j                  |       | j                  |      }| j                  ||      S | j                  ||      S t        |      r || j                         |      S t        |      r| j                  |j                  k7  rt        d      | j                   |j                   k7  r|j#                  | j                         }|dvr| j                  ||      S t        d	t        d       | j                  t	        j$                  | j                  t        j&                              }| j                  ||d
k(  rdnd      }||z
  S t(        S )Nr   )_le__ge_z >= and <= don't work with 0.r.   rk   r)   inconsistent shapes)r   r   zUComparing sparse matrices using >= and <= is inefficient, using <, >, or !=, instead.r   _gt__lt_)r   NotImplementedErrorr   r	   rA   emptyr-   result_typefillr   r   r{   r   r   r   rJ   r7   r8   r   r   r   )rP   rx   ry   op_namebad_scalar_msg	other_arrr   rz   s           r[   _inequalityz_cs_matrix._inequality  sm   Ezg)99)*IJJAu^%<KHHTZZr~~e7LM	u% NN95	||Iw77**5"55U^dllne,,e_zzU[[( !677,t{{3..||E733 /(Q8 ~~bggdjj&IJH,,u60AfvNCc>!!!re   c                 F    | j                  |t        j                  dd      S )Nr   zgComparing a sparse matrix with a scalar greater than zero using < is inefficient, try using >= instead.)r   r   ltrP   rx   s     r[   __lt__z_cs_matrix.__lt__=  $    x{{F!89 	9re   c                 F    | j                  |t        j                  dd      S )Nr   zdComparing a sparse matrix with a scalar less than zero using > is inefficient, try using <= instead.)r   r   gtr   s     r[   __gt__z_cs_matrix.__gt__C  r   re   c                 F    | j                  |t        j                  dd      S )Nr   zgComparing a sparse matrix with a scalar greater than zero using <= is inefficient, try using > instead.)r   r   ler   s     r[   __le__z_cs_matrix.__le__I  $    x{{F!78 	8re   c                 F    | j                  |t        j                  dd      S )Nr   zdComparing a sparse matrix with a scalar less than zero using >= is inefficient, try using < instead.)r   r   ger   s     r[   __ge__z_cs_matrix.__ge__O  r   re   c                 H   |j                   | j                   k7  r&t        d| j                    d|j                    d      t        | j                  j                  |j                  j                        }| j                  d      d   }t        j                  |||d      }| j                  | j                         \  }}|j                  j                  r|n|j                  }t        ||| j                  | j                  | j                  |       | j                  |d	      S )
NzIncompatible shapes (z and rj   CFr   T)r*   orderr1   Fr3   )r-   rJ   r   r*   charrD   rA   rI   flagsc_contiguousTr   r9   r:   r;   
_container)rP   rx   r*   r   resultrR   rS   ys           r[   
_add_densez_cs_matrix._add_denseY  s    ;;$**$4TZZLekk]RSTUUDJJOOU[[-=-=>

4 #%uEEzz$**%1ll//FVXXAq$++t||TYYBvE22re   c                 &    | j                  |d      S )N_plus_r   r   s     r[   _add_sparsez_cs_matrix._add_sparsed  s    ||E8,,re   c                 &    | j                  |d      S )N_minus_r   r   s     r[   _sub_sparsez_cs_matrix._sub_sparseg  s    ||E9--re   c                    t        |      r| j                  |      S t        |      r| j                  |j                  k(  r#| j	                  |      }| j                  |d      S |j                  dk(  rt        d      |j                  dk(  r"| j                  |j                         d         S | j                  dk(  r"|j                  | j                         d         S | j                  d   dk(  r1|j                  d   dk(  r| j                  |j                               S | j                  d   dk(  r1|j                  d   dk(  r|j                  | j                               S |j                  d   dk(  r~| j                  d   |j                  d   k(  r_| j                  |j                         j                         dgf|j                  d   |j                  d   f      }| j                  |      S | j                  d   dk(  r~| j                  d   |j                  d   k(  r_| j                  | j                         j                         dgf| j                  d   | j                  d   f      }|j                  |      S |j                  d   dk(  r~| j                  d   |j                  d   k(  r_| j                  |j                         j                         dgf|j                  d   |j                  d   f      }|j                  |       S | j                  d   dk(  r~| j                  d   |j                  d   k(  r_| j                  | j                         j                         dgf| j                  d   | j                  d   f      }|j                  |      S t        d      t        j                  |      }|j                  d	k7  r$t        j                   | j                         |      S |j"                  dk(  rA|j$                  t        j&                  k(  rt(        S | j                  |j*                  d         S | j                  dk(  r't        j                   | j                         d   |      S | j-                         }| j                  |j                  k(  r;t        j                   |j.                  ||j0                  |j2                  f         }n| j                  d   dk(  rd|j                  d   dk(  r!t        j                   |j.                  |      }n\|j                  d   | j                  d   k(  r2t        j                   |j.                  |d
d
|j2                  f         }nt        d      t        j4                  t        j6                  |j                  d         t9        |j0                              }t        j:                  |j2                  |j                  d         }| j=                  |j?                  t        j@                        j                         ||ff|j                  d   | j                  d   fd      S | j                  d   dk(  rn|j                  d   dk(  r(t        j                   |j.                  d
d
d
f   |      }n_|j                  d   | j                  d   k(  r5t        j                   |j.                  d
d
d
f   ||j0                           }nt        d      t        j4                  |j0                  |j                  d         }t        j:                  t        j6                  |j                  d         t9        |j2                              }| j=                  |j?                  t        j@                        j                         ||ff| j                  d   |j                  d   fd      S |j                  d   dk(  r_| j                  d   |j                  d   k(  r@t        j                   |j.                  |d
d
|j2                  f   j                               }nx|j                  d   dk(  r[| j                  d   |j                  d   k(  r<t        j                   |j.                  ||j0                     j                               }nt        d      |j?                  t        j@                        j                         |_        |S )zVPoint-wise multiplication by another array/matrix, vector, or
        scalar.
        _elmul_r   z+broadcast from a 1d array not yet supported)r   r   )r   r   r   r-   r   r+   NFr-   r1   )!r   _mul_scalarr   r-   r   r   rM   	TypeErrortoarray_matmul_sparsetocsc_dia_containerravelrJ   rA   
atleast_2dmultiplysizer*   object_r   flattocoor;   rg   colrepeatarangerE   tilerF   viewndarray)rP   rx   r1   retr;   rg   r   s          r[   r   z_cs_matrix.multiplyj  s	   
 ##E**E?zzU[[(u-||E955zzQ MNN&''(=>>v%(()=>>A!#A!(;**5;;=99A!#A!(;++DJJL99Q1$A%++a.)H++]]_**,qc2 ;;q>5;;q>: ,  **511A!#

1Q(G**\\^))+aS1::a=$**Q-8 +  ++D11Q1$A%++a.)H++]]_**,qc2 ;;q>5;;q>: ,  ++D11A!#

1Q(G**\\^))+aS1::a=$**Q-8 +  **511 !677 e$::?;;t||~u55::?{{bjj(%%##EJJqM22ZZ6!;;t||~d3U;;jjl::$;;sxxsww/?)@ADZZ]a{{1~"{{388U3Q4::a=0{{388U1cgg:->? !677))BIIekk!n5s377|DC''#''5;;q>2C&&2::&,,.c
;{{1~tzz!}5 '   ZZ]a{{1~"{{388AtG#4e<Q4::a=0{{388AtG#4eCGGnE !677))CGGU[[^4C''"))EKKN3S\BC&&2::&,,.c
;zz!}ekk!n5 '   [[^q TZZ]ekk!n%D;;sxxq#''z):)@)@)BCD[[^q TZZ]ekk!n%D;;sxxsww)=)=)?@D23399RZZ(..0
re   c           	      H   | j                   \  }}t        j                  |t        | j                  j
                  |j                  j
                              }t        t        | j                  dz         } |||| j                  | j                  | j                  ||       |S )Nr)   _matvec)r-   rA   rB   r   r*   r   getattrr   r7   r9   r:   r;   )rP   rx   rR   rS   r   fns         r[   _matmul_vectorz_cs_matrix._matmul_vector  s}    zz1 !;tzz/4{{/?/?$A B \4;;#:;
1adllDIIufEre   c                    | j                   \  }}|j                   d   }t        j                  ||ft        | j                  j
                  |j                  j
                              }t        t        | j                  dz         } ||||| j                  | j                  | j                  |j                         |j                                |S )Nr   r)   _matvecs)r-   rA   rB   r   r*   r   r   r   r7   r9   r:   r;   r   )rP   rx   rR   rS   n_vecsr   r   s          r[   _matmul_multivectorz_cs_matrix._matmul_multivector  s    zz1Q1f+ +DJJOOU[[=M=M NP \4;;#;<
1adllDII;;=&,,.	* re   c                 J   | j                   \  }}|j                   \  }}| j                  ||f      d   }| j                  |      }| j                  | j                  | j
                  |j                  |j
                  f      }t        t        | j                  dz         } |||t        j                  | j                  |      t        j                  | j
                  |      t        j                  |j                  |      t        j                  |j
                  |            }	| j                  | j                  | j
                  |j                  |j
                  f|	      }t        j                  |dz   |      }
t        j                  |	|      }t        j                  |	t        | j                  |j                              }t        t        | j                  dz         } |||t        j                  | j                  |      t        j                  | j
                  |      | j                  t        j                  |j                  |      t        j                  |j
                  |      |j                  |
||       | j                  |||
f||f      S )Nr   _matmat_maxnnzr)   r&   r   _matmatr   )r-   rD   r   r?   r9   r:   r   r   r7   rA   rK   r   r   r*   r;   )rP   rx   rR   K1K2rS   
major_axisrT   r   rp   r9   r:   r;   s                r[   r   z_cs_matrix._matmul_sparse  s   

2AZZA'*
u%))4;;%*\\5==+B C	 \4;;1A#ABADKKy9DLL	:ELL	:EMM;	= ))4;;%*\\5==+B+. * 0	 *q.	:((3i0xx6$**ekk#BC\4;;#:;
1aDKKy9::dll)499::ell)4::emm95::7D	" ~~tWf5aV~DDre   c           
         | j                   \  }}|| k  s||k\  r+t        j                  d| j                  j                        S t        t        | j                  dz         }t        j                  t        |t        |d      z   |t        |d      z
        t        | j                              } ||| j                   d   | j                   d   | j                  | j                  | j                  |       |S )Nr   r)   	_diagonalr   )r-   rA   r   r;   r*   r   r   r7   rq   r@   r   r9   r:   )rP   krowscolsr   r   s         r[   diagonalz_cs_matrix.diagonal!  s    ZZ
d:d88ATYY__55\4;;#<=HHSAq	)4#a)+;<!$**-/
1djjmTZZ]DKK99a	re   c                    t        |      r ||      rt        dt        d       t        j                  | j
                  t        j                  |      j                        }|j                  |       | j                  |      }| j                  ||      S | j                           || j                  t        j                  |            }| j                  || j                  | j                  f|j                  | j
                        }|S t        |      r || j!                         |      S t#        |      r| j                  ||      S t%        d      )NzITaking maximum (minimum) with > 0 (< 0) number results to a dense matrix.r.   rk   r)   )r*   r-   zOperands not compatible.)r   r   r	   rA   r   r-   rK   r*   r   r   r   rH   r;   r:   r9   r   r   r   rJ   )rP   rx   npopr   dense_checkr   new_datamats           r[   _maximum_minimumz_cs_matrix._maximum_minimum2  s   5! +,C !# HHTZZrzz%7H7N7NO	u% NN95	||Iw77##%		2::e+<=nnhdkk%J+3>> % M
U^..e_<<w//788re   c                 H    | j                  |t        j                  dd       S )N	_maximum_c                 2    t        j                  |       dkD  S Nr   rA   rK   rt   s    r[   <lambda>z$_cs_matrix.maximum.<locals>.<lambda>K      BJJqMA<M re   )r   rA   maximumr   s     r[   r   z_cs_matrix.maximumI  %    $$UBJJ%02MO 	Ore   c                 H    | j                  |t        j                  dd       S )N	_minimum_c                 2    t        j                  |       dk  S r   r   r   s    r[   r   z$_cs_matrix.minimum.<locals>.<lambda>Q  r   re   )r   rA   minimumr   s     r[   r   z_cs_matrix.minimumO  r   re   c                    t        | d      s|| j                  d      d   v rt        | j                        }t	        j
                  t        | j                        dz
  |      }| j                  t        j                        \  }}|||<   | j                  |      }|dz  dk(  r|j                  }|$|j                  |j                  k7  rt        d      |j                  d||	      S t        j                  | |||	      S )
zSum the array/matrix over the given axis.  If the axis is None, sum
        over both rows and columns, returning a scalar.
        	blocksize))r   r]   )r   r+   r   r   r)   r+   zdimensions do not match )rb   r*   out)hasattrrD   r    r*   rA   rB   rE   r9   _minor_reduceadd_ascontainerr   r-   rJ   sumr   )rP   rb   r*   r   	res_dtyper   major_indexvalues           r[   r  z_cs_matrix.sumY  s     k*

#45a88%djj1I((3t{{+a/yAC!%!3!3BFF!;K$C##C(Cax1}ee399		#9 !:;;77%S799 ;;t$eEEre   c                     || j                   }t        j                  t        j                  | j                              }|j                  |t        | j                  |               }||fS )a  Reduce nonzeros with a ufunc over the minor axis when non-empty

        Can be applied to a function of self.data by supplying data parameter.

        Warning: this does not call sum_duplicates()

        Returns
        -------
        major_index : array of ints
            Major indices where nonzero

        value : array of self.dtype
            Reduce result for nonzeros in each major_index
        )r;   rA   flatnonzerora   r9   reduceatr   )rP   ufuncr;   r  r  s        r[   r  z_cs_matrix._minor_reducev  sZ     <99DnnRWWT[[%9:t24;;{3KLNE!!re   c                    | j                  | j                        \  }}| j                  ||f      \  }}t        ||| j                  | j                  | j
                  ||dz   ||dz   	      \  }}}	|	j                  | j                        S )Nr   r)   )rD   r-   r   r9   r:   r;   r  r*   )
rP   rg   r   rR   rS   majorminorr9   r:   r;   s
             r[   _get_intXintz_cs_matrix._get_intXint  s~    zz$**%1zz3*-u 1q$++t||TYY519eUQY!0 xxdjjx))re   c                     | j                  ||f      \  }}|j                  dv r"|j                  dv r| j                  ||d      S | j                  |      j	                  |      S )N)r   NTr3   )rD   step_get_submatrix_major_slice_minor_slicerP   rg   r   r  r  s        r[   _get_sliceXslicez_cs_matrix._get_sliceXslice  sc    zz3*-u::"uzzY'>&&ue$&??  '44U;;re   c                    | j                   j                  }| j                  | j                        \  }}| j                  ||f      \  }}t	        j
                  ||      }t	        j
                  ||      }t	        j                  |j                  | j                        }t        ||| j                  | j                   | j                  |j                  |j                         |j                         |	       |j                  dk(  r| j                  |      S | j                  |j                  |j                              S )Nr)   r   )r:   r*   rD   r-   rA   rK   r   r   r   r9   r;   r   rM   r  r   reshape)	rP   rg   r   rT   rR   rS   r  r  vals	            r[   _get_arrayXarrayz_cs_matrix._get_arrayXarray  s    LL&&	zz$**%1zz3*-u

5	2

5	2hhuzz4!QT\\499**ekkmU[[]C	I::?$$S))~~ckk%++677re   c                 n    | j                  ||f      \  }}| j                  |      j                  |      S N)rD   _major_index_fancy_minor_index_fancyr  s        r[   _get_columnXarrayz_cs_matrix._get_columnXarray  s4    zz3*-u&&u-@@GGre   c           	      j   | j                  | j                  | j                  f      }t        j                  ||      j                         }| j                  | j                        \  }}t        |      }| j                  ||f      }|dk(  r| j                  || j                        S | j                  |dz      | j                  |   z
  j                  |      }t        j                  |dz   |      }	t        j                  ||	dd        |	d   }
t        j                  |
|      }t        j                  |
| j                        }t        ||| j                  j                  |d      | j                  j                  |d      | j                   ||       | j                  |||	f|d	      S )
zBIndex along the major axis where idx is an array of ints.
        r)   r   r   Nr   r]   Fr3   r   )r?   r9   r:   rA   rK   r   rD   r-   rE   r   r*   rN   rB   cumsumr   r   r;   )rP   idxrT   r:   rc   rS   rR   	new_shaperow_nnz
res_indptrrp   res_indicesres_datas                r[   r  z_cs_matrix._major_index_fancy  sx    ))4;;*EF	**S	288:zz$**%1LJJ1v&	6>>)4::>>>;;w{+dkk'.BBJJ9UXXac3

		'z!"~.nhhs)488Ctzz2KKyu5LL	6II	
 ~~xjA$-E  ; 	;re   c           
      D   |t        d      k(  r|r| j                         S | S | j                  | j                        \  }}|j	                  |      \  }}}t        t        |||            }| j                  ||f      }|dk(  r| j                  || j                        S ||}
}	|dk(  r|dk\  rd}
|dz   |dz   }}| j                  |||   | j                  |	|
|   z
  }| j                  j                  }t        j                  |dz   |      }t        j                  ||dd        |dk(  rot        | j                  |   | j                  |         }t        j                  | j                  |   |      }t        j                  | j                  |   |      }nm|d   }t        j                  ||      }t        j                  || j                        }t!        |||| j                  | j                  | j                  ||       | j                  |||f|d	      S )
z@Index along the major axis where idx is a slice object.
        Nr   r)   r]   r   r"  r3   Fr   )slicer1   rD   r-   r:   rE   ranger   r*   r9   rA   rB   r#  rI   r;   r   r   )rP   r$  r1   rR   rS   startstopr  r%  start0stop0start1stop1r&  rT   r'  all_idxr(  r)  rp   s                       r[   r  z_cs_matrix._major_slice  s    %+"&499;0D0zz$**%1KKNtTeT4()JJ1v&	6>>)4::>>> t2:%1*E	4!8++fU4/0KKuT)*+LL&&	XXac3

		'z!"~.19DKK.D0ABG((4<<#8tDKxx		' 2>HR.C((3i8Kxx4::6H%tT[[$,,))[(< ~~xjA$-E  ; 	;re   c           
         | j                  | j                  | j                  f      }| j                  j                  |d      }| j                  j                  |d      }t	        j
                  ||      j                         }| j                  | j                        \  }}t        |      }| j                  ||f      }|dk(  r| j                  || j                        S t	        j                  ||      }	t	        j                  | j                  |      }
t        |||||||	|
       t	        j                  |      j                  |d      }|
d   }t	        j                   ||      }t	        j                   || j                        }t#        ||	t        | j                        || j$                  ||       | j                  |||
f|d      S )zBIndex along the minor axis where idx is an array of ints.
        Fr3   r)   r   r]   r   )r?   r:   r9   rN   rA   rK   r   rD   r-   rE   r   r*   rB   
empty_liker   argsortr   r   r;   )rP   r$  rT   r:   r9   rR   rS   r   r%  col_offsetsr'  	col_orderrp   r(  r)  s                  r[   r  z_cs_matrix._minor_index_fancy  s    ))4<<*EF	,,%%ie%<##IE#:jjI.446zz$**%1HJJ1v&	6>>)4::>>> hhq	2]]4;;i@
		
 JJsO**95*A	nhhs)488Ctzz2)[#dll2C!499k8	E~~xjA$-E  ; 	;re   c                    |t        d      k(  r|r| j                         S | S | j                  | j                        \  }}|j	                  |      \  }}}t        t        |||            }|dk(  r.| j                  | j                  ||f      | j                        S |dk(  r| j                  ||      S | j                  t        j                  |||            S )z@Index along the minor axis where idx is a slice object.
        Nr   r)   r   )r  r1   )r+  r1   rD   r-   r:   rE   r,  r   r*   r  r  rA   r   )rP   r$  r1   rR   rS   r-  r.  r  s           r[   r  z_cs_matrix._minor_slice"  s     %+"&499;0D0zz$**%1KKNtTeT4()6>>$**aV"4DJJ>GG19&&St&<<&&ryyd'CDDre   c                    | j                  | j                        \  }}t        ||      \  }}t        ||      \  }}	|dk(  r#|dk(  r||k(  r|	|k(  r|r| j                         S | S t	        ||| j
                  | j                  | j                  ||||		      \  }
}}| j                  ||z
  |	|z
  f      }| j                  |||
f|| j                  d      S )zbReturn a submatrix of this matrix.

        major, minor: None, int, or slice with step 1
        r   F)r-   r*   r1   )
rD   r-   _process_slicer1   r   r9   r:   r;   r   r*   )rP   r  r  r1   rR   rS   i0i1j0j1r9   r:   r;   r-   s                 r[   r  z_cs_matrix._get_submatrix2  s    
 zz$**%1q)Bq)B7rQw27rQw"&499;0D0 1q$++t||TYYBB!H 

BGR"W-.~~tWf5U$(JJU  < 	<re   c                 V    | j                  ||f      \  }}| j                  |||       y r  rD   	_set_manyrP   rg   r   rt   ri   js         r[   _set_intXintz_cs_matrix._set_intXintE  (    zz3*%1q!Qre   c                 V    | j                  ||f      \  }}| j                  |||       y r  rA  rC  s         r[   _set_arrayXarrayz_cs_matrix._set_arrayXarrayI  rF  re   c                 R    | j                   | j                  ||f        |j                  \  }}|dk7  xr |j                  d   dk(  }|dk7  xr |j                  d   dk(  }|j                  |j                  }	}t        j                  |j                  | j                        }|j                  dk(  ry |r^t        j                  t        j                  |      t        |            }t        j                  |	|      }	t        j                  ||      }|r^t        j                  ||      }t        j                  t        j                  |      t        |	            }	t        j                  ||      }| j                  |||	f   |||	f   f      \  }
}| j                  |
||       y )Nr   r   r)   )
_zero_manyrD   r-   rg   r   rA   rK   r;   r*   r   r   r   rE   r   rB  )rP   rg   r   rt   rR   rS   broadcast_rowbroadcast_colrcri   rD  s               r[   _set_arrayXarray_sparsez"_cs_matrix._set_arrayXarray_sparseM  sF   S#J/0yy1Q21771:?Q21771:?uuaee1JJqvvTZZ066Q;		"))A,A/A1A1A		!QA		!c!f-A		!QAzz3q!t9c!Q$i011q!Qre   c           
          d| j                   v ry | j                   \  }}|j                  dk(  }|dk  r|rt        ||z   |      }nt        ||z   |t        |            }t	        j
                  | ||z
  | j                  j                        }t	        j
                  || j                  j                        }n|rt        |||z
        }nt        |||z
  t        |            }t	        j
                  || j                  j                        }t	        j
                  |||z   | j                  j                        }|s|d t        |       }t	        j                  t	        j                  || j                              j                         }	|	j                         j                   |j                         j                   k7  r t	        j                  |	|j                         }	|	j                  dk(  ry | j                  ||f      \  }}| j                  ||f      \  }}|	j                  }
t	        j                  |
| j                  j                        }t!        ||| j"                  | j                  |
|||      }|dk(  r6| j%                          t!        ||| j"                  | j                  |
|||       d|vr|	| j&                  |<   y |dk  }|j)                         | j*                  dz  k  r9||   }||   }| j-                  |||	|          | }|	|   | j&                  ||   <   y | j/                         }|j1                  ||       |j3                  | j                        }|\  | _        | _        | _        }y )Nr   r)   r   r]   gMbP?)r-   rM   rq   rE   rA   r   r:   r*   
atleast_1drK   r   squeezebroadcast_tor   rD   r   r   r9   rH   r;   r  rp   _insert_manyr   _setdiagrG   )rP   valuesr   rR   rS   	broadcast	max_indexri   rD  rt   	n_samplesoffsetsr   maskrU   rV   rc   s                    r[   rU  z_cs_matrix._setdiagf  s   

?zz1[[A%	q5AqM	Aq#f+6			1"i!m4<<3E3EFA		)4<<+=+=>A 1q5M	1q5#f+6			)4<<+=+=>A		!Q]$,,2D2DEAGSV_FMM"**V4::>?EEG99;		 1 11177+A66Q;zz1a&!1zz1a&!1FF	((9DLL,>,>? At{{DLL)!"Aw0!8!q!T[[$,,	 !W.W!"DIIg2 88:5(($A$AaAdG,5D'(wDIIgdm$ **,CLL#++DJJ7F6<3DKty!re   c                    | j                  | j                        \  }}d }t        j                  t        j                  || j
                  j                              j                         }t        j                  t        j                  || j
                  j                              j                         } |||        |||       ||||fS )Nc                     | j                         }||k\  rt        d||fz        | j                         }|| k  rt        d||fz        y )Nzindex (%d) out of range (>= %d)zindex (%d) out of range (< -%d))r@   
IndexErrorrq   )r:   boundr$  s      r[   check_boundsz1_cs_matrix._prepare_indices.<locals>.check_bounds  se    ++-Ce| !B"%u". / /++-CeV| !B"%u". / / re   r)   )rD   r-   rA   rQ  rK   r:   r*   r   )rP   ri   rD  rR   rS   r`  s         r[   _prepare_indicesz_cs_matrix._prepare_indices  s    zz$**%1	/ MM"**Qdll.@.@ABHHJMM"**Qdll.@.@ABHHJQQ!Qzre   c           
         | j                  ||      \  }}}}t        j                  t        j                  || j                              j                         }|j                  }t        j                  || j                  j                        }t        ||| j                  | j                  ||||      }|dk(  r6| j                          t        ||| j                  | j                  ||||       d|vr|| j                  |<   yt        dj                  | j                        t        d       |dkD  }	||	   | j                  ||	   <   |	 }	||	   }||dk  xx   |z  cc<   ||	   }||dk  xx   |z  cc<   | j!                  ||||	          y)	zSets value at each (i, j) to x

        Here (i,j) index major and minor respectively, and must not contain
        duplicate entries.
        r)   r   r]   NzZChanging the sparsity structure of a {}_matrix is expensive. lil_matrix is more efficient.r.   rk   r   )ra  rA   rQ  rK   r*   r   r   r   r:   r   r9   rH   r;   r   r7   r	   rT  )
rP   ri   rD  rt   rR   rS   rY  rZ  r   r[  s
             r[   rB  z_cs_matrix._set_many  sm    **1a0
1aMM"**Qdjj9:@@BFF	((9DLL,>,>? At{{DLL)!"Aw0!8!q!T[[$,,	 !W. W!"DIIg  228&2E(Q8 R<D'(wDIIgdm$5D$Aa!eHMH$Aa!eHMHaAdG,re   c           
         | j                  ||      \  }}}}t        |      }t        j                  || j                  j
                        }t        ||| j                  | j                  ||||      }|dk(  r6| j                          t        ||| j                  | j                  ||||       d| j                  ||dkD     <   y)zSets value at each (i, j) to zero, preserving sparsity structure.

        Here (i,j) index major and minor respectively.
        r)   r   r   r]   N)
ra  rE   rA   r   r:   r*   r   r9   rH   r;   )rP   ri   rD  rR   rS   rY  rZ  r   s           r[   rJ  z_cs_matrix._zero_many  s    
 **1a0
1aF	((9DLL,>,>? At{{DLL)!"Aw0!8!q!T[[$,,	 !W. ,-		''B,'(re   c           	         t        j                  |d      }|j                  |d      }|j                  |d      }|j                  |d      }| j                  }| j	                  | j
                  | j                  f| j                  d   |j                  z         }t        j                  | j                  |      | _        t        j                  | j
                  |      | _        t        j                  ||      }t        j                  ||      }g }g }t        j                  |d	      \  }	}
t        j                  |
t        |            }
t        j                  |
      }d
}t        t        |	|
|
dd             D ]  \  }\  }}}| j                  |   }| j                  |   }|j                  | j
                  ||        |j                  | j                  ||        t        j                  ||| ddd   d	      \  }}t        |      ||z
  k(  r)|j                  |||        |j                  |||        nH|j                  ||| ddd   |          |j                  ||| ddd   |          t        |      ||<   |} | j                     }|j                  | j
                  |d        |j                  | j                  |d        t        j                   |      | _        t        j                   |      | _        t        j"                  | j                  j$                  |      } |d
      |d
<   t        j                  | j                        }||	xx   |z  cc<   ||dd t        j&                  ||      | _        |rd| _        | j)                          | j+                  d       y)a:  Inserts new nonzero at each (i, j) with value x

        Here (i,j) index major and minor respectively.
        i, j and x must be non-empty, 1d arrays.
        Inserts each major group (e.g. all entries per row) at a time.
        Maintains has_sorted_indices property.
        Modifies i, j, x in place.
        	mergesort)rm   clip)moder]   r&   r)   T)return_indexr   r   Nr"  Fr4   )rA   r6  takehas_sorted_indicesr?   r:   r9   r   rK   uniqueappendrE   ra   	enumeratezipr;   concatenater   r-   r#  sort_indicesrO   )rP   ri   rD  rt   r   do_sortrT   indices_parts
data_partsui	ui_indptrnew_nnzsprevrN  iijsjer-  r.  uj	uj_indptrnnzsindptr_diffs                          r[   rT  z_cs_matrix._insert_many  s<    

1;/FF5vF&FF5vF&FF5vF&)) ))4<<*E,0KKOaff,D * G	jjI>zz$,,i@JJq	*JJq	* 
		!$7IIIiQ0	779%(RIabM)JK 	OA|BKK%E;;r?D  eD!9:diid34 IIa2httn4HMB	2w"r'!$$Qr"X.!!!Br(+$$Qr"Xdd^I%>?!!!Br(4R4.";<!"gD#	( BT\\%&12$))EF+, ~~m4NN:.	xx));A,Qggdkk*B8#QRii$/&+D#U+re   c                    | j                  | j                        \  }}| j                  }t        j                  t        |      | j                  j                        }t        j                  || j                  |       | j                  ||f      }| j                  | j                  |f| j                  || j                        S )Nr)   r0   )rD   r-   r:   rA   r   rE   r*   r   	expandptrr9   rF   r;   )rP   r1   rY   rZ   minor_indicesmajor_indicescoordss          r[   r   z_cs_matrix.tocooB  s    #zz$**5	9]!34<<;M;MNy$++}E]M:;""YY$djj # 
 	
re   c                    ||| j                  d      d   }| j                  ||      }|j                  j                  s!|j                  j                  st        d      |j                  j                  r| j                         }|}n| j                         }|j                  }|j                  |j                        \  }}t        |||j                  |j                  |j                  |       |S )Ncfr   z&Output array must be C or F contiguous)rD   _process_toarray_argsr   r   f_contiguousrJ   tocsrr   r   r-   r   r9   r:   r;   )rP   r   r   rt   r   rR   rS   s          r[   r   z_cs_matrix.toarrayO  s    ;5=JJt$Q'E((4		&&#))*@*@EFF99!!

AA

AAwwqww1Aq!((AIIqvvq9
re   c                     | j                  | j                        \  }}t        j                  ||| j                  | j
                  | j                         | j                          y)z\Remove zero entries from the array/matrix

        This is an *in place* operation.
        N)rD   r-   r   csr_eliminate_zerosr9   r:   r;   ro   rP   rR   rS   s      r[   rw   z_cs_matrix.eliminate_zerosf  sH    
 zz$**%1((At{{DLL)-	4

re   returnc                    t        | dd      sd| _        | j                  S t        | d      sOt        t	        j
                  t        | j                        dz
  | j                  | j                              | _	        | j                  S )aZ  Whether the array/matrix has sorted indices and no duplicates

        Returns
            - True: if the above applies
            - False: otherwise

        has_canonical_format implies has_sorted_indices, so if the latter flag
        is False, so will the former be; if the former is found True, the
        latter flag is also set.
        _has_sorted_indicesTF_has_canonical_formatr   )
r   r  r  boolr   csr_has_canonical_formatrE   r9   r:   has_canonical_formatrP   s    r[   r  z_cs_matrix.has_canonical_formatp  s{     t2D9).D& ))) 67(,55$q($++t||E)D% )))re   r  c                 8    t        |      | _        |rd| _        y y )NT)r  r  rj  rP   r  s     r[   r  z_cs_matrix.has_canonical_format  s    %)#Y"&*D# re   c                    | j                   ry| j                          | j                  | j                        \  }}t	        j
                  ||| j                  | j                  | j                         | j                          d| _         y)zfEliminate duplicate entries by adding them together

        This is an *in place* operation.
        NT)
r  rp  rD   r-   r   csr_sum_duplicatesr9   r:   r;   ro   r  s      r[   rH   z_cs_matrix.sum_duplicates  sj    
 $$zz$**%1''1dkk4<<(,			3 	

$(!re   c                     t        | d      sOt        t        j                  t	        | j
                        dz
  | j
                  | j                              | _        | j                  S )zWhether the indices are sorted

        Returns
            - True: if the indices of the array/matrix are in sorted order
            - False: otherwise
        r  r   )r  r  r   csr_has_sorted_indicesrE   r9   r:   r  r  s    r[   rj  z_cs_matrix.has_sorted_indices  sV     t23'+33$q($++t||E(D$ '''re   c                 $    t        |      | _        y r  )r  r  r  s     r[   rj  z_cs_matrix.has_sorted_indices  s    #'9 re   c                 F    | j                         }|j                          |S )z?Return a copy of this array/matrix with sorted indices
        )r1   rp  )rP   As     r[   sorted_indicesz_cs_matrix.sorted_indices  s     IIK	re   c                     | j                   sTt        j                  t        | j                        dz
  | j                  | j
                  | j                         d| _         yy)z9Sort the indices of this array/matrix *in place*
        r   TN)rj  r   csr_sort_indicesrE   r9   r:   r;   r  s    r[   rp  z_cs_matrix.sort_indices  sL     &&))#dkk*:Q*>*.,,		C&*D# 're   c                    | j                  | j                        d   }t        | j                        |dz   k7  rt	        d      t        | j
                        | j                  k  rt	        d      t        | j                        | j                  k  rt	        d      t        | j
                  d| j                         | _        t        | j                  d| j                         | _        y)z8Remove empty space after all non-zero elements.
        r   r   z index pointer has invalid lengthz)indices array has fewer than nnz elementsz&data array has fewer than nnz elementsN)	rD   r-   rE   r9   rJ   r:   rp   r;   r   )rP   rY   s     r[   ro   z_cs_matrix.prune  s     JJtzz*1-	t{{y1},?@@t||txx'HIItyy>DHH$EFF#DLL$(($;< 9DHH!56	re   c                    t        |      }t        | d      r| j                  \  }}t        |d   |      \  }}t        |d   |      \  }}|s|r%t	        dj                  | j                  |            | j                  d   |z  | j                  d   |z  }	}n2| j                  |      \  }}| j                  | j                        \  }}	||k  rZ| j                  d | j                  |    | _        | j                  d | j                  |    | _
        | j                  d |dz    | _	        n[||kD  rVt        j                  | j                  |dz         | _	        | j                  |dz   d  j                  | j                  |          ||	k  r| j                  |k  }
t        j                  |
      s| j                  |
   | _        | j                  |
   | _
        | j                  t        j                   |
      \  }}| j                  j                  d       || j                  dd  |<   t        j"                  | j                  | j                         || _        y )Nr   r   r   z.shape must be divisible into {} blocks. Got {}r"  )r!   r  r   divmodrJ   r7   r-   rD   r:   r9   r;   rA   resizer   allr  r  r#  r<   )rP   r-   bmbnnew_Mrmnew_NrnrR   rS   r[  r  r  s                r[   r  z_cs_matrix.resize  s   E"4%^^FBuQx,IE2uQx,IE2R  "**0&*GI I::a=B&

1(;qA::e,LE5::djj)DAq19<<(;U);<DL		"54;;u#56DI++juqy1DKQY))DKK;DKKKA$$T[[^419<<%'D66$<#||D1 IIdO	#'#5#5bffd#C S  #/2AB,		$++4;;7re   c                 :   |r[| j                  || j                  j                         | j                  j                         f| j                  |j
                        S | j                  || j                  | j                  f| j                  |j
                        S )zReturns a matrix with the same sparsity structure as self,
        but with different data.  By default the structure arrays
        (i.e. .indptr and .indices) are copied.
        r,   )r   r:   r1   r9   r-   r*   )rP   r;   r1   s      r[   rv   z_cs_matrix._with_data  s    
 >>4):):)<#';;#3#3#5#7(,

(,

 " 4 4
 >>4t{{"C(,

$** " F Fre   c                 N   | j                  |      }t        t        | j                  |z   | j                  z         }| j                  |j                  z   }| j                  | j                  | j                  |j                  |j                  f|      }t        j                  | j                  j                  |      }t        j                  ||      }g d}||v r&t        j                  |t        j                        }	n5t        j                  |t        | j                  |j                              }	 || j                  d   | j                  d   t        j                  | j                  |      t        j                  | j                  |      | j                  t        j                  |j                  |      t        j                  |j                  |      |j                  |||	       | j                  |	||f| j                        }
|
j!                          |
S )z5apply the binary operation fn to two sparse matrices.r&   r)   )r}   r   r   r   r   r   r   r   )r   r   r   r7   rp   r?   r9   r:   rA   r   r-   r   r   r*   rK   r;   ro   )rP   rx   ry   r   maxnnzrT   r9   r:   bool_opsr;   r  s              r[   r   z_cs_matrix._binopt  s   u% \4;;#3dkk#ABEII%))4;;%*\\5==+B+1 * 3	 $++++9=((63;>88F"((3D88F&U[[*IJD
4::a=$**Q-::dkk3::dll)499::ell)4::emm95::7D	" NND'62$**NE		re   c                 *   |j                   | j                   k7  rt        d      | j                  |d      }t        j                  |j
                  t        j                        rt        j                  | j                   | j
                        }|j                  t        j                         |j                         \  }}d|||f<   |j                         }|j                  ||j                  |j                  f<   | j                  |      }|S |}|S )z?
        Divide this matrix by a second sparse matrix.
        r   _eldiv_r)   r   )r-   rJ   r   rA   
issubdtyper*   inexactr   r   nannonzeror   r;   rg   r   r   )rP   rx   rM  r   rg   r   s         r[   _divide_sparsez_cs_matrix._divide_sparse.  s     ;;$**$233LL	*=="**-
 ((4::TZZ8CHHRVV}}HCCSM	A !Cquu//#&C
 
 C
re   )NNFr  )T)r   )NNN)F)NN)>__name__
__module____qualname____doc__r6   rd   r   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  rE  rH  rO  rU  ra  rB  rJ  rT  r   r   rw   propertyr  r  setterrH   rj  r  rp  ro   r  rv   r   r  r   re   r[   r$   r$      s8   V,p3 oo--GO;-N""H "D!"F9988	3-.rp"EH	 ''//H9.O oo--GOO oo--GOF6 ++%%CK"4*<8H
;B&;P%;NE <&   2@=D&%-N-(F,X	
 MM))EM" oo--GO *d * *,   + + !+
)  (D ( ( -d - -+7 D ^^++FNF Dre   r$   c                 ,   | d|}}||fS t        | t              r5| j                  |      \  }}}|dk7  rt        d      t	        ||      }||fS t        |       r0| dk  r| |z  } | | dz   }}|dk  s||kD  rt        d|||fz        ||fS t        d      )Nr   r   z$slicing with step != 1 not supportedz'index out of bounds: 0 <= %d < %d <= %dzexpected slice or scalar)r=   r+  r:   rJ   rq   r   r^  r   )slnumr<  r=  strides        r[   r;  r;  J  s    	zCB  r6M 
B	CBQ;CDDR[ r6M 
26#IBR!VB6R#XF "c]+ , ,
 r6M 233re   )-r  __all__warningsr   r   numpyrA   scipy._lib._utilr   r   _baser   r   r	   r
   _datar   r    r   r   r   r   r   r   r   r   r   _indexr   _sputilsr   r   r   r   r   r   r   r   r   r    r!   r"   r$   r;  r   re   r[   <module>r     sl    D
    9 F F . A A A G G G G
q}j qh)re   