bgndZddlZddlZddlZddlZddlmZddlmZm Z m Z m Z  ddl Z n #e $rdZ YnwxYwejjdkZejdkrd Znd Zd Zd Zd ZdZejdZejdZejdZdeiZdZGddZdZde_GddZ GddZ!dZ"dZ#dZ$dZ%dZ&id d d!d"d#d#d$d$d%d%d&d&d'd'd(d(d)d)d*d*d+d+d,d,d-d-d.d.d/d/d0d0d1d2d3d4d5d6d7d8d9Z'd:(e')Z*id d d!d"d#d#d$d$d%d;d&d<d'd=d(d>d)d=d*d>d+d?d,d@d-dAd.d.d/d/d1d2dBd3d5d6d7d8dCZ+d:(e+)Z,dDdEdFdGdHZ-GdIdJZ.dKZ/dLZ0dMZ1dNZ2dOZ3dPZ4dQZ5dRZ6dSZ7dTZ8dUZ9dS)VzI A place for internal code Some things are more easily handled Python. N)DTypePromotionError)dtypearrayndarray promote_typespypylittle<>c>g}|D]\}}t|}t|tr|dvrt d|dkr |d|krOt |d}|dkrt dt |d|}|dkr |d}nd}|||||f|d d |D} d |D} d |D} d |D} | | | | fS)N)rzentry not a 2- or 3- tuplerrrzinvalid offset.alignc|dS)Nr)xs K/opt/cloudlinux/venv/lib64/python3.11/site-packages/numpy/core/_internal.pyz!_makenames_list..-s 1)keycg|] }|d Srr.0rs r z#_makenames_list...s % % %aQqT % % %rcg|] }|d Srrrs rrz#_makenames_list../'''qt'''rcg|] }|d S)rrrs rrz#_makenames_list..0r rcg|] }|d S)rrrs rrz#_makenames_list..1s & & &qad & & &r) itemslen isinstancetuple ValueErrorintrappendsort) adictr allfieldsfnameobjnnumformattitlenamesformatsoffsetstitless r_makenames_listr7sUIkkmm66 s HH#u%% ;&9:: : q55SVu__ #a&kk 77.// /s1vU+++ q55FEEE%e45555 NN~~N&&& % %9 % % %E''Y'''G''Y'''G & &I & & &F '7F **rc |d}n#t$rd}YnwxYw|t||\}}}}ng}g}g}|D]}||}||d||dt|dkr||do|dt ||||d|S)Nrrr)r3r4r5r6)KeyErrorr7r)r$r)r+rr3r4r5r6nameress r _usefieldsr=8sb   }*9%*G*G'w $ $D+C NN3q6 " " " NN3q6 " " "3xx!|| c!f%%%% d#### 5$$"$$&+ , ,,s  cj |j _|j}|9|j|jS|j}|r |j|fS|jSt |d|dfS|j} fd|D}g}d}|D]}|d|kr+|d|z }|dd|f||z }n|d|krtdt|dkr|d|df} n|d} |djr5| t |djd|djdf} n| t |df} ||dj z }|| |j |kr$|j |z }|dd|f|S) Nrrc(g|]}||fzSrr)rrfieldss rrz _array_descr..is$6661fQi1$&666rz|VzLdtype.descr is not defined for types with overlapping or out-of-order fieldsrr) r@subdtypemetadatastrcopy _array_descrr3r)r'r$itemsize) descriptorrBnewr3ordered_fieldsresultoffsetfieldr0r;tupr@s @rrFrFXs   F ~&  "*!~% )..00*&NC00%>) !--x{; ;  E6666666N F F 8f  (V#C MM2zCzz* + + + cMFF 1X  &'' ' u::>>!HeAh'DD8D 8  1eAh&7&:;;8$Q')CCeAh//0C%(## cV##!F* r:::&''' Mrc.tj|||SN)r__new__)subtypeshapers r _reconstructrTs ?7E5 1 11rzw(?P[<>|=]?)(?P *[(]?[ ,0-9]*[)]? *)(?P[<>|=]?)(?P[A-Za-z0-9.?]*(?:\[[a-zA-Z0-9,.]+\])?)z\s*,\s*z\s+$=cd}g}|t|krt||} |\}}}}n<#tt f$r(t dt|dzd|ddwxYw|}|t|krt||rt|}nVt||}|s$t dt|dz|fz|}|dkr|}n\|dkr|}nSt ||}t ||}||krt d |d ||}|d d tfvrd}||z}|dkr|} n|tj|f} || |t|k|S) Nr)poszformat number rz of "z" is not recognizedz*format number %d of "%s" is not recognizedrAz&inconsistent byte-order specification z and |rU)r$ format_rematchgroups TypeErrorAttributeErrorr'endspace_resep_re _convorderget_nboast literal_evalr)) astr startindexrKmoorder1repeatsorder2rordernewitems r _commastringrns0J F s4yy __Tz_ 2 2 /1yy{{ ,VWfee>*   NVQNNTNNN  VVXX D ! !~~d ~33 & YY \\$J\77/$DVQ-./// VVXX R<<EE r\\EE^^FF33F^^FF33F&   jVVVV%&&&E S#t$ $ $E  rMMGGc.w778G gS s4yy V Ms A9B c,eZdZdZdZdZdZdZdS) dummy_ctypec||_dSrP_cls)selfclss r__init__zdummy_ctype.__init__s  rc|SrPrrtothers r__mul__zdummy_ctype.__mul__s rc,||SrPrrrxs r__call__zdummy_ctype.__call__syyrc"|j|jkSrPrrrxs r__eq__zdummy_ctype.__eq__yEJ&&rc"|j|jkSrPrrrxs r__ne__zdummy_ctype.__ne__rrN)__name__ __module__ __qualname__rvrzr|r~rrrrrprps_   ''''''''rrpc0tj}||Stddl}t |j}nYt dj}|dkr tj}n2|dkr tj }n|dkr tj }n tj }|t_|S)Nrpilq) _getintp_ctypecachectypesnumpyrpintprcharc_intc_long c_longlong)valnprs rrrs  C   ~"'""Szz 3;;,CC S[[-CC S[[#CC-CN Jrc.eZdZdZGddZdS)_missing_ctypesc|jSrPvalue)rtr0r.s rcastz_missing_ctypes.casts yrceZdZdZdS)_missing_ctypes.c_void_pc||_dSrPr)rtptrs rrvz!_missing_ctypes.c_void_p.__init__s DJJJrN)rrrrvrrrc_void_prs#     rrN)rrrrrrrrrrsKrrceZdZddZdZdZdZedZedZ edZ ed Z d Z d Z d Zd ZdS)_ctypesNc6||_tr,t|_|j||_n>t |_|j||_||j_|jjdkr d|_dSd|_dS)NrTF) _arrrrr_datar_objectsndim_zerod)rtrrs rrvz_ctypes.__init__s  (!DL..s33DJJ+,,DL..s33DJ"'DJ  9>Q  DKKKDKKKrc^|j|j|}|j|_|S)a Return the data pointer cast to a particular c-types object. For example, calling ``self._as_parameter_`` is equivalent to ``self.data_as(ctypes.c_void_p)``. Perhaps you want to use the data as a pointer to a ctypes array of floating-point data: ``self.data_as(ctypes.POINTER(ctypes.c_double))``. The returned pointer will keep a reference to the array. )rrrr)rtr.rs rdata_asz_ctypes.data_as s+l C009 rcL|jrdS||jjz|jjS)z Return the shape tuple as an array of some other c-types type. For example: ``self.shape_as(ctypes.c_short)``. N)rrrrSrtr.s rshape_asz_ctypes.shape_ass- ; 4"DIN"TY_55rcL|jrdS||jjz|jjS)z Return the strides tuple as an array of some other c-types type. For example: ``self.strides_as(ctypes.c_longlong)``. N)rrrstridesrs r strides_asz_ctypes.strides_as's. ; 4"DIN"TY%677rc|jjS)a A pointer to the memory area of the array as a Python integer. This memory area may contain data that is not aligned, or not in correct byte-order. The memory area may not even be writeable. The array flags and data-type of this array should be respected when passing this attribute to arbitrary C-code to avoid trouble that can include Python crashing. User Beware! The value of this attribute is exactly the same as ``self._array_interface_['data'][0]``. Note that unlike ``data_as``, a reference will not be kept to the array: code like ``ctypes.c_void_p((a + b).ctypes.data)`` will result in a pointer to a deallocated array, and should be spelt ``(a + b).ctypes.data_as(ctypes.c_void_p)`` )rrrts rdataz _ctypes.data0s zrcD|tS)a (c_intp*self.ndim): A ctypes array of length self.ndim where the basetype is the C-integer corresponding to ``dtype('p')`` on this platform (see `~numpy.ctypeslib.c_intp`). This base-type could be `ctypes.c_int`, `ctypes.c_long`, or `ctypes.c_longlong` depending on the platform. The ctypes array contains the shape of the underlying array. )rrrs rrSz _ctypes.shapeBs}}^--...rcD|tS)aj (c_intp*self.ndim): A ctypes array of length self.ndim where the basetype is the same as for the shape attribute. This ctypes array contains the strides information from the underlying array. This strides information is important for showing how many bytes must be jumped to get to the next element in the array. )rrrs rrz_ctypes.stridesNs~//000rc@|tjS)ze Overrides the ctypes semi-magic method Enables `c_func(some_array.ctypes)` )rrrrs r_as_parameter_z_ctypes._as_parameter_Ys||FO,,,rcHtjdtd|jS)zYDeprecated getter for the `_ctypes.data` property. .. deprecated:: 1.21 z,"get_data" is deprecated. Use "data" insteadr stacklevel)warningswarnDeprecationWarningrrs rget_dataz_ctypes.get_datads-  D(Q 8 8 8 8yrcHtjdtd|jS)zZDeprecated getter for the `_ctypes.shape` property. .. deprecated:: 1.21 z."get_shape" is deprecated. Use "shape" insteadrr)rrrrSrs r get_shapez_ctypes.get_shapems-  F(Q 8 8 8 8zrcHtjdtd|jS)z\Deprecated getter for the `_ctypes.strides` property. .. deprecated:: 1.21 z2"get_strides" is deprecated. Use "strides" insteadrr)rrrrrs r get_stridesz_ctypes.get_stridesvs-  J(Q 8 8 8 8|rcHtjdtd|jS)zcDeprecated getter for the `_ctypes._as_parameter_` property. .. deprecated:: 1.21 z>"get_as_parameter" is deprecated. Use "_as_parameter_" insteadrr)rrrrrs rget_as_parameterz_ctypes.get_as_parameters0  L 1    ""rrP)rrrrvrrrpropertyrrSrrrrrrrrrrrs    "&666888  X " / /X /11X1--X- # # # # #rrc|j}t|}t|tr|g}t }t|tt fr|D]f} ||n8#t$r+||vrtd|dtd|dwxYw||gt t||zStd|)zf Given a datatype and an order object, return a new names tuple, with the order indicated zduplicate field name: Nzunknown field name: zunsupported order value: ) r3listr%rDsetr&remover'add)datatyperloldnames nameslistseenr;s r _newnamesrs ~HXI% 55D%$'' .  D N  &&&& N N N4<<$%Dd%D%DEE4O$%BD%B%BCCM  N HHTNNNNT%[[9,--- 888 9 99s A445B)cl|jjfdjDd}t||dS)aReturn copy of structured array with padding between fields removed. Parameters ---------- ary : ndarray Structured array from which to remove padding bytes Returns ------- ary_copy : ndarray Copy of ary with padding bytes removed c6g|]}j|dSr)r@)rr;dts rrz _copy_fields..s$FFFTbioa0FFFr)r3r4T)rrE)rr3r)ary copy_dtypers @r _copy_fieldsrsM B8FFFFRXFFFHHJ JT 2 2 22rc|j|j|j|jkr td|jd|jd||u}g}|jD]}|j|}|j|}t|d|d}|o ||du}|dd|ddkrtd|dt |dkr|||f||d|f|ft ||jp|j }|rH|j|jkr8|jD].}|j|d |j|d kr|cS/|S|S) a Perform type promotion for two structured dtypes. Parameters ---------- dt1 : structured dtype First dtype. dt2 : structured dtype Second dtype. Returns ------- out : dtype The promoted dtype Notes ----- If one of the inputs is aligned, the result will be. The titles of both descriptors must match (point to the same field). Nz field names `z` and `z ` mismatch.rrzfield titles of field 'z ' mismatchrr) r3rr@r r$r)risalignedstructrG) dt1dt2 identical new_fieldsr;field1field2 new_descrr<s r_promote_fieldsrs* SY.39 3I3I!H HH#)HHHJJ Js IJ > >D!D!!&)VAY77 8)vay"8  !"": # #%>d>>>@@ @ v;;!     tY/ 0 0 0 0   q 40)< = = = =  #"5"L9L M M MC S\S\11I  Dz$"cj&6q&999 : Jrc|js|jr_|dkr||krdS|j;|jD]3}|j|d|kr|j|d|krdS4tddS)a Checks safety of getfield for object arrays. As in _view_is_safe, we need to check that memory containing objects is not reinterpreted as a non-object datatype and vice versa. Parameters ---------- oldtype : data-type Data type of the original ndarray. newtype : data-type Data type of the field being accessed by ndarray.getfield offset : int Offset of the field being accessed by ndarray.getfield Raises ------ TypeError If the field access is invalid rNrz'Cannot get/set field of an object array) hasobjectr3r@r\)oldtypenewtyperLr;s r_getfield_is_safers*CG-C Q;;7g-- F = $   N4(+v55t,Q/7::FFABBB FrcP||krdS|js|jrtddS)az Checks safety of a view involving object arrays, for example when doing:: np.zeros(10, dtype=oldtype).view(newtype) Parameters ---------- oldtype : data-type Data type of original ndarray newtype : data-type Data type of the view Raises ------ TypeError If the new type is incompatible with the old type. Nz)Cannot change data-type for object array.)rr\)rrs r _view_is_safer s?,'EG-ECDDD Fr?cS1bBhHrIrLrQefdgZfFDGSUOV)ZdZgswrrrAi2u2i4u4i8u8f2r)rrrrz UCS-2 stringspointers bitfieldszfunction pointers)u&tXcBeZdZdZdZdZdZedZdZ dS)_Streamc"||_d|_dS)N@)r byteorder)rtrs rrvz_Stream.__init__isrcL|jd|}|j|d|_|SrPr)rtr/r<s radvancez_Stream.advancems'fRaRj rc|jdt||kr$|t|dSdS)NTF)rr$r)rtrs rconsumez_Stream.consumers? 6'3q66'?a   LLQ 4urct|rxd}|t|jkrI||j|s3|dz}|t|jkr||j|3||S|j|}||}|t||S)Nrr)callabler$rrindex)rtrrr<s r consume_untilz_Stream.consume_untilxs A;; Ac$&kk//!!DF1I,,/Ec$&kk//!!DF1I,,/<<?? " QA,,q//C LLQ Jrc|jdS)Nrrrs rnextz _Stream.nextsvayrc*t|jSrP)boolrrs r__bool__z_Stream.__bool__sDF||rN) rrrrvrrrrrrrrrrrhsz    XrrcLt|}t|d\}}|S)NF is_subdtype)r__dtype_from_pep3118)specstreamrrs r_dtype_from_pep3118r&s( T]]F'EBBBLE5 Lrc$tgggd}d}d}d}|rgd}|drnNd}|drJ|d}tt t |d}|jd vr$|d}|d krd }||_ |j d vrt} t} nt} t} |d } | rt | } nd} d}|drt|d\}} n|j| vr|jdkr|d}n|d}|dk}| |}|dvr |d| zz }d} ddd |j |j }t!||z}|j} n_|jt$vr:t$|j}t'd|j|t+d|jzd}|j dkr]| | z}|j | z}||z }|dkr1| dks|$t1|dkrt3||}n||z }t5| |}| dkrt!|| ff}|t!||f}|dr|d}nd}|r|p|||dvrt7d|d|d||d||d|||jz }||z }||d <|g|j dkr|d xx| |zz cc<|ddgkr@|dddkr.|d |ddjkr|s|dd}nt;|t!|}||fS)!Nrr3r4r5rGrF}(),)rrUr r ^!r.r )rr-c,| SrP)isdigit)rs rrz&__dtype_from_pep3118..s!))++orzT{Tr!ZrrUSVz%drUz,Unrepresentable PEP 3118 data type {!r} ({})z'Unknown PEP 3118 data type specifier %rr:r3zDuplicate field name 'z' in PEP3118 formatr4r5rG)dictrrr&mapr(splitrrr_pep3118_native_map_pep3118_native_typechars_pep3118_standard_map_pep3118_standard_typecharsr#rbr alignment_pep3118_unsupported_mapNotImplementedErrorr1r'rrG_prod_add_trailing_padding_lcm RuntimeErrorr) _fix_names)r%r" field_specrLcommon_alignment is_paddingrrSrtype_maptype_map_chars itemsize_strrGrtypechar dtypecharnumpy_byteorderdesc extra_offset start_padding intra_paddingr;rets rr#r#s J FJ q( >>#     >>#   6((--E#c5;;s#3#34455E ;8 8 8q))IC (F   z ) )*H6NN,H8N++,E,EFF  <((HHH >>$   S/D***LE55 [N * *{c!!!>>!,,!>>!,,"c/J *IE!!TH_, $'c2266 &"244O/I566EOEE [4 4 4+FK8D%> T**,, ,FQRR R  s " "$W-M#n_5M m #F!!a<>#   '',,DDD 1t|DJw,?$?$?"#UD#U#U#UVVV w  & &t , , , y ! ( ( / / / y ! ( ( 0 0 0%. ,!' :c q(h3:F7.>">> 7v%%9%a(A--:&*Y*?*B*KKKL#A&:J   rcv|d}t|D] \}}|d} d|}||vrn|dz}|||<!dS)z< Replace names which are None with the next unused f%d name r3NrTrr) enumerate)rCr3rr;js rrBrB!sx w EU##  4     q77D5  AA   a  rc|jtdg|gdg|j}n>|j|j}t|fd|Dfd|D|j}|dxx|z cc<t |S)zBInject the specified number of padding bytes at the end of a dtypeNf0rr(c,g|]}|dSrrrr;r@s rrz)_add_trailing_padding..>!777VD\!_777rc,g|]}|dSrrrWs rrz)_add_trailing_padding..?rXrrG)r@r4rGr3r)rpaddingrCr3r@s @rr?r?0s |&GC^     77777777777777^    zg%   rcd}|D]}||z}|S)Nrr)arrs rr>r>Fs& A  Q Hrc|r |||z}}| |S)z0Calculate the greatest common divisor of a and brr\rs r_gcdr_Ls& !a%1  Hrc.|t||z|zSrP)r_r^s rr@r@Rs Q ?Q rcdd|Dd|Dz}||ddz}dd|D}d||||S)= Format the error message for when __array_ufunc__ gives up. , c8g|]}d|S)z{!r}r1rargs rrz0array_ufunc_errmsg_formatter..Ws$BBBCV]]3//BBBrc@g|]\}}d||S)z{}={!r}re)rkvs rrz0array_ufunc_errmsg_formatter..Xs<999!%A'--a33999routrc3XK|]%}tt|jV&dSrP)reprtyperrfs r z/array_ufunc_errmsg_formatter..[s3FF#T$s))"455FFFFFFrzToperand type(s) all returned NotImplemented from __array_ufunc__({!r}, {!r}, {}): {})joinr#rbr1)dummyufuncmethodinputskwargs args_stringargs types_strings rarray_ufunc_errmsg_formatterryUs))BB6BBB99)/9999::K FJJub)) )D99FFFFFFFL 2 VE6; = =?rcd|j|j}d|t|S)rbz{}.{}zOno implementation found for '{}' on types that implement __array_function__: {})r1rrr) public_apitypes func_names rarray_function_errmsg_formatterr~as;z4j6IJJI %%+VItE{{%C%CErc|jdkrd}n1ddt|jD}|jdkrd}ni|jdkrd}n[ddd t|jDt d |jz }d }|jd|d}n|dz }d|j|||S)zz Builds a signature string which resembles PEP 457 This is used to construct the first line of the docstring rrrcc3&K|] }d|dzV dS)rrNrrrs rroz1_ufunc_doc_signature_formatter..ss,@@!I!II@@@@@@rrz , /, out=()z , /, out=Nonez%[, {positional}], / [, out={default}]c3FK|]}d|dzVdS)zout{}rNrers rroz1_ufunc_doc_signature_formatter..|sK!@!@()qs##!@!@!@!@!@!@rrP) positionaldefaultz8, casting='same_kind', order='K', dtype=None, subok=TrueNz , where=Truez[, signature, extobj]z![, signature, extobj, axes, axis]z&{name}({in_args}{out_args}, *{kwargs}))r;in_argsout_argsru)ninrprangenoutr1rm signaturer)rrrrrus r_ufunc_doc_signature_formatterrhs/ yA~~))@@uUY/?/?@@@@@ zQ  q":AAyy!@!@-25:->->!@!@!@@@+,,B     ====55 4 : : ^ ;  rc| tr|jd}n |jd}d|jvS#t$rYdSwxYw)NrF)IS_PYPY__mro__r Exception)ru ctype_bases rnpy_ctypes_checkrs[   )RJJRJJ111 uus *- ;;):__doc__rdresysr exceptionsr multiarrayrrrr r ImportErrorimplementationr;rrrcr7r=rFrTcompilerYr`r_rarnrprrrrrrrrrr7rpkeysr8r9r:r<rr&r#rBr?r>r_r@ryr~rrrrrrsi  ,,,,,,<<<<<<<<<<<<MMMM FFF   !V +=H DD D+++<,,,@---h222 BJK L L  J   2:g  4[ ...` ' ' ' ' ' ' ' '&O#O#O#O#O#O#O#O#d:::.333$666r   @   @      !" ##$  /2GG$7$<$<$>$>??       #!" ##$ +.!gg&;&@&@&B&BCC     !!!!!!!!H N!N!N!`   ,       ? ? ?EEE---`s +55