a :jg"q@sFdZddlZddlZddlZddlZddlmZddlmZm Z m Z m Z m Z ddl mZz ddlZWneyzdZYn0ejjdkZejd krd Znd Zd d ZddZddZedZedZedZdeiZddZGdddZddZ de _!GdddZ"GdddZ#d d!Z$d"d#Z%d$d%Z&d&d'Z'd(d)Z(d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;dd?d@dAZ)dB*e)+Z,d*d+d,d-dCdDdEdFdEdFdGdHdId7d8d:d;d=d>d?d@dJZ-dB*e-+Z.dKdLdMdNdOZ/GdPdQdQZ0dRdSZ1dTdUZ2dVdWZ3dXdYZ4dZd[Z5d\d]Z6d^d_Z7d`daZ8dbdcZ9dddeZ:dfdgZ;efdhdiZc Csg}|D]\}}t|}t|tr.|dvr6td|dkrL|d|krLq t|d}|dkrhtdt|d|d}|dkr|d}nd}|||||fq |jdd d d d |D} d d |D} dd |D} dd |D} | | | | fS)N)rzentry not a 2- or 3- tuplerrrzinvalid offset.aligncSs|dS)Nr)xrr?/usr/local/lib/python3.9/site-packages/numpy/_core/_internal.py.z!_makenames_list..)keycSsg|] }|dqSrr.0rrrr /rz#_makenames_list..cSsg|] }|dqSrrrrrrr0rcSsg|] }|dqS)rrrrrrr1rcSsg|] }|dqS)rrrrrrr2r) itemslen isinstancetuple ValueErrorintrappendsort) adictrZ allfieldsfnameobjnnumformattitlenamesformatsoffsetstitlesrrr_makenames_lists*  r0cCsz |d}Wnty"d}Yn0|dur@t||\}}}}n`g}g}g}|D]N}||}||d||dt|dkr||dqP|dqPt||||d|S)Nrrr)r,r-r.r/)KeyErrorr0r#rr)r%rr,r-r.r/nameresrrr _usefields9s.     r5c s|jdur`|j}|durL|jdur,|jS|j}|rD|j|fS|jSnt|d|dfS|j}fdd|D}g}d}|D]}|d|kr|d|}|dd|f||7}n|d|krtdt |dkr|d |df} n|d } |djr(| t|djd|djdf} n| t|df} ||dj 7}|| q|j |kr||j |}|dd|f|S) Nrrcsg|]}||fqSrrrfieldsrrrjrz _array_descr..z|VzLdtype.descr is not defined for types with overlapping or out-of-order fieldsrr) r7subdtypemetadatastrcopy _array_descrr,r#r!ritemsize) Z descriptorr9newr,Zordered_fieldsresultoffsetfieldr)r3tuprr6rr=YsL             r=zw(?P[<>|=]?)(?P *[(]?[ ,0-9]*[)]? *)(?P[<>|=]?)(?P[A-Za-z0-9.?]*(?:\[[a-zA-Z0-9,.]+\])?)z\s*,\s*z\s+$=c Csd}g}d}|t|krtj||d}z|\}}}}Wn6ttfyrtdt|dd|ddYn0|}|t|krtj||drt|}n6t j||d}|stdt|d|f|}d }|d kr|} nD|d kr|} n6t ||}t ||}||kr$td ||f|} | d d t fvr"get_as_parameter" is deprecated. Use "_as_parameter_" insteadrrJ)rXrYrZrrrrrget_as_parameters z_ctypes.get_as_parameter)N)rnrorprgrrrpropertyrrrrrrrrrrrrrs           rc Cs|j}t|}t|tr|g}t}t|ttfr|D]Z}z||Wn<ty||vrptd|dntd|dYn0||q6tt||Std|dS)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: ) r,listrr;setr remover!add)datatyper^ZoldnamesZ nameslistseenr3rrr _newnamess    rcs0|jjfddjDd}t||ddS)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 csg|]}j|dqSrr6rr3dtrrrrz _copy_fields..)r,r-T)rr<)rr,r)ZaryZ copy_dtyperrr _copy_fieldss rc CsF|jdus |jdus |j|jkr:td|jd|jd||u}g}|jD]}|j|}|j|}t|d|d}|o||du}|dd|ddkrtd|dt|dkr|||fqL||d|f|fqLt||jp|jd }|rB|j|jkrB|jD],}|j|d |j|d kr|Sq|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) r,rr7rrr#rZisalignedstructr>) Zdt1Zdt2Z identical new_fieldsr3Zfield1Zfield2Z new_descrr4rrr_promote_fieldss2        rcCsl|js |jrh|dkr ||kr dS|jdur`|jD].}|j|d|kr0|j|d|kr0dSq0tddS)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) hasobjectr,r7rO)oldtypenewtyperAr3rrr_getfield_is_safes   rcCs$||kr dS|js|jr tddS)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. Nz0Cannot change data-type for array of references.)rrO)rrrrr _view_is_safes  r?ZS1bBhHrqIrrLrsQefdgFDGSUOV)rcrrrrrqrrrrrsrrrrrZfZdZZgswrrr8i2u2i4Zu4i8u8f2)rrrrrrrqrrrrrsrrrrrrrrrrz UCS-2 stringsZpointersZ bitfieldszfunction pointers)u&tXc@s@eZdZddZddZddZddZed d Zd d Z d S)_StreamcCs||_d|_dS)N@)r byteorder)rerrrrrgvsz_Stream.__init__cCs"|jd|}|j|d|_|Srbr)rer(r4rrradvancezsz_Stream.advancecCs,|jdt||kr(|t|dSdS)NTF)rrr)rerrrrconsumesz_Stream.consumecCsht|rrF}rGrHrI)rrDr r^!rr)rrcSs | Srb)isdigit)rrrrrrz&__dtype_from_pep3118..zT{TrZrrZUSVz%drDz,Unrepresentable PEP 3118 data type {!r} ({})z'Unknown PEP 3118 data type specifier %rr:r,zDuplicate field name 'z' in PEP3118 formatr-r.r>)dictrrr mapr"splitrrr_pep3118_native_map_pep3118_native_typechars_pep3118_standard_map_pep3118_standard_typecharsrrUrZ alignment_pep3118_unsupported_mapNotImplementedErrorr*r!rr>_prod_add_trailing_padding_lcm RuntimeErrorr# _fix_names)rr field_specrAZcommon_alignmentZ is_paddingr}rrZtype_mapZtype_map_charsZ itemsize_strr>rZtypecharZ dtypecharZnumpy_byteorderdescZ extra_offsetZ start_paddingZ intra_paddingr3retrrrrs                        "           rcCsR|d}t|D]<\}}|dur"qd}d|}||vr:qD|d}q&|||<qdS)z< Replace names which are None with the next unused f%d name r,Nrrr) enumerate)rr,rqr3jrrrr2s  rcsv|jdur$tdg|gdg|jd}n:|j|j}t|fdd|Dfdd|D|jd}|d|7<t|S) zBInject the specified number of padding bytes at the end of a dtypeNZf0rrcsg|]}|dqSrrrr6rrrOrz)_add_trailing_padding..csg|]}|dqSrrrr6rrrPrr>)r7rr>r,r)r}paddingrr,rr6rrAs" rcCsd}|D] }||9}q|S)Nrr)aprrrrrWs rcCs|r|||}}q|S)z0Calculate the greatest common divisor of a and brrrrrr_gcd]srcCs|t|||Srb)rrrrrrcsrcOsZddd|Ddd|D}||dd}ddd|D}d ||||S) = Format the error message for when __array_ufunc__ gives up. , cSsg|]}d|qS)z{!r}r*rargrrrrhrz0array_ufunc_errmsg_formatter..cSsg|]\}}d||qS)z{}={!r}r)rkvrrrrisoutrcss|]}tt|jVqdSrb)reprtypernrrrr lrz/array_ufunc_errmsg_formatter..zToperand type(s) all returned NotImplemented from __array_ufunc__({!r}, {!r}, {}): {})joinrrUr*)dummyufuncmethodinputskwargs args_stringargsZ types_stringrrrarray_ufunc_errmsg_formatterfsr cCs d|j|j}d|t|S)rz{}.{}zOno implementation found for '{}' on types that implement __array_function__: {})r*rornr)Z public_apitypes func_namerrrarray_function_errmsg_formatterrsrcCs|jdkrd}ndddt|jD}|jdkr:d}n>|jdkrJd}n.d jdd dt|jDtd |jd }d }|jdurd|d}n|d7}dj|j|||dS)zz Builds a signature string which resembles PEP 457 This is used to construct the first line of the docstring rrrcss|]}d|dVqdS)rrNrrrqrrrrrz1_ufunc_doc_signature_formatter..rz , /, out=()z , /, out=Nonez%[, {positional}], / [, out={default}]css|]}d|dVqdS)zout{}rNrrrrrrsrb) positionaldefaultz8, casting='same_kind', order='K', dtype=None, subok=TrueNz , where=Truez [, signature]z[, signature, axes, axis]z&{name}({in_args}{out_args}, *{kwargs}))r3in_argsout_argsr )ZninrrangeZnoutr*r signaturern)rrrr rrr_ufunc_doc_signature_formatterys0      rcCs@z&tr|jd}n |jd}d|jvWSty:YdS0dS)NrF)IS_PYPY__mro__ro Exception)rfZ ctype_baserrrnpy_ctypes_checks    rcCs|turt|dSt||dS)N)coercerZ na_object)r r r rrr_convert_to_stringdtype_kwargss r!)=__doc__r[resysrX exceptionsrZ multiarrayrrrrr rwr rv ImportErrorimplementationr3rrrVr0r5r=compilerLrSrRrTr`rartrur{rrrrrrrrkeysrrrrrrrrrrrrr rrrr!rrrrs        2   ; 9 "$ 0