B
    G0dj                 @   s2  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	 yddl
Z
W n ek
rd   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(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>Z#d?$e#% Z&d'd(d)d*d@dAdBdCdBdCdDdEdFd4d5d7d8d:d;d<d=dGZ'd?$e'% Z(dHdIdJdKdLZ)G dMdN dNZ*dOdP Z+dQdR Z,dSdT Z-dUdV Z.dWdX Z/dYdZ Z0d[d\ Z1d]d^ Z2d_d` Z3dadb Z4dcdd Z5G dedf dfZ6dS )gzI
A place for internal code

Some things are more easily handled Python.

    N   )dtypearrayndarrayPyPylittle<>c             C   s   g }x|   D ]\}}t|}t|tr0|dkr8td|dkrN|d |krNqt|d }|dk rjtdt|d |d}|dkr|d }nd }|||||f qW |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   F/var/www/html/venv/lib/python3.7/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   r   /   s    c             S   s   g | ]}|d  qS )r
   r   )r   r   r   r   r   r   0   s    c             S   s   g | ]}|d  qS )r   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   y| d }W n t k
r$   d }Y nX |d krBt| |\}}}}ndg }g }g }xV|D ]N}| | }||d  ||d  t|dkr||d  qT|d  qTW t||||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(    

r-   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}x|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 }||
 qW | j
|kr| j
| }|dd| f |S )
Nr   r   c                s   g | ]} | |f qS r   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
   )r.   subdtypemetadatastrcopy_array_descrr$   r   r   r   itemsize)Z
descriptorr0   newr$   Zordered_fieldsresultoffsetfieldr!   r+   tupr   )r.   r   r4   X   sH    





r4   c             C   s   t | ||S )N)r   __new__)subtypeshaper   r   r   r   _reconstruct   s    r>   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   sr  d}g }xb|t | k rltj| |d}y| \}}}}W n8 ttfk
rt   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r:d}|| }|dkrR|}	n|t|f}	||	 qW |S )Nr   )poszformat number r   z of "z" is not recognizedz*format number %d of "%s" is not recognizedr/   z/inconsistent byte-order specification %s and %s|r?   )r   	format_rematchgroups	TypeErrorAttributeErrorr   endspace_resep_re
_convorderget_nboastliteral_evalr   )
ZastrZ
startindexr7   moZorder1ZrepeatsZorder2r   ordernewitemr   r   r   _commastring   sN    



rR   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 )N)_cls)selfclsr   r   r   __init__   s    zdummy_ctype.__init__c             C   s   | S )Nr   )rU   otherr   r   r   __mul__   s    zdummy_ctype.__mul__c             G   s
   |  |S )N)rT   )rU   rX   r   r   r   __call__   s    zdummy_ctype.__call__c             C   s   | j |j kS )N)rT   )rU   rX   r   r   r   __eq__   s    zdummy_ctype.__eq__c             C   s   | j |j kS )N)rT   )rU   rX   r   r   r   __ne__   s    zdummy_ctype.__ne__N)__name__
__module____qualname__rW   rY   rZ   r[   r\   r   r   r   r   rS      s
   rS   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ctypesnumpyrS   Zintpr   charc_intZc_longZ
c_longlong)valnprh   r   r   r   rd      s     
rd   c               @   s"   e Zd Zdd ZG dd dZdS )_missing_ctypesc             C   s   |j S )N)value)rU   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 )N)rm   )rU   ptrr   r   r   rW      s    z!_missing_ctypes.c_void_p.__init__N)r]   r^   r_   rW   r   r   r   r   c_void_p   s   rp   N)r]   r^   r_   rn   rp   r   r   r   r   rl      s   rl   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)	_arrrf   rq   rp   _datarl   _objectsndim_zerod)rU   r   ro   r   r   r   rW      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.
        )rq   rn   rs   rr   )rU   r   ro   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)rv   rr   ru   r=   )rU   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)rv   rr   ru   strides)rU   r   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)``
        )rs   rm   )rU   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. This base-type could be `ctypes.c_int`, `ctypes.c_long`, or
        `ctypes.c_longlong` depending on the platform.
        The c_intp type is defined accordingly in `numpy.ctypeslib`.
        The ctypes array contains the shape of the underlying array.
        )rx   rd   )rU   r   r   r   r=   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.
        )rz   rd   )rU   r   r   r   ry   N  s    	z_ctypes.stridesc             C   s   |  tjS )ze
        Overrides the ctypes semi-magic method

        Enables `c_func(some_array.ctypes)`
        )rw   rf   rp   )rU   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{   )rU   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   r=   )rU   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   ry   )rU   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|   )rU   r   r   r   get_as_parameter  s    
z_ctypes.get_as_parameter)N)r]   r^   r_   rW   rw   rx   rz   propertyr{   r=   ry   r|   r   r   r   r   r   r   r   r   rq      s   
					rq   c          	   C   s   | j }t|}t|tr|g}t }t|ttfrxd|D ]\}y|| W n> tk
r   ||krttd| dntd| dY nX || q8W t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   r2   setr   remover   add)datatyperP   ZoldnamesZ	nameslistseenr+   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   )r.   )r   r+   )dtr   r   r     s    z _copy_fields.<locals>.<listcomp>)r$   r%   T)r   r3   )r   r$   r   )ZaryZ
copy_dtyper   )r   r   _copy_fields  s    r   c             C   sn   |j s| j rj|dkr || kr dS | jdk	rbx6| jD ],}| j| d |kr2| j| d |kr2dS q2W t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$   r.   rE   )oldtypenewtyper8   r+   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   rE   )r   r   r   r   r   _view_is_safe  s
    r   ?ZS1bBhHra   Irb   Lrc   QefdgFDGSUOV)r   cr   r   r   r   ra   r   rb   r   rc   r   r   r   r   r   ZfZdZZgswr   r   r/   i2u2i4Zu4i8u8f2)r   r   r   r   r   r   ra   r   rb   r   rc   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)rU   r   r   r   r   rW   0  s    z_Stream.__init__c             C   s"   | j d | }| j |d  | _ |S )N)r   )rU   r    r,   r   r   r   advance4  s    z_Stream.advancec             C   s,   | j d t| |kr(| t| dS dS )NTF)r   r   r   )rU   r   r   r   r   consume9  s    z_Stream.consumec             C   sl   t |r@d}x(|t| jk r4|| j| s4|d }qW | |S | j|}| |}| t| |S d S )Nr   r   )callabler   r   r   index)rU   r   ra   r,   r   r   r   consume_until?  s    

z_Stream.consume_untilc             C   s
   | j d S )Nr   )r   )rU   r   r   r   nextK  s    z_Stream.nextc             C   s
   t | jS )N)boolr   )rU   r   r   r   __bool__O  s    z_Stream.__bool__N)
r]   r^   r_   rW   r   r   r   r   r   r   r   r   r   r   r   /  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_pep3118S  s    r   c             C   sh  t g g g dd}d}d}d}x| rd }| dr6P d }| drb| 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rf| 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	rDt||f}| dr\| d}nd }|rp|d ks|d k	r||d krtd| d|d | |d | |d  | ||j7 }||7 }||d!< q W | j	dkr|d!  | | 7  < |d d gkrP|d  d dkrP|d! |d d jkrP|sP|d d }nt| t|}||fS )"Nr   )r$   r%   r&   r5   r   F}(),)r   r?   r   r	   ^!r   r	   )r   r   c             S   s
   |    S )N)isdigit)r   r   r   r   r     r   z&__dtype_from_pep3118.<locals>.<lambda>zT{T)r   Zr
   r   ZUSVz%dr?   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&   r5   )dictr   r   r   mapr   splitr   r   r   _pep3118_native_map_pep3118_native_typechars_pep3118_standard_map_pep3118_standard_typecharsr   rK   r   Z	alignment_pep3118_unsupported_mapNotImplementedErrorr"   r   r   r5   _prod_add_trailing_padding_lcmRuntimeErrorr   
_fix_names)r   r   
field_specr8   Zcommon_alignmentZ
is_paddingrm   r=   r   Ztype_mapZtype_map_charsZitemsize_strr5   r   ZtypecharZ	dtypecharZnumpy_byteorderdescZextra_offsetZstart_paddingZintra_paddingr+   retr   r   r   r   X  s    














"



r   c             C   sZ   | d }xLt |D ]@\}}|dk	r$qd}x d| }||kr>P |d }q*W |||< qW dS )z< Replace names which are None with the next unused f%d name r$   Nr   r   r   )	enumerate)r   r$   ra   r+   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$   r%   r&   r5   c                s   g | ]} | d  qS )r   r   )r   r+   )r.   r   r   r     s    z)_add_trailing_padding.<locals>.<listcomp>c                s   g | ]} | d  qS )r   r   )r   r+   )r.   r   r   r     s    r5   )r.   r   r5   r$   r   )rm   paddingr   r$   r   )r.   r   r     s    

r   c             C   s   d}x| D ]}||9 }q
W |S )Nr   r   )ar`   r   r   r   r   r     s    
r   c             C   s   x|r|| |  } }qW | S )z0Calculate the greatest common divisor of a and br   )r   r   r   r   r   _gcd  s    r   c             C   s   | t | | | S )N)r   )r   r   r   r   r   r     s    r   c             O   sZ   d dd |D dd | D  }||dd }d dd |D }d	||||S )
z= Format the error message for when __array_ufunc__ gives up. z, c             S   s   g | ]}d  |qS )z{!r})r"   )r   argr   r   r   r     s    z0array_ufunc_errmsg_formatter.<locals>.<listcomp>c             S   s   g | ]\}}d  ||qS )z{}={!r})r"   )r   kvr   r   r   r     s   outr   c             s   s   | ]}t t|jV  qd S )N)reprtyper]   )r   r   r   r   r   	<genexpr>"  s    z/array_ufunc_errmsg_formatter.<locals>.<genexpr>zToperand type(s) all returned NotImplemented from __array_ufunc__({!r}, {!r}, {}): {})joinr   rK   r"   )dummyufuncmethodinputskwargsargs_stringargsZtypes_stringr   r   r   array_ufunc_errmsg_formatter  s    r   c             C   s    d | j| j}d |t|S )z= Format the error message for when __array_ufunc__ gives up. z{}.{}zOno implementation found for '{}' on types that implement __array_function__: {})r"   r^   r]   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   z, c             s   s   | ]}d |d  V  qdS )r   r   Nr   )r   ra   r   r   r   r   :  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   N)r"   )r   ra   r   r   r   r   D  s    )N)
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}))r+   in_argsout_argsr   )Zninr   rangeZnoutr"   r   	signaturer]   )r   r   r   r   r   r   r   _ufunc_doc_signature_formatter/  s(    



r   c             C   s>   y$t r| jd }n
| jd }d|jkS  tk
r8   dS X d S )Nrq   F)IS_PYPY__mro__r^   	Exception)rV   Z
ctype_baser   r   r   npy_ctypes_check_  s    

r  c               @   s    e Zd ZdZdd Zdd ZdS )	recursivea  
    A decorator class for recursive nested functions.
    Naive recursive nested functions hold a reference to themselves:

    def outer(*args):
        def stringify_leaky(arg0, *arg1):
            if len(arg1) > 0:
                return stringify_leaky(*arg1)  # <- HERE
            return str(arg0)
        stringify_leaky(*args)

    This design pattern creates a reference cycle that is difficult for a
    garbage collector to resolve. The decorator class prevents the
    cycle by passing the nested function in as an argument `self`:

    def outer(*args):
        @recursive
        def stringify(self, arg0, *arg1):
            if len(arg1) > 0:
                return self(*arg1)
            return str(arg0)
        stringify(*args)

    c             C   s
   || _ d S )N)func)rU   r  r   r   r   rW     s    zrecursive.__init__c             O   s   | j | f||S )N)r  )rU   r   r   r   r   r   rZ     s    zrecursive.__call__N)r]   r^   r_   __doc__rW   rZ   r   r   r   r   r  q  s   r  )7r  rM   resysplatformr~   Z
multiarrayr   r   r   rf   ImportErrorpython_implementationr  r   rL   r(   r-   r4   r>   compilerB   rI   rH   rJ   rR   rS   rd   re   rl   rq   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   r   <module>   s   

 4


0	  !$ 0