L i dZgZddlmZddlZddlZddlmZm Z ddl m Z m Z m Z mZddlmZmZddlmZdd lmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$dd l%m&Z&dd l'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2Gd d eee&Z3ddZ4dZ5y)z>Base class for sparse matrix formats using compressed storage.)warnN) _prune_arraycopy_if_needed)_spbaseissparsesparraySparseEfficiencyWarning) _data_matrix _minmax_mixin) _sparsetools)get_csr_submatrixcsr_sample_offsets csr_todensecsr_sample_values csr_row_index csr_row_slicecsr_column_index1csr_column_index2 csr_diagonal expandptrcsr_has_canonical_formatcsr_eliminate_zeroscsr_sum_duplicatescsr_has_sorted_indicescsr_sort_indicescsr_matmat_maxnnz csr_matmat) IndexMixin) upcast upcast_char to_nativeisshapegetdtype isintlikedowncast_intp_index get_sum_dtype check_shapeget_index_dtypebroadcast_shapesc4eZdZdZd6dddZd7dZej je_d7dZejje_d8dZdZ d Z d Z d Z d Z d ZdZdZd9dZej"je_d:dZej$je_d7dZdZdZdZdZdZd;dZdZd;dZd6dZdZdZdZdZ d Z!d!Z"d"Z#d#Z$d8d$Z%ejJje%_dj@d| t)jB|}t|tFr7|jHdk7r(|jdk(rt=d|jHd|jHdkDrt=d|jHd|j3||} | j5|j} | \|_|_|_|_ |t||j|_ no|j&c t1|j dz }|jj%dz}t|j||f|j|_ |-t-|}|jjK|d|_|jMdy#tD$r+}t=d|j>j@d||d}~wwxYw#tD$r}t=d|d}~wwxYw)Nr-allow_ndmaxvalr)defaultrdtypeshaper6T)r3check_contentscopyr6z unrecognized z constructor input: csczCSC arrays don't support zD input. Use 2DzCSR arrays don't yet support zD.z!unable to infer matrix dimensionsFr= full_check)'r __init__rformatr=asformatindptrindicesdata_shape isinstancetupler# _allow_ndr(_swap _shape_as_2d_get_index_dtypemaxr9npzerosr$floatlen_coo_container_coo_to_compressedsum_duplicatesrarray ValueError __class____name__asarray Exceptionr ndimastype check_format)selfarg1r9r6r=r.MN idx_dtypecooarraysrGrFrEr3enewdtypes ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/sparse/_compressed.pyrBz_cs_matrix.__init__s dD8< D>{{dkk)dyy{}}T[[1 T\\499dkkA =DKty$+e $tdnn5*$H zz$"3"341!11TZZ1I HHQ(FG !xx95  hhq1uI> t9>--d%u-MC 33DJJ?FHNEDKty$+'')Y!^.2+T7F"F(Qe^!$U $ 5 5w6G7=?C!6!EI -#%88G$i#PDL"$((6I"NDK "D FDI$}T^^5L5L4MN;;?&&BCC  Fzz$'$(TYY!^ u@T #>RDK  H (((>DI U+; F =1H1H0IJ77;f">?DEF F( M !DE1L Ms0Q+5R"+ R4&RR" R<+ R77R<c|t|jdS|jdk(r'|dvrt|jdStd|dkr|dz }|j |d|z f\}}|j |j \}}|dk(r*t jt|j|S|dk(rt j|jStd)Nrrrkaxis out of boundsrr7 minlength) intrEr]rXrLr9rPbincountr&rFdiff)r`axis_rcs ri_getnnzz_cs_matrix._getnnzvs <t{{2' ' YY!^w4;;r?++12 2ax jj$D!12GD!::djj)DAqqy{{#6t||#DPQRRwwt{{++12 2c |j|tj|jS|jdk(r.|dvr t dtj|jS|dkr|dz }|j |d|z f\}}|dk(rx|j |j\}}|jdk7}|jr |jn|j|}tjt||S|dk(r|jjrtj|jStj|j}tj |Dcgc]'\}}tj|j||)c}}St dcc}}w)Nrrlrmrr7rn)rVrP count_nonzerorGr]rXrLr9allrFrqr&rrrE itertoolspairwiserW) r`rsrtrcmaskidxpairsijs rirxz_cs_matrix.count_nonzerosd  <##DII. . 99>7" !566##DII. . !8 AID**dAH-.a 19::djj)DAq99>D"&((*$,,$,,t2DC;;2371E E QYyy}}wwt{{++&&t{{3E88%P$!QR--dii!n=PQ Q12 2Qs,F? c:|jjjdk7r/td|jjjdd|j jjdk7r/td|j jjdd|j j|j j|jjfD]}|dk7s td|j|j\}}t|j|dzk7r'td t|jd |dz|jd d k7r td t|j t|j k7r td |jdt|j kDr td|j|r+|jd kDr|j j|k\rtd||j jd kr tdt!j"|jjd kr td|j%|j|j f}t!j&|j||_t!j&|j ||_t)|j |_yy)aCheck 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`. rz$indptr array has non-integer dtype ()r: stacklevelz%indices array has non-integer dtype (rz'data, indices, and indptr should be 1-Dzindex pointer size z should be rz!index pointer should start with 0z*indices and data should have the same sizerkzQLast value of index pointer should be less than the size of index and data arrayszindices must be < zindices must be >= 0z(indptr must be a non-decreasing sequencer5N)rEr6kindrnamerFrGr]rXrLrMrSprunennzrOminrPrrrNr[r")r`rAxrbrcrds rir_z_cs_matrix.check_formats ;;   ! !S ( 7 8I8I8N8N7OqQ  <<   " "c ) 89K9K9P9P8QQRS ))..$,,"3"3T[[5E5EF LAAv !JKK L zz$++,1  A %23t{{3C2DKPQTUPUwWX X KKNa @A A  TYY /IJ J KKOc$,,/ /AB B xx!|<<##%*$'9!%=>><<##%)$%;<<774;;'++-1$%OPP--t{{DLL.IJI**T[[ BDK::dll)DDL!$)),DI rvc|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. Tr?)rV _with_datarGeliminate_zeros)r`otheropress ri_scalar_binoptz_cs_matrix._scalar_binopts> oobE2o>  rvcH|j|jk7r&td|jd|jdt|jj|jj}|j dd}t j|||d}|jjr|n |j}|j |j\}}t|||j|j|j||j!|d S) NzIncompatible shapes ( and rCFrT)r6orderr=Fr?)r9rXr!r6charrLrPrWflags c_contiguousTrMrrErFrG _container)r`rr6rresultyrbrcs ri _add_densez_cs_matrix._add_denses ;;$** $4TZZLekk]RSTU UDJJOOU[[-=-=> 4 #%uEEll//FVXXzz$++,1Aq$++t||TYYBvE22rvc&|j|dS)N_plus__binoptr`rs ri _add_sparsez_cs_matrix._add_sparses||E8,,rvc&|j|dS)N_minus_rrs ri _sub_sparsez_cs_matrix._sub_sparses||E9--rvct|r|j|jk(r#|j|}|j|dS|jdk(rS|j |j d}|j dk(r |jd|jdfS|S|jdk(r"|j |j dS|jdvr)|j |jjS|j\}}|j\}}|dk(r4|dk(r/|j|j||jS|dk(r4|dk(r/|j|j||jSt|t}|dk(rb||k(r]t|j j!|}|j|}|j dk(r|S|jd|fS|dk(r>||k(r9t|j j!|} |j| S|dk(r>||k(r9t|j j!|}|j|S|dk(r>||k(r9t|j j!|} | j|St#d |jd |jt%j&|}|j dkDr$t%j(|j |S|j*dk(rp|j,t$j.k(rt0St3|j|j} |j |j4dj| S|jdvr]t3|j|j} t%j(|jj|j| S|j7} |j|jk(rat%j(| j|| j8} | j;t$j<j!| _| St%j>|}|jddk(s|j dk(r|jddk(r!t%j(| j|} nv|jd|jd k(r2t%j(| j|d d | j@f} n%t#d |jd |j|jC| j@| jD|jdz }t%jFt%jH|jd|| jD}t%jJ| j@jM|d|jd}|jO| j;t$j<j!||ff|jd|jd fdS|jddk(r|jddk(r(t%j(| jd d d f|} ny|jd|jdk(r5t%j(| jd d d f|| jP} n%t#d |jd |j|jC| jP| jD|jdz }t%jF| jPjM|d|jd}t%jJt%jH|jd|| jD}|jO| j;t$j<j!||ff|jd|jdfdS|jddk(r_|jd|jdk(r@t%j(| j|d d | j@fj!} n|jddk(r[|jd|jdk(r!>>1djjm*<== {{d"'' (:;;zz^+((99&&FB''FBQw27++DLLR,@,F,F,HIIQw27**5==R+@+F+F+HII!$0HQw28.u}}/D/D/FQ ,,Y7!%avLV^^QG5LLQw28)$,,.*>*>*@(K++D11Qw28.u}}/D/D/FQ  //55Qw28-dlln.B.B.DhO..u553DJJ;;t||~u5 5 ::?{{bjj(%%%djj%++>F##EJJqM2::6B B :: '%djj%++>F;;tyy}}6>>vF Fjjl :: $;;sxxszz):;Dyy,224CHJ--& ::a=A a}}Q1${{388W5q!TZZ^3{{388WQZ-@A #7 |5 !VWW--cgg58WWw}}Q?O5O.QI))BIIgmmA&6iH#''RC''#''...?qAQRC&&2::&,,.c ;}}Q'B8'  ::a=A }}Q1${{388AtG#4g>q!TZZ]2{{388AtG#4gcgg6FG #7 |5 !VWW--cgg58WWw}}Q?O5O.QI))CGGNN95NA7==QRCSTC''"))GMM!$4IFPC&&2::&,,.c ;zz!}gmmA&67'  == q TZZ]gmmA6F%F;;sxxCGG)<)B)B)DED ]]1  "tzz!} a8H'H;;sxx)9)?)?)ABD3DJJ>>6), , rvc |j\}}|j}|dk(r*|jd|jdfj}|jdk(r |j n|jddf\}}d}|jdk(r||fz }|dk(r||fz }|jdk(r|nd|dk(r|ndf}|j |}|j|j|j|jf} |j||f\}}|j||f\} } |j| } tj| j| } tj| j| }tj| j| }tj| j| }t||| |||}|dk(rk|dk(r5tjdt|j |j S|j |t|j |j S|j| |}|| k7r|} tj| j| } tj| j| }tj| j| }tj| j| }tj"|dz| }tj"|| }tj"|t|j |j }t%||| || j&||| j&||| |dk(rtj|dS|j |||f|}||k7r0|j(dk7r|j+}|j|}|S) Nrrr7r5r2r9csr)rMr]rr9rrHrYrErFrLrNrPr[rrWr r6emptyrrGrCtocsr)r`rrbK1o_ndimK2rc new_shape faux_shape index_arrayssords_indptr s_indiceso_indptr o_indicesr new_idx_dtyperErFrGrs rirz_cs_matrix._matmul_sparses!!2 Q;MM1ekk!n"5688E % a ekk!na5HA 99> ! I Q; ! I99>aqv{!J u% T\\5<<O zz1a&!1zz4-(1)),7 ::ahhi8JJqyy : ::ahhi8JJqyy : 1h 8YO !8Bxx EKK)HII>>)6$**ekk3R>S S--l3-G I %%Izz!(()Izz!(()I!a%y1((3i0xx6$**ekk#BC1aYY7D * ?88DG$ $nndGV4JnG  "zzU"iik++i(C rvc |j|j\}}|j|| f\}}|| ks||k\r+tjd|jj Stjt |t |dz|t|dz t|j }t||||j|j|j||S)Nrr5) rLr9rPrrGr6rrOr rrErF)r`krbrcrtrs ridiagonalz_cs_matrix.diagonalszz$**%1zz1qb'"1 7a1f88ATYY__5 5 HHSSAYC1I 6fTZZ>P QQ1dkk4<<AFrvc|jdk(rt|ds||jddvrt|j}t j t|jdz |}|jt j\}}|||<|j|}|dzdk(r |j}|jd||Stj||||S) zSum the array/matrix over the given axis. If the axis is None, sum over both rows and columns, returning a scalar. r7 blocksize))rrk)rrrr5r)rsr6out)r]hasattrrLr'r6rPrQrSrE _minor_reduceadd _ascontainerrrr)r`rsr6r res_dtyper major_indexvalues rirz_cs_matrix.sums IIN74#= #56q99%djj1I((3t{{+a/yAC!%!3!3BFF!; K$C ##C(Cax1}ee77%S79 9;;t$eE Ervc| |j}tjtj|j}|j |t |j|}||fS)aReduce 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 )rGrP flatnonzerorrrEreduceatr&)r`ufuncrGrrs rirz_cs_matrix._minor_reducesZ <99DnnRWWT[[%9: t24;;{3KLNE!!rvc |j|j\}}|j||f\}}t|||j|j|j ||dz||dz \}}} | j |jS)Nrr5)rLr9rrErFrGrr6) r`rrrbrcmajorminorrErFrGs ri _get_intXintz_cs_matrix._get_intXints~zz$**%1zz3*- u 1 q$++t||TYY 519eUQY!0xxdjjx))rvc|j||f\}}|jdvr"|jdvr|j||dS|j|j |S)NrNTr?)rLstep_get_submatrix _major_slice _minor_slicer`rrrrs ri_get_sliceXslicez_cs_matrix._get_sliceXslice&sczz3*- u :: "uzzY'>&&ue$&? ?  '44U;;rvc |jj}|j|j\}}|j||f\}}t j ||}t j ||}t j |j|j}t|||j|j|j|j|j|j| |jdk(r|j|S|j|j|jS)Nr5r)rFr6rLr9rPr[rrrrErGrr]rrYr) r`rrrdrbrcrrvals ri_get_arrayXarrayz_cs_matrix._get_arrayXarray,sLL&& zz$**%1zz3*- u 5 2 5 2hhuzz4!Q T\\499**ekkmU[[]C I ::?$$S) )~~ckk%++677rvcn|j||f\}}|j|j|SN)rL_major_index_fancy_minor_index_fancyrs ri_get_columnXarrayz_cs_matrix._get_columnXarray;s4zz3*- u&&u-@@GGrvc |j|j|jf}tj||j }|j |jd}t|}|jdk(r|j ||fn|f}|dk(r|j||jS|j|dz|j|z j|}tj|dz|}tj||dd|d} tj| |} tj| |j} t!|||jj|d |jj|d |j"| | |j| | |f|d S) zBIndex along the major axis where idx is an array of ints. r5rr7rNrrkFr?r)rNrErFrPr[rrLrMrSr]rYr6r^rQcumsumrrrG) r`r}rdrFrcrbrrow_nnz res_indptrr res_indicesres_datas rirz_cs_matrix._major_index_fancy@s))4;; *EF **S 288: JJt(( )! , L*.))q.DJJ1v&qd 6>>)4::>> >;;w{+dkk'.BBJJ9UXXa!e95  'z!"~.nhhs)4 88Ctzz2  KK  yu  5 LL     6 II   ~~xjA$-E; ;rvc h|tdk(r|r|jS|S|j|j\}}|j |\}}}t t |||}|jdk(r|j||fn|f}|dk(r|j||jS||} } |dk(r|dk\rd} |dz|dz} } |j| | ||j| | |z } |jj}tj|dz|}tj| |dd|dk(rot|j||j|}tj|j||}tj|j||}nm|d}tj ||}tj ||j}t#||||j|j|j|||j|||f|d S) z@Index along the major axis where idx is a slice object. Nr7rr5rkrrr?Fr)slicer=rLrMrFrSranger]rYr6rErPrQrrWrGrr)r`r}r=rbrcstartstoprrstart0stop0start1stop1rrdrall_idxrrrs rirz_cs_matrix._major_slice`s %+ "&499; 0D 0zz$++,1KKNtT eT4( )*.))q.DJJ1v&qd 6>>)4::>> >t 2:%1*E 4!8++fU4/0 KKuT) *+LL&& XXac3  'z!"~. 19DKK. D0ABG((4<<#8tDKxx ' 2>HR.C((3i8Kxx4::6H %tT[[$,,))[( <~~xjA$-E; ;rvc |j|j|jf}|jj|d}|jj|d}t j ||j }|j|j\}}t|}|jdk(r|j||fn|f}|dk(r|j||jSt j||} t j|j|} t||||||| | t j |j|d} | d} t j"| |} t j"| |j}t%| | t|j||j&| ||j|| | f|dS)zBIndex along the minor axis where idx is an array of ints. Fr?r5r7rrkr)rNrFrEr^rPr[rrLrMrSr]rYr6rQ empty_likerargsortrrrG)r`r}rdrFrErbrcrr col_offsetsr col_orderrrrs rirz_cs_matrix._minor_index_fancys))4<<*EF ,,%%ie%<##IE#:jjI.446zz$++,1 H*.))q.DJJ1v&qd 6>>)4::>> >hhq 2 ]]4;;i@       JJsO**95*A nhhs)4 88Ctzz2)[#dll2C!499k8 E~~xjA$-E; ;rvc|tdk(r|r|jS|S|j|j\}}|j |\}}}t t |||}|dk(r.|j|j||f|jS|dk(r|j||S|jtj|||S)z@Index along the minor axis where idx is a slice object. Nrr5r)rr=) rr=rLrMrFrSrrYr6rrrPr)r`r}r=rbrcrrrs rirz_cs_matrix._minor_slices %+ "&499; 0D 0zz$++,1KKNtT eT4( ) 6>>$**aV"4DJJ>G G 19&&St&< <&&ryyd'CDDrvc |j|j\}}t||\}}t||\}} |dk(r#|dk(r||k(r| |k(r|r|jS|St |||j |j |j|||| \} } } |j||z | |z f} |jdk(r| df} |j| | | f| |jdS)zbReturn a submatrix of this matrix. major, minor: None, int, or slice with step 1 rrF)r9r6r=) rLrM_process_slicer=rrErFrGr]rYr6)r`rrr=rbrci0i1j0j1rErFrGr9s rirz_cs_matrix._get_submatrixs zz$++,1q)Bq)B 7rQw27rQw"&499; 0D 0 1 q$++t||TYYBB!H BGR"W-. 99>1XKE~~tWf5U$(JJU< %&JK Kzz1[[A% q5AqM Aq#f+6  1"i!m4<<3E3EFA )4<<+=+=>A1q5M 1q5#f+6  )4<<+=+=>A !Q]$,,2D2DEAGSV_F MM"**V4::> ? E E G 99;   1 1 1177+A 66Q; zz1a&!1zz1a&!1FF ((9DLL,>,>? At{{DLL)!"Aw0 !8    ! q!T[[$,,  !W . W !"DIIg  1  88dhhj 488e#3 3'(wDIIgdm $5D$A$A   aAdG ,**,C LL #++DJJ7F6< 3DKty!rvc|j|j\}}d}tjtj||j j j}tjtj||j j j}||||||||||fS)Nc|j}||k\rtd|d|d|j}|| krtd|d|dy)Nzindex (z) out of range (>= rz) out of range (< -)rO IndexErrorr)rFboundr}s ri check_boundsz1_cs_matrix._prepare_indices..check_bounds<sc++-Ce| 73%/B5'!KLL++-CeV| 73%/B5'!KLLrvr5)rLrMrPr@r[rFr6r)r`rrrbrcrNs ri_prepare_indicesz_cs_matrix._prepare_indices9szz$++,1 M MM"**Qdll.@.@A B H H J MM"**Qdll.@.@A B H H JQQ!Qzrvc |j||\}}}}tjtj||jj }|j }tj||jj}t|||j|j||||}|dk(r6|jt|||j|j||||d|vr||j|<ytd|jjdt d|dkD} || |j|| <| } || }||d kxx|z cc<|| }||d kxx|z cc<|j#|||| y) zSets value at each (i, j) to x Here (i,j) index major and minor respectively, and must not contain duplicate entries. r5rrkNz%Changing the sparsity structure of a z. is expensive. lil and dok are more efficient.r:rr)rOrPr@r[r6rrrrFrrErVrGrrYrZr rC) r`rrrrbrcrHrIrr|s rir1z_cs_matrix._set_manyJsw **1a0 1a MM"**Qdjj9 : @ @ BFF ((9DLL,>,>? At{{DLL)!"Aw0 !8    ! q!T[[$,,  !W . W !"DIIg   89P9P8QR??(Q 8R,>? At{{DLL)!"Aw0 !8    ! q!T[[$,,  !W .,- ''B,'(rvc tj|d}|j|d}|j|d}|j|d}|j}|j |j |j f|j d|jz}tj|j ||_tj|j ||_tj||}tj||}g}g}tj|d \} } tj| t|} tj| } d } tt| | | d d D] \} \}}}|j | }|j |}|j|j |||j|j||tj|||d d dd \}}t|||z k(r)|j||||j|||nH|j|||d d d||j|||d d d|t|| | <|} |j }|j|j |d |j|j|d tj ||_tj ||_tj"|j j$|}|d |d <tj|j }|| xx| z cc<||d d tj&|| |_|rd|_|j)|j+dy )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)rclip)moderkr2r5T) return_indexrrNrFr@)rPr%takehas_sorted_indicesrNrFrErr[uniqueappendrSrr enumerateziprG concatenaterr9r sort_indicesr_)r`rrrrdo_sortrd indices_parts data_partsui ui_indptrnew_nnzsprevr<iijsjerruj uj_indptrnnzs indptr_diffs rirCz_cs_matrix._insert_manys< 1;/ FF5vF & FF5vF & FF5vF &))))4<<*E,0KKOaff,D*G jjI> zz$,,i@ JJq * JJq *   !$7 IIIiQ0 779%(RIabM)JK OA|BKK%E;;r?D  eD!9 :   diid3 4IIa2httn4HMB 2w"r'!$$Qr"X.!!!Br(+$$Qr"Xdd^I%>?!!!Br(4R4.";<!"g D# ( BT\\%&12$))EF+,~~m4 NN:. xx ));A,Qggdkk* B8#QRii$/ &+D #     U+rvc$|jdk(rE|j}|j|j|jff|j |S|j |j \}}|j}tjt||jj}t||j||j ||f}|j|j|f|j ||jS)Nrr?r5r<) r]rrTrGrFr9rLrPrrSr6rrE)r`r=r major_dim minor_dim minor_indices major_indicesrs rirz_cs_matrix.tocoos 99>**,C&&3;;.'A399SW&X X#zz$**5 9 ]!34<<;M;MN )T[[-8]M:;"" YY $djj#  rvc|||jdd}|j||}|jjs!|jjs t d|jjr|j }|}n|j}|j}|j|j\}}t|||j|j|j||S)Ncfrz&Output array must be C or F contiguous)rL_process_toarray_argsrr f_contiguousrXrrrrMrrErFrG)r`rrrrrbrcs rirz_cs_matrix.toarrays ;5=JJt$Q'E((4 &&#))*@*@EF F 99 ! ! AA AAwwq~~&1Aq!((AIIqvvq9 rvc|j|j\}}t|||j|j|j |j y)z\Remove zero entries from the array/matrix This is an *in place* operation. N)rLrMrrErFrGrr`rbrcs rirz_cs_matrix.eliminate_zerossA zz$++,1Aq$++t||TYYG rvreturnct|ddsd|_|jSt|dsGt|jdz }t t ||j|j|_|jS)aZWhether 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) rr{rrSrEboolrrFhas_canonical_formatr`rbs rir}z_cs_matrix.has_canonical_formatsvt2D9).D & ))) 67DKK 1$A(,(DKKF)D %)))rvr c8t||_|rd|_yy)NT)r|r{rXr`r s rir}z_cs_matrix.has_canonical_formats%)#Y" &*D # rvc|jry|j|j|j\}}t |||j |j |j|jd|_y)zfEliminate duplicate entries by adding them together This is an *in place* operation. NT) r}r^rLrMrrErFrGrrws rirVz_cs_matrix.sum_duplicatessa  $ $  zz$++,11adllDIIF $(!rvct|dsGt|jdz }tt ||j|j |_|j S)zWhether the indices are sorted Returns - True: if the indices of the array/matrix are in sorted order - False: otherwise rzr)rrSrEr|rrFrzr~s rirXz_cs_matrix.has_sorted_indices-sQt23DKK 1$A'+&q$++t||D(D $'''rvc$t||_yr)r|rzrs rirXz_cs_matrix.has_sorted_indices=s#'9 rvcF|j}|j|S)z?Return a copy of this array/matrix with sorted indices )r=r^)r`As risorted_indicesz_cs_matrix.sorted_indicesBs IIK rvc|jsLt|jdz }t||j|j|j d|_yy)z9Sort the indices of this array/matrix *in place* rTN)rXrSrErrFrGr~s rir^z_cs_matrix.sort_indicesMsG&&DKK 1$A Q T\\499 E&*D #'rvc|j|jd}t|j|dzk7r t dt|j |j kr t dt|j|j kr t dt|j d|j |_t|jd|j |_y)z8Remove empty space after all non-zero elements. rrz index pointer has invalid lengthz)indices array has fewer than nnz elementsz&data array has fewer than nnz elementsN) rLrMrSrErXrFrrGr)r`rns rirz_cs_matrix.pruneUsJJt001!4 t{{ y1} ,?@ @ t|| txx 'HI I tyy>DHH $EF F#DLL$(($;<  9DHH!56 rvct||j}t|drw|j\}}t |d|\}}t |d|\}}|s|rt d|jd||j d|z|j d|z} }nG|jt|dkDr|nd|df\}}|j|j\}} ||krZ|jd|j||_ |jd|j||_ |jd|dz|_ n[||kDrVtj|j|dz|_ |j|dzdj|j||| kr|j|k} tj | s|j| |_ |j| |_ |j#tj$| \} } |jjd| |jdd| <tj&|j|j||_y)Nr0rrrzshape must be divisible into z blocks. Got r)r(rKrrdivmodrXr9rLrSrMrFrErGrPresizefillryrrrrH) r`r9bmbnnew_Mrmnew_Nrnrbrcr|rr s rirz_cs_matrix.resizedsEDNN; 4 %^^FBuQx,IE2uQx,IE2R #@@P#0"9::::a=B& 1 (;qA::s5z!|e!U1XOLE5::d//0DAq 19<<(;U);>4):):)<#';;#3#3#5#7(, (, "4 4 >>4t{{"C(, $**"F Frvc .|j|}ttd|zdz}|j|jz}|j |j |j |j |j f|}tj|j j|}tj||}gd}||vr&tj|tj} n5tj|t|j|j} |j|j\} } || | tj|j |tj|j ||j tj|j |tj|j ||j ||| |j| ||f|j} | j#| S)z5apply the binary operation fn to two sparse matrices.rr2r5)_ne__lt__gt__le__ge_r)rYrr rrNrErFrPrr9bool_r r6rLrMr[rGr) r`rrrmaxnnzrdrErFbool_opsrGrbrcrs rirz_cs_matrix._binoptsu%\52:#5 6EII%))4;; %*\\5==+B+1*3 $++++9=((63; >88F"((3D88F&U[[*IJDzz$++,1 1a ::dkk 3 ::dll) 4 99 ::ell) 4 ::emm9 5 :: 7D " NND'62$**N E  rvcb|j|jk7r%td|jd|j|j|d}tj|j tj rtj|j|j }|jtj|j}|jdk(r|df}d||<|j}|j||j<|j|S|}|S)z? Divide this matrix by a second sparse matrix. rr_eldiv_r5rrkr)r9rXrrP issubdtyper6inexactrrnannonzeror]rrGrr)r`rr;rrs ri_divide_sparsez_cs_matrix._divide_sparses ;;$** $3DJJ2D. Got Dc3&K|] }|dk( ywrr).0rs ri z+_cs_matrix._broadcast_to..s)!qAv)s)r9r=r(rKr*rXrSrVrrYr6rPfullrGrrW_csr_containerrMrLryrrFrrE) r`r9r=rcrGrFrE old_shaper]rbrrs ri _broadcast_toz_cs_matrix._broadcast_tos :: "&499; 0D 0ET^^= DJJ .% 723 3 tzz?a CJ!O    !xx1}~~e4::E~JJaA771diil+Dii!nGXXq!f%F&&gv'>eRW&X X%% u:?u:DOPTvUVWX X 88q=>>%tzz>F F zz% 1I&B )y) )771q5$))A,/DggbiilA.GYYq#d)a-3F 1Wq77499a(DggdllA.GYYq#d)a-TYY@F 1Wq99TYY*DggbiilC N;G[[1_F~~tWf5U~OOrv)NNFr)T)r)NNNF)NN)6rZ __module__ __qualname____doc__rBrurrxr_rrrrrrrrrrrrr r rrrrrrr3r6r=rDrOr1r8rCrrrpropertyr|r}setterrVrXrr^rrrrrrrrvrir,r,sV,TV,p3$oo--GO34$1199M7-F 3-.vx 7 ;z''//H F,++%%CK"4*< 8H ;@&;P%;NE <*   2B=H"%-N-(F,X  MM))EM"oo--GO *d**,  ++!+ ) (D ( (-d--+ 7!F^^++FN F!F80Prvr,cddlm}m}|r|n|}t|}t |}t j |dz|}|dd}||||f||fS)zbuild diagonal csc_array/csr_array => self._csr_container Parameter `data` should be a raveled numpy array holding the values on the diagonal of the resulting sparse matrix. r) csr_array csr_matrixr2r5Nrkr)_csrrrrSr)rPr)rGrrrrcrdrErFs rirrsZ ,% :I D Aq)I YYq1uI .FSbkG dGV,QF ;;rvc2|d|}}||fSt|tr5|j|\}}}|dk7r tdt ||}||fSt |r3|dkr||z }||dz}}|dks||kDrt d|d|d|||fStd)Nrrz$slicing with step != 1 not supportedzindex out of bounds: 0 <= z < z <= zexpected slice or scalar)rIrrFrXrr%rL TypeError)slnumr+r,strides rir*r*s zCB r6M B CB Q;CD D R[ r6M 2 6 #IBR!VB 6R#X9"SDNO O r6M233rvr)6r__all__warningsrrznumpyrPscipy._lib._utilrr_baserrr r _datar r r rrrrrrrrrrrrrrrrr_indexr_sputilsr r!r"r#r$r%r&r'r(r)r*r,rr*rrvrirszD 9FF.::::: VVVV rP}jrPj'<"rv