U
    b<n                     @   s0  d Z ddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
 zddlZW n ek
rh   dZY nX e dkZejdkrdZndZd	d
 Zdd Zdd Zdd ZedZedZedZdeiZdd ZG dd dZdd Zde_G dd dZG dd dZdd  Z d!d" Z!d#d$ Z"d%d& Z#d'd( Z$d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@Z%dA&e%' Z(d)d*d+d,dBdCdDdEdDdEdFdGdHd6d7d9d:d<d=d>d?dIZ)dA&e)' Z*dJdKdLdMdNZ+G dOdP dPZ,dQdR Z-dSdT Z.dUdV Z/dWdX Z0dYdZ Z1d[d\ Z2d]d^ Z3d_d` Z4dadb Z5dcdd Z6dedf Z7dS )gzI
A place for internal code

Some things are more easily handled Python.

    N   )dtypearrayndarraypromote_typesPyPylittle<>c                 C   s   g }|   D ]\}}t|}t|tr.|dkr6td|dkrL|d |krLqt|d }|dk rhtdt|d |d}|dkr|d }nd }|||||f q|jdd	 d
 dd |D }	dd |D }
dd |D }dd |D }|	|
||fS )N)      zentry not a 2- or 3- tupler   r   r   zinvalid offset.alignc                 S   s   | d S )Nr    )xr   r   T/home/fireinfo/NEWAFireInfo/venv/lib/python3.8/site-packages/numpy/core/_internal.py<lambda>-       z!_makenames_list.<locals>.<lambda>)keyc                 S   s   g | ]}|d  qS r   r   .0r   r   r   r   
<listcomp>.   s     z#_makenames_list.<locals>.<listcomp>c                 S   s   g | ]}|d  qS r   r   r   r   r   r   r   /   s     c                 S   s   g | ]}|d  qS )r   r   r   r   r   r   r   0   s     c                 S   s   g | ]}|d  qS )r   r   r   r   r   r   r   1   s     )	itemslen
isinstancetuple
ValueErrorintr   appendsort)adictr   Z	allfieldsfnameobjnnumformattitlenamesformatsoffsetstitlesr   r   r   _makenames_list   s*    
r-   c                 C   s   z| d }W n t k
r$   d }Y nX |d krBt| |\}}}}n`g }g }g }|D ]N}| | }||d  ||d  t|dkr||d  qR|d  qRt||||d|S )Nr   r   r   )r)   r*   r+   r,   )KeyErrorr-   r    r   r   )r"   r   r)   r*   r+   r,   nameresr   r   r   
_usefields8   s.    
r2   c                    s  | j   d kr`| j}|d krL| jd kr,| jS | j }|rD| j|fS | jS nt|d |d fS | j} fdd|D }g }d}|D ]}|d |kr|d | }|dd| f ||7 }n|d |k rtdt	|dkr|d	 |d f}	n|d	 }	|d jr(|	t|d jd |d jd f}
n|	t|d f}
||d j
7 }||
 q| j
|kr|| j
| }|dd| f |S )
Nr   r   c                    s   g | ]} | |f qS r   r   r   fieldsr   r   r   i   s     z _array_descr.<locals>.<listcomp> z|VzLdtype.descr is not defined for types with overlapping or out-of-order fieldsr   r   )r4   subdtypemetadatastrcopy_array_descrr)   r    r   r   itemsize)Z
descriptorr6   newr)   Zordered_fieldsresultoffsetfieldr&   r0   tupr   r3   r   r:   X   sL    




r:   c                 C   s   t | ||S N)r   __new__)subtypeshaper   r   r   r   _reconstruct   s    rE   zw(?P<order1>[<>|=]?)(?P<repeats> *[(]?[ ,0-9]*[)]? *)(?P<order2>[<>|=]?)(?P<dtype>[A-Za-z0-9.?]*(?:\[[a-zA-Z0-9,.]+\])?)z\s*,\s*z\s+$=c           
   	   C   sl  d}g }|t | k rhtj| |d}z| \}}}}W n8 ttfk
rp   tdt |d  d|  dd Y nX | }|t | k rtj| |drt | }n2t	j| |d}|stdt |d | f | }|dkr|}nD|dkr|}n6t
||}t
||}||krtd	||f |}|d
dtfkr6d}|| }|dkrN|}	n|t|f}	||	 q|S )Nr   )poszformat number r   z of "z" is not recognizedz*format number %d of "%s" is not recognizedr5   z/inconsistent byte-order specification %s and %s|rF   )r   	format_rematchgroups	TypeErrorAttributeErrorr   endspace_resep_re
_convorderget_nboastliteral_evalr    )
ZastrZ
startindexr=   moZorder1ZrepeatsZorder2r   ordernewitemr   r   r   _commastring   sZ    


rY   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )dummy_ctypec                 C   s
   || _ d S rA   _cls)selfclsr   r   r   __init__   s    zdummy_ctype.__init__c                 C   s   | S rA   r   r]   otherr   r   r   __mul__   s    zdummy_ctype.__mul__c                 G   s
   |  |S rA   r[   r`   r   r   r   __call__   s    zdummy_ctype.__call__c                 C   s   | j |j kS rA   r[   r`   r   r   r   __eq__   s    zdummy_ctype.__eq__c                 C   s   | j |j kS rA   r[   r`   r   r   r   __ne__   s    zdummy_ctype.__ne__N)__name__
__module____qualname__r_   rb   rc   rd   re   r   r   r   r   rZ      s
   rZ   c                  C   sx   t j} | d k	r| S td kr.dd l}t|j} n@tdj}|dkrHtj} n&|dkrXtj	} n|dkrhtj
} ntj	} | t _| S )Nr   pilq)_getintp_ctypecachectypesZnumpyrZ   Zintpr   charc_intc_long
c_longlong)valnprp   r   r   r   rm      s     
rm   c                   @   s"   e Zd Zdd ZG dd dZdS )_missing_ctypesc                 C   s   |j S rA   value)r]   r&   r$   r   r   r   cast   s    z_missing_ctypes.castc                   @   s   e Zd Zdd ZdS )z_missing_ctypes.c_void_pc                 C   s
   || _ d S rA   rw   )r]   ptrr   r   r   r_      s    z!_missing_ctypes.c_void_p.__init__N)rf   rg   rh   r_   r   r   r   r   c_void_p   s   r{   N)rf   rg   rh   ry   r{   r   r   r   r   rv      s   rv   c                   @   s~   e Zd ZdddZdd Zdd Zdd	 Zed
d Zedd Z	edd Z
edd Zdd Zdd Zdd Zdd ZdS )_ctypesNc                 C   s\   || _ tr t| _| j|| _nt | _| j|| _|| j_| j jdkrRd| _nd| _d S )Nr   TF)	_arrro   r|   r{   _datarv   _objectsndim_zerod)r]   r   rz   r   r   r   r_      s    z_ctypes.__init__c                 C   s   | 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.
        )r|   ry   r~   r}   )r]   r$   rz   r   r   r   data_as  s    z_ctypes.data_asc                 C   s   | j r
dS || jj | jj S )z
        Return the shape tuple as an array of some other c-types
        type. For example: ``self.shape_as(ctypes.c_short)``.
        N)r   r}   r   rD   r]   r$   r   r   r   shape_as  s    z_ctypes.shape_asc                 C   s   | j r
dS || jj | jj S )z
        Return the strides tuple as an array of some other
        c-types type. For example: ``self.strides_as(ctypes.c_longlong)``.
        N)r   r}   r   stridesr   r   r   r   
strides_as'  s    z_ctypes.strides_asc                 C   s   | j jS )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)``
        )r~   rx   r]   r   r   r   data0  s    z_ctypes.datac                 C   s   |  t S )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.
        )r   rm   r   r   r   r   rD   B  s    
z_ctypes.shapec                 C   s   |  t S )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.
        )r   rm   r   r   r   r   r   N  s    	z_ctypes.stridesc                 C   s   |  tjS )ze
        Overrides the ctypes semi-magic method

        Enables `c_func(some_array.ctypes)`
        )r   ro   r{   r   r   r   r   _as_parameter_Y  s    z_ctypes._as_parameter_c                 C   s   t jdtdd | jS )zYDeprecated getter for the `_ctypes.data` property.

        .. deprecated:: 1.21
        z,"get_data" is deprecated. Use "data" insteadr   
stacklevel)warningswarnDeprecationWarningr   r   r   r   r   get_datad  s
     z_ctypes.get_datac                 C   s   t jdtdd | jS )zZDeprecated getter for the `_ctypes.shape` property.

        .. deprecated:: 1.21
        z."get_shape" is deprecated. Use "shape" insteadr   r   )r   r   r   rD   r   r   r   r   	get_shapem  s
     z_ctypes.get_shapec                 C   s   t jdtdd | jS )z\Deprecated getter for the `_ctypes.strides` property.

        .. deprecated:: 1.21
        z2"get_strides" is deprecated. Use "strides" insteadr   r   )r   r   r   r   r   r   r   r   get_stridesv  s
     z_ctypes.get_stridesc                 C   s   t jdtdd | jS )zcDeprecated getter for the `_ctypes._as_parameter_` property.

        .. deprecated:: 1.21
        z>"get_as_parameter" is deprecated. Use "_as_parameter_" insteadr   r   )r   r   r   r   r   r   r   r   get_as_parameter  s     z_ctypes.get_as_parameter)N)rf   rg   rh   r_   r   r   r   propertyr   rD   r   r   r   r   r   r   r   r   r   r   r|      s    
		





			r|   c              	   C   s   | j }t|}t|tr|g}t }t|ttfr|D ]\}z|| W n> tk
r   ||krrtd| dntd| dY nX || q6tt|| S td| dS )zf
    Given a datatype and an order object, return a new names tuple, with the
    order indicated
    zduplicate field name: Nzunknown field name: zunsupported order value: )	r)   listr   r8   setr   remover   add)datatyperW   ZoldnamesZ	nameslistseenr0   r   r   r   	_newnames  s     
r   c                    s0   | j   j fdd jD d}t| |ddS )a  Return 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
    c                    s   g | ]} j | d  qS r   r3   r   r0   dtr   r   r     s     z _copy_fields.<locals>.<listcomp>)r)   r*   T)r   r9   )r   r)   r   )ZaryZ
copy_dtyper   r   r   _copy_fields  s
    r   c           	      C   s(  | j dks |j dks | j |j kr(td| |k}g }| j D ]}| j| }|j| }t|d |d }|or||d k}|dd |dd krtdt|dkr|||f q:||d |f|f q:t|| jp|jd}|r$|j| jkr$| j D ](}| j| d |j| d kr|  S q| 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invalid type promotionr   r   r   r   )	r)   rL   r4   r   r   r    r   Zisalignedstructr;   )	Zdt1Zdt2Z	identical
new_fieldsr0   Zfield1Zfield2Z	new_descrr1   r   r   r   _promote_fields  s*     




r   c                 C   sl   |j s| j rh|dkr || kr dS | jdk	r`| jD ].}| j| d |kr0| j| d |kr0 dS q0tddS )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

    r   Nr   z'Cannot get/set field of an object array)	hasobjectr)   r4   rL   )oldtypenewtyper>   r0   r   r   r   _getfield_is_safe  s    

r   c                 C   s$   | |krdS |j s| j r tddS )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.)r   rL   )r   r   r   r   r   _view_is_safe  s
    r   ?ZS1bBhHrj   Irk   Lrl   QefdgFDGSUOV)r   cr   r   r   r   rj   r   rk   r   rl   r   r   r   r   r   ZfZdZZgswr   r   r5   i2u2i4Zu4i8u8f2)r   r   r   r   r   r   rj   r   rk   r   rl   r   r   r   r   r   r   r   r   r   r   zUCS-2 stringsZpointersZ	bitfieldszfunction pointers)u&tXc                   @   s@   e Zd Zdd Zdd Zdd Zdd Zed	d
 Zdd Z	dS )_Streamc                 C   s   || _ d| _d S )N@)r   	byteorder)r]   r   r   r   r   r_   g  s    z_Stream.__init__c                 C   s"   | j d | }| j |d  | _ |S rA   r   )r]   r%   r1   r   r   r   advancek  s    z_Stream.advancec                 C   s,   | j d t| |kr(| t| dS dS )NTF)r   r   r   )r]   r   r   r   r   consumep  s    z_Stream.consumec                 C   sh   t |r<d}|t| jk r2|| j| s2|d }q| |S | j|}| |}| t| |S d S )Nr   r   )callabler   r   r   index)r]   r   rj   r1   r   r   r   consume_untilv  s    


z_Stream.consume_untilc                 C   s
   | j d S )Nr   r   r   r   r   r   next  s    z_Stream.nextc                 C   s
   t | jS rA   )boolr   r   r   r   r   __bool__  s    z_Stream.__bool__N)
rf   rg   rh   r_   r   r   r   r   r   r   r   r   r   r   r   f  s   
r   c                 C   s   t | }t|dd\}}|S )NFis_subdtype)r   __dtype_from_pep3118)specstreamr   r   r   r   r   _dtype_from_pep3118  s    r   c                 C   sd  t g g g dd}d}d}d}| rd }| dr4qd }| dr`| d}ttt|d}| jd	kr| d}|d
krd}|| _	| j	dkrt
}	t}
nt}	t}
| dd }|rt|}nd}d}| drt| dd\}}n| j|
krd| jdkr| d}n
| d}|dk}|	| }|dkr:|d| 7 }d}ddd| j	| j	}t|| }|j}n8| jtkrt| j }td| j|ntd| j d}| j	dkr| | }|j | }||7 }|dkr
|dks|d k	rt|dkrt||}n||7 }t||}|dkr,t||ff}|d k	rBt||f}| drZ| d}nd }|rn|d ks|d k	r||d krtd| d|d | |d | |d  | ||j7 }||7 }||d!< q| j	dkr|d!  | | 7  < |d d gkrL|d  d dkrL|d! |d d jkrL|sL|d d }nt| t|}||fS )"Nr   r)   r*   r+   r;   r   F}(),)r   rF   r	   r
   ^!r   r
   )r   r   c                 S   s
   |    S rA   )isdigit)r   r   r   r   r     r   z&__dtype_from_pep3118.<locals>.<lambda>zT{Tr   Zr   r   ZUSVz%drF   z,Unrepresentable PEP 3118 data type {!r} ({})z'Unknown PEP 3118 data type specifier %rr   :r)   zDuplicate field name 'z' in PEP3118 formatr*   r+   r;   )dictr   r   r   mapr   splitr   r   r   _pep3118_native_map_pep3118_native_typechars_pep3118_standard_map_pep3118_standard_typecharsr   rR   r   	alignment_pep3118_unsupported_mapNotImplementedErrorr'   r   r   r;   _prod_add_trailing_padding_lcmRuntimeErrorr    
_fix_names)r   r   
field_specr>   Zcommon_alignmentZ
is_paddingrx   rD   r   Ztype_mapZtype_map_charsZitemsize_strr;   r   ZtypecharZ	dtypecharZnumpy_byteorderdescZextra_offsetZstart_paddingZintra_paddingr0   retr   r   r   r     s    







 


 
 

"




r   c                 C   sR   | d }t |D ]<\}}|dk	r"qd}d| }||kr:qD|d }q&|||< qdS )z< Replace names which are None with the next unused f%d name r)   Nr   r   r   )	enumerate)r   r)   rj   r0   jr   r   r   r     s    

r   c                    sv   | j dkr$tdg| gdg| jd}n:| j  | j}t| fdd|D  fdd|D | jd}|d  |7  < t|S )	zBInject the specified number of padding bytes at the end of a dtypeNZf0r   r   c                    s   g | ]} | d  qS r   r   r   r3   r   r   r   <  s     z)_add_trailing_padding.<locals>.<listcomp>c                    s   g | ]} | d  qS r   r   r   r3   r   r   r   =  s     r;   )r4   r   r;   r)   r   )rx   paddingr   r)   r   r3   r   r   .  s"    
r   c                 C   s   d}| D ]}||9 }q|S )Nr   r   )ari   r   r   r   r   r   D  s    
r   c                 C   s   |r|| |  } }q | S )z0Calculate the greatest common divisor of a and br   r   r   r   r   r   _gcdJ  s    r   c                 C   s   | t | | | S rA   )r   r   r   r   r   r   P  s    r   c                 O   sZ   d dd |D dd | D  }||dd }d dd |D }d	||||S )
= Format the error message for when __array_ufunc__ gives up. , c                 S   s   g | ]}d  |qS )z{!r}r'   r   argr   r   r   r   U  s     z0array_ufunc_errmsg_formatter.<locals>.<listcomp>c                 S   s   g | ]\}}d  ||qS )z{}={!r}r   )r   kvr   r   r   r   V  s   outr   c                 s   s   | ]}t t|jV  qd S rA   )reprtyperf   r   r   r   r   	<genexpr>Y  s     z/array_ufunc_errmsg_formatter.<locals>.<genexpr>zToperand type(s) all returned NotImplemented from __array_ufunc__({!r}, {!r}, {}): {})joinr   rR   r'   )dummyufuncmethodinputskwargsargs_stringargsZtypes_stringr   r   r   array_ufunc_errmsg_formatterS  s       r  c                 C   s    d | j| j}d |t|S )r   z{}.{}zOno implementation found for '{}' on types that implement __array_function__: {})r'   rg   rf   r   )Z
public_apitypes	func_namer   r   r   array_function_errmsg_formatter_  s
     r  c                 C   s   | j dkrd}nddd t| j D }| jdkr:d}n>| jdkrJd}n.d	jdd
d t| jD td| j d}d}| jdkrd| d}n|d7 }dj| j|||dS )zz
    Builds a signature string which resembles PEP 457

    This is used to construct the first line of the docstring
    r   r   r   c                 s   s   | ]}d |d  V  qdS )r   r   Nr   r   rj   r   r   r   r  q  s     z1_ufunc_doc_signature_formatter.<locals>.<genexpr>r   z, /, out=()z, /, out=Nonez%[, {positional}], / [, out={default}]c                 s   s   | ]}d  |d V  qdS )zout{}r   Nr   r  r   r   r   r  z  s    rA   )
positionaldefaultz8, 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}))r0   in_argsout_argsr  )Zninr  rangeZnoutr'   r  	signaturerf   )r	  r  r  r  r   r   r   _ufunc_doc_signature_formatterf  s0    




r  c                 C   sB   z&t r| jd }n
| jd }d|jkW S  tk
r<   Y dS X d S )Nr|   F)IS_PYPY__mro__rg   	Exception)r^   Z
ctype_baser   r   r   npy_ctypes_check  s    
r   )8__doc__rT   resysplatformr   Z
multiarrayr   r   r   r   ro   ImportErrorpython_implementationr  r   rS   r-   r2   r:   rE   compilerI   rP   rO   rQ   rY   rZ   rm   rn   rv   r|   r   r   r   r   r   r   r  keysr   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r   r   r   r   r   <module>   s   

 4


0	 7 !$ 0