L iQdZddlZddlZddlmZmZmZddlm Z m Z gZ GddeZ eD]!Z e jZdZee eee #d ZGd d Zy) zBase class for sparse matrice with a .data attribute subclasses must provide a _with_data() method that creates a new matrix with the same sparsity pattern as self but with a different data array N)_spbasesparray _ufuncs_with_fixed_point_at_zero) isscalarlike validateaxiscDeZdZdddZedZej dZdZdZddZ d Z d Z d Z d Z d ZddZejj"e_ddZej$j"e_dZej&j"e_ddZdZy) _data_matrixNmaxprintc4tj|||y)Nr )r__init__)selfarg1r s X/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/sparse/_data.pyrz_data_matrix.__init__sth7c.|jjSNdatadtypers rrz_data_matrix.dtypesyyrc&||j_yrr)rnewtypes rrz_data_matrix.dtypes ! rcRt|dr|j|jS)Nsum_duplicates)hasattrrrrs r _deduped_dataz_data_matrix._deduped_data s# 4) *    !yyrcR|jt|jSr) _with_dataabsrrs r__abs__z_data_matrix.__abs__%ss4#5#5#7899rcj|jtj|j|S)N)decimals)r nparoundr)rndigitss r __round__z_data_matrix.__round__(s%ryy););)=PQQrcL|j|jjSr)r rrealrs r_realz_data_matrix._real+tyy~~..rcL|j|jjSr)r rimagrs r_imagz_data_matrix._imag.r,rc|jjdk(r td|j|j S)Nbz0negating a boolean sparse array is not supported)rkindNotImplementedErrorr rrs r__neg__z_data_matrix.__neg__1s9 ::??c !%'23 3 z**rcRt|r|xj|zc_|StSrrrNotImplementedrothers r__imul__z_data_matrix.__imul__7s#   II IKrc\t|rd|z }|xj|zc_|StS)Ng?r6)rr9recips r __itruediv__z_data_matrix.__itruediv__=s,  %KE II IK! !rctj|}|j|k7rP|j|jj ||dd}|j|j dS|r|j S|S)NT)castingcopyr@F)r%rr rastyperr@)rrr?r@matrixs rrBz_data_matrix.astypeEs :: __   d C%F$$V%9%9%;%$H H 99; Krctj|jtjr+|j |j j |S|r|jS|S)NrA)r% issubdtypercomplexfloatingr r conjugater@)rr@s rrGz_data_matrix.conjugateTsN ==R%7%7 8??499#6#6#8t?D D 99; KrcX|j|jjdSNTrA)r rr@rs rr@z_data_matrix.copy^s tyy~~/d;;rct|s td|s td|j}||j|d}|j ||zS)a This function performs element-wise power. Parameters ---------- n : scalar n is a non-zero scalar (nonzero avoids dense ones creation) If zero power is desired, special case it to use `np.ones` dtype : If dtype is not specified, the current dtype will be preserved. Raises ------ NotImplementedError : if n is a zero scalar If zero power is desired, special case it to use ``np.ones(A.shape, dtype=A.dtype)`` zinput is not scalarzpzero power is not supported as it would densify the matrix. Use `np.ones(A.shape, dtype=A.dtype)` for this case.FrA)rr3rrBr )rnrrs rpowerz_data_matrix.powercsh$A%&;< <%G  !!#  ;;u5;1Dtqy))rc>|j|j|zSr)r rr8s r _mul_scalarz_data_matrix._mul_scalarstyy5011r)r)unsafeT)Tr)__name__ __module__ __qualname__rpropertyrsetterrr"r(r+r/r4r:r=rBr__doc__rGr@rLrNrrr r s)-8 \\"" :R//+  " ^^++FN ))11I<<<''DL*F2rr cTfd}dtdtd|_t|_|S)NcV|j}|j|dSrI)rr )rresultops rmethodz_create_method..methods)**,-F??6?5 5rz Element-wise z. See `numpy.z` for more information.)namerUrP)rZr[s` r_create_methodr]s4 6*$0((,v-DF rcTt|D]\}}||k7s |cSdz }||kr|Sy)Nr) enumerate)indrKkas r_find_missing_indexrds?#1 6HFA1urc|eZdZdZdZdZdZdZdddd Zdddd Z dddd Z dddd Z dddd Z ddddZ y) _minmax_mixinzlMixin for min and max methods. These are not implemented for dia_matrix, hence the separate class. c h|j|}|jd|z }|j|}|dk(r|jn|j}|j |j |\}} |s4t j|j||k} || | d| | <| dk7} t j| |j|d}t j| | } t|tr&|f} |f} |j| | f| |jS|dk(rB|j| t jt!| ||ff|jd|fS|j| |t jt!| |ff|j|dfS) Nr)maxvalrFrA)shaperr)rri)ri_get_index_dtypetocsctocsrr _minor_reducer%diffindptrcompressrB isinstancer_coo_containerrzeroslen)raxis min_or_maxexplicitNM idx_dtypemat major_indexvaluenot_fullmaskcoordsris r_min_or_max_axisz_minmax_mixin._min_or_max_axiss JJt  JJq4x )))3 "aidjjlTZZ\  ..z: Uwwszz*;7!;H(x! LMjjA'  &&bhhs5z&KLMjjA' rcT| tdt|j}|djvr tdjj d}j dk(r|S|jjj}j tjjk7r |s |||}|Stfd|Dr tdjdk(rj|d||Sj|||S)Nz3Sparse min/max does not support an 'out' parameter.ndimrz&zero-size array to reduction operationc3BK|]}j|dk(ywrNri).0drs r z,_minmax_mixin._min_or_max..s0atzz!}!0) ValueErrorrrrirtypennzreducerravelmathprodanyr_min_or_max_axis_nd)rrvoutrwrxzeroms` r _min_or_maxz_minmax_mixin._min_or_maxs ?RS SDtyy1 <DJJ !IJJ::??1%Dxx1} !!$"4"4"6"<"<">?Axx499TZZ00tQ'H 040 0EF F 99>((a*hG G''j(CCrc&|jjd}|dk(r|jn|j}|j |j |j \}}tj|t} tjtj|j\} | D]} |j| | dz\} } |j| | }|j| | }||}||}|r| | z dkDsN||| | <W|||s| | z |k(r ||| | <qt||}||k(rt!||| | <|| | <t#|t$r| S|dk(r| j'dd} |j)| S)Nrrjrrr_)rrrlrmr_swaprir%rtintnonzerororprindicesrdminrrrreshape _ascontainer)rrv argminmaxcomparerxrr|ret_size line_sizeretnz_linesipqrr extreme_index extreme_valuezero_inds r_argminmax_axisz_minmax_mixin._argminmax_axiss{zzq!"aidjjlTZZ\ !ii 2)hhxs+JJrwwszz23  *A::aA&DAq88Aa=Dkk!A&G%dOM /Mq519$]3CF=$/1q5I3E$]3CF27IFH$,!$]H!=A!)A# *& dG $J 19++b!$C  %%rcZ|&|tjk(rdnd}td|dt|j}|tt fd|Dr&|tjk(rdnd}td|djd k(rj |d |||Sj||||Sd jvr&|tjk(rdnd}td|d jd k(r)|r&|tjk(rdnd}td|d y jjd }j}|j||j} |r| S|j| } |jd kDr|jd }t!j"j} || |s|j| k(rj|jdk(rt%|j&| S|jd } t%|j(| | zt%|j&| zS|jdk(r|j*d } n+|jd } |j(| z|j&z} t-| | }| |k(r t/|| S|S)NargminargmaxzSparse z% does not support an 'out' parameter.rc3BK|]}j|dk(ywrr)rrrs rrz+_minmax_mixin._argminmax..s4!4::a=A%4rz Cannot apply z along a zero-sized dimension.rrz to an empty matrix.z# to zero matrix when explicit=True.r_r)r%rrrrrr_argminmax_axis_ndrirrrtocoorrrrrrcolrowrrdr)rrvrrrrxminmaxrr|rrmaxnnznum_collinear_indicesfirst_implicit_zero_indexs` r _argminmaxz_minmax_mixin._argminmaxsw ?!*bii!7XXFwvh.STU UDtyy1  4t44%."))%; =8V!WXXyyA~++DGYRR**4GXN N  ?!*bii!7XXF}VH4HIJ J 88q=%."))%; =97"788zzq!jjl !#((+  / 88a<++b/C4::& =$ '377f+<xx1}377=122iimGsww}-.83sww}?U;VV V 88q= ZZ^NiimG WWw.8N$7$O! D 0-@ @((rNF)rxcF|j||tj|S)aReturn the maximum of the array/matrix or maximum along an axis. By default, all elements are taken into account, not just the non-zero ones. But with `explicit` set, only the stored elements are considered. Parameters ---------- axis : {-2, -1, 0, 1, None} optional Axis along which the sum is computed. The default is to compute the maximum over all elements, returning a scalar (i.e., `axis` = `None`). out : None, optional This argument is in the signature *solely* for NumPy compatibility reasons. Do not pass in anything except for the default value, as this argument is not used. explicit : {False, True} optional (default: False) When set to True, only the stored elements will be considered. If a row/column is empty, the sparse.coo_array returned has no stored element (i.e. an implicit zero) for that row/column. .. versionadded:: 1.15.0 Returns ------- amax : coo_array or scalar Maximum of `a`. If `axis` is None, the result is a scalar value. If `axis` is given, the result is a sparse.coo_array of dimension ``a.ndim - 1``. See Also -------- min : The minimum value of a sparse array/matrix along a given axis. numpy.max : NumPy's implementation of 'max' )rr%maximumrrvrrxs rmaxz_minmax_mixin.maxO Lc2::x@@rcF|j||tj|S)aReturn the minimum of the array/matrix or maximum along an axis. By default, all elements are taken into account, not just the non-zero ones. But with `explicit` set, only the stored elements are considered. Parameters ---------- axis : {-2, -1, 0, 1, None} optional Axis along which the sum is computed. The default is to compute the minimum over all elements, returning a scalar (i.e., `axis` = `None`). out : None, optional This argument is in the signature *solely* for NumPy compatibility reasons. Do not pass in anything except for the default value, as this argument is not used. explicit : {False, True} optional (default: False) When set to True, only the stored elements will be considered. If a row/column is empty, the sparse.coo_array returned has no stored element (i.e. an implicit zero) for that row/column. .. versionadded:: 1.15.0 Returns ------- amin : coo_matrix or scalar Minimum of `a`. If `axis` is None, the result is a scalar value. If `axis` is given, the result is a sparse.coo_array of dimension ``a.ndim - 1``. See Also -------- max : The maximum value of a sparse array/matrix along a given axis. numpy.min : NumPy's implementation of 'min' )rr%minimumrs rrz_minmax_mixin.minwrrcF|j||tj|S)aReturn the maximum, ignoring any Nans, along an axis. Return the maximum, ignoring any Nans, of the array/matrix along an axis. By default this takes all elements into account, but with `explicit` set, only stored elements are considered. .. versionadded:: 1.11.0 Parameters ---------- axis : {-2, -1, 0, 1, None} optional Axis along which the maximum is computed. The default is to compute the maximum over all elements, returning a scalar (i.e., `axis` = `None`). out : None, optional This argument is in the signature *solely* for NumPy compatibility reasons. Do not pass in anything except for the default value, as this argument is not used. explicit : {False, True} optional (default: False) When set to True, only the stored elements will be considered. If a row/column is empty, the sparse.coo_array returned has no stored element (i.e. an implicit zero) for that row/column. .. versionadded:: 1.15.0 Returns ------- amax : coo_array or scalar Maximum of `a`. If `axis` is None, the result is a scalar value. If `axis` is given, the result is a sparse.coo_array of dimension ``a.ndim - 1``. See Also -------- nanmin : The minimum value of a sparse array/matrix along a given axis, ignoring NaNs. max : The maximum value of a sparse array/matrix along a given axis, propagating NaNs. numpy.nanmax : NumPy's implementation of 'nanmax'. )rr%fmaxrs rnanmaxz_minmax_mixin.nanmax Xc277H==rcF|j||tj|S)aReturn the minimum, ignoring any Nans, along an axis. Return the minimum, ignoring any Nans, of the array/matrix along an axis. By default this takes all elements into account, but with `explicit` set, only stored elements are considered. .. versionadded:: 1.11.0 Parameters ---------- axis : {-2, -1, 0, 1, None} optional Axis along which the minimum is computed. The default is to compute the minimum over all elements, returning a scalar (i.e., `axis` = `None`). out : None, optional This argument is in the signature *solely* for NumPy compatibility reasons. Do not pass in anything except for the default value, as this argument is not used. explicit : {False, True} optional (default: False) When set to True, only the stored elements will be considered. If a row/column is empty, the sparse.coo_array returned has no stored element (i.e. an implicit zero) for that row/column. .. versionadded:: 1.15.0 Returns ------- amin : coo_array or scalar Minimum of `a`. If `axis` is None, the result is a scalar value. If `axis` is given, the result is a sparse.coo_array of dimension ``a.ndim - 1``. See Also -------- nanmax : The maximum value of a sparse array/matrix along a given axis, ignoring NaNs. min : The minimum value of a sparse array/matrix along a given axis, propagating NaNs. numpy.nanmin : NumPy's implementation of 'nanmin'. )rr%fminrs rnanminz_minmax_mixin.nanminrrcd|j||tjtj|S)aReturn indices of maximum elements along an axis. By default, implicit zero elements are taken into account. If there are several minimum values, the index of the first occurrence is returned. If `explicit` is set, only explicitly stored elements will be considered. Parameters ---------- axis : {-2, -1, 0, 1, None}, optional Axis along which the argmax is computed. If None (default), index of the maximum element in the flatten data is returned. out : None, optional This argument is in the signature *solely* for NumPy compatibility reasons. Do not pass in anything except for the default value, as this argument is not used. explicit : {False, True} optional (default: False) When set to True, only explicitly stored elements will be considered. If axis is not None and an axis has no stored elements, argmax is undefined, so the index ``0`` is returned for that row/column. .. versionadded:: 1.15.0 Returns ------- ind : numpy.matrix or int Indices of maximum elements. If matrix, its size along `axis` is 1. )rr%rgreaterrs rrz_minmax_mixin.argmaxs#<tS"))RZZJJrcd|j||tjtj|S)aReturn indices of minimum elements along an axis. By default, implicit zero elements are taken into account. If there are several minimum values, the index of the first occurrence is returned. If `explicit` is set, only explicitly stored elements will be considered. Parameters ---------- axis : {-2, -1, 0, 1, None}, optional Axis along which the argmin is computed. If None (default), index of the minimum element in the flatten data is returned. out : None, optional This argument is in the signature *solely* for NumPy compatibility reasons. Do not pass in anything except for the default value, as this argument is not used. explicit : {False, True} optional (default: False) When set to True, only explicitly stored elements will be considered. If axis is not None and an axis has no stored elements, argmin is undefined, so the index ``0`` is returned for that row/column. .. versionadded:: 1.15.0 Returns ------- ind : numpy.matrix or int Indices of minimum elements. If matrix, its size along `axis` is 1. )rr%rlessrs rrz_minmax_mixin.argmins#<tS"))RWWhGGr)NN)rPrQrRrUrrrrrrrrrrrVrrrfrfst DD4#&J>)@&A5&AP&A5&AP,>e,>\,>e,>\KeK@HeHrrf)rUrnumpyr%_baserrr_sputilsrr__all__r npfuncrPr\r]setattrrdrfrVrrrst EE0  s27s2n/8F ??D  L$v 678" QHQHr