
Xc           @` sA  d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l m Z m	 Z	 d d l
 m Z m Z m Z d d l Z d d l m Z e j d k r e d	  Z n e d
  Z d   Z d   Z d   Z d   Z e j e d   Z e j e d   Z e j e d   Z i e e d  6Z d   Z d   Z d e _ d e  f d     YZ! d e  f d     YZ" d   Z# d   Z$ d   Z% d   Z& i d d 6d d 6d  d  6d! d! 6d" d" 6d# d# 6d$ d$ 6d% d% 6d& d& 6d' d' 6d( d( 6d) d) 6d* d* 6d+ d+ 6d, d, 6d- d- 6d. d/ 6d0 d1 6d2 d3 6d4 d5 6d6 d7 6d8 d8 6d9 d: 6Z' d; j( e' j)    Z* i d d 6d d 6d  d  6d! d! 6d< d" 6d= d# 6d> d$ 6d? d% 6d> d& 6d? d' 6d@ d( 6dA d) 6dB d* 6d+ d+ 6d, d, 6d. d/ 6d0 d1 6d4 d5 6d6 d7 6d8 d8 6d9 d: 6Z+ d; j( e+ j)    Z, dC e- dD  Z. dE   Z/ dF   Z0 dG   Z1 dH e2 f dI     YZ3 d S(J   s_   
A place for code to be called from core C-code.

Some things are more easily handled Python.

i    (   t   divisiont   absolute_importt   print_functionN(   t   asbytest
   basestringi   (   t   dtypet   arrayt   ndarray(   t   object_t   littlet   <t   >c         C` s  g  } t  |  j    } x | D] } |  | } t |  } t | t  sW | d
 k rf t d   n  | d k r | d | k r q n  t | d  } | d k  r t d   n  t | d d | } | d k r | d }	 n d  }	 | j	 | | | |	 f  q W| j
 d d	    g  | D] }
 |
 d ^ q} g  | D] }
 |
 d ^ q<} g  | D] }
 |
 d ^ qY} g  | D] }
 |
 d ^ qv} | | | | f S(   Ni   i   s   entry not a 2- or 3- tuplei   i    s   invalid offset.t   alignt   keyc         S` s   |  d S(   Ni   (    (   t   x(    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt   <lambda>*   s    (   i   i   (   t   listt   keyst   lent
   isinstancet   tuplet
   ValueErrort   intR   t   Nonet   appendt   sort(   t   adictR   t	   allfieldst   fnamest   fnamet   objt   nt   numt   formatt   titleR   t   namest   formatst   offsetst   titles(    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt   _makenames_list   s.    
c         C` s   y |  d } Wn t  k
 r' d  } n X| d  k rR t |  |  \ } } } } n g  } g  } g  } xm | D]e } |  | } | j | d  | j | d  t |  d k r | j | d  qk | j d   qk Wt i | d 6| d 6| d 6| d 6|  S(	   Nii    i   i   R#   R$   R%   R&   (   t   KeyErrorR   R'   R   R   R   (   R   R   R#   R$   R%   R&   t   namet   res(    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt
   _usefields5   s(    

c         C` s  |  j  } | d  k r |  j } | d  k rl |  j d  k r@ |  j S|  j j   } | rb |  j | f S|  j Sq t | d  | d f Sn  |  j } g  | D] } | | | f ^ q } g  } d } x | D] }	 |	 d | k r|	 d | }
 | j d d |
 f  | |
 7} n  t	 |	  d k r8|	 d |	 d f } n
 |	 d } |	 d j r}| t |	 d j d  |	 d j d f } n | t |	 d  f } | |	 d j
 7} | j |  q W|  j
 | k r|  j
 | }
 | j d d |
 f  n  | S(   Ni    i   t    s   |V%di   i   (   t   fieldsR   t   subdtypet   metadatat   strt   copyt   _array_descrR#   R   R   t   itemsize(   t
   descriptorR-   R.   t   newR#   R   t   ordered_fieldst   resultt   offsett   fieldR    R)   t   tup(    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyR2   U   sB    		
	$
c         C` s   t  j |  | |  S(   N(   R   t   __new__(   t   subtypet   shapeR   (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt   _reconstruct   s    sx   (?P<order1>[<>|=]?)(?P<repeats> *[(]?[ ,0-9L]*[)]? *)(?P<order2>[<>|=]?)(?P<dtype>[A-Za-z0-9.?]*(?:\[[a-zA-Z0-9,.]+\])?)s   \s*,\s*s   \s+$t   =c   
      C` s  d } g  } x	| t  |   k  rt j |  d | } y | j   \ } } } } Wn7 t t f k
 r t d t  |  d |  f   n X| j   } | t  |   k  rt j |  d | r t  |   } qt	 j |  d | } | st d t  |  d |  f   n  | j   } n  | t
 d  k r6| } nj | t
 d  k rQ| } nO t j | |  } t j | |  } | | k rt d | | f   n  | } | t
 d  t
 d  t g k rt
 d  } n  | | } | t
 d  k r| }	 n | t |  f }	 | j |	  q W| S(	   Ni    t   poss*   format number %d of "%s" is not recognizedi   R,   s/   inconsistent byte-order specification %s and %st   |R?   (   R   t	   format_ret   matcht   groupst	   TypeErrort   AttributeErrorR   t   endt   space_ret   sep_reR   t
   _convordert   gett   _nbot   evalR   (
   t   astrt
   startindexR7   t   mot   order1t   repeatst   order2R   t   ordert   newitem(    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt   _commastring   sL    		!
	c          C` s   t  j }  |  d  k	 r |  St d  j } | d k r@ t j }  n9 | d k rX t j }  n! | d k rp t j }  n	 t j }  |  t  _ |  S(   Nt   pt   it   lt   q(	   t   _getintp_ctypet   cacheR   R   t   chart   ctypest   c_intt   c_longt
   c_longlong(   t   valR]   (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyR[      s    			t   _missing_ctypesc           B` s   e  Z d    Z d   Z RS(   c         C` s   | S(   N(    (   t   selfR    R   (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt   cast   s    c         C` s   | S(   N(    (   Rd   R    (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt   c_void_p   s    (   t   __name__t
   __module__Re   Rf   (    (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyRc      s   	t   _ctypesc           B` s   e  Z d d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 e e d d d	 Z e e d d d
 Z e e	 d d d Z e e
 d d d Z RS(   c         C` sj   y t  |  _ Wn t k
 r, t   |  _ n X| |  _ | |  _ |  j j d k r] t |  _ n	 t	 |  _ d  S(   Ni    (
   R^   Ri   t   ImportErrorRc   t   _arrt   _datat   ndimt   Truet   _zerodt   False(   Rd   R   t   ptr(    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt   __init__   s    		c         C` s   |  j  j |  j |  S(   N(   Ri   Re   Rl   (   Rd   R   (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt   data_as   s    c         C` s'   |  j  r d  S| |  j j |  j j   S(   N(   Ro   R   Rk   Rm   R=   (   Rd   R   (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt   shape_as   s    	c         C` s'   |  j  r d  S| |  j j |  j j   S(   N(   Ro   R   Rk   Rm   t   strides(   Rd   R   (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt
   strides_as   s    	c         C` s   |  j  S(   N(   Rl   (   Rd   (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt   get_data   s    c         C` s*   |  j  r d  St   |  j j |  j j   S(   N(   Ro   R   R[   Rk   Rm   R=   (   Rd   (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt	   get_shape   s    	c         C` s*   |  j  r d  St   |  j j |  j j   S(   N(   Ro   R   R[   Rk   Rm   Ru   (   Rd   (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt   get_strides  s    	c         C` s   |  j  j |  j  S(   N(   Ri   Rf   Rl   (   Rd   (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt   get_as_parameter  s    t   docs   c-types datas   c-types shapes   c-types stridess   _as parameter_N(   Rg   Rh   R   Rr   Rs   Rt   Rv   Rw   Rx   Ry   Rz   t   propertyt   dataR=   Ru   t   _as_parameter_(    (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyRi      s   							c         C` s   |  j  } t |  } t | t  r0 | g } n  t | t t f  r xF | D]> } y | j |  WqL t k
 r t d | f   qL XqL Wt t |  |  St d | f   d  S(   Ns   unknown field name: %ss   unsupported order value: %s(   R#   R   R   R0   R   t   removeR   (   t   datatypeRT   t   oldnamest	   nameslistR)   (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt	   _newnames  s    	c         C` sW   |  j  } i | j d 6g  | j D] } | j | d ^ q  d 6} t |  d | d t S(   s  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
    R#   i    R$   R   R1   (   R   R#   R-   R   Rn   (   t   aryt   dtR)   t
   copy_dtype(    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt   _copy_fields!  s    	+c         C` s   | j  s |  j  r | d k r. | |  k r. d S|  j r xF |  j D]8 } |  j | d | k rA |  j | d | k rA d SqA Wn  t d   n  d S(   s   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

    i    Ni   s'   Cannot get/set field of an object array(   t	   hasobjectR#   R-   RE   (   t   oldtypet   newtypeR8   R)   (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt   _getfield_is_safe3  s    	c         C` s5   |  | k r d S| j  s" |  j  r1 t d   n  d S(   sz   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.

    Ns)   Cannot change data-type for object array.(   R   RE   (   R   R   (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt   _view_is_safeS  s
    t   ?t   S1t   ct   bt   Bt   ht   HRX   t   IRY   t   LRZ   t   Qt   et   ft   dt   gt   Ft   Zft   Dt   Zdt   Gt   Zgt   St   st   Ut   wt   Ot   VR   R,   t   i2t   u2t   i4t   u4t   i8t   u8t   f2t   @c         ` s/  i   d } t  } t  } d } t  } d g     f d        f d   } x"|  rud  }	 |  d d k r~ |  d }  Pn  d  }
 |  d d k r |  j d  } t t t |  d | !j d    }
 |  | d }  n  |  d d k r|  d } | d k rd } n  |  d }  n  | d k r0t } t } n t	 } t
 } d } |  d j   rd } x1 t d t |    D] } |  | j   snPqnqnWt |  |   } |  | }  n  t  } |  d  d k rt |  d d | d t \ }	 }  } } n |  d | k r| } |  d d k rd } n d } |  |  } |  | }  | d k } | | } | d k rl| d | 7} d } n  i d
 d	 6d
 d 6j | |  } t | |  }	 |	 j } n t d |    d } | d	 k r\| | } |	 j | } | | 7} | d k rB| d k s#|
 d  k	 r5t |
  d k r5t |	 |  }	 qB| | 7} n  | | t | |  } n  | d k rt |	 | f f  }	 n  |
 d  k	 rt |	 |
 f  }	 n  t  } |  r|  j d  r|  d j d  d } |  d | !} |  | d }  t } t } n	 |   } | s| rU|  k r2t d |   n  |	 | f  | <| sU   qUn  | } | |	 j 7} | | 7} qT Wt   d k r| r d d d k r| r d d } n t   } | | j } | d	 k r| | | 7} n  | r| rt | |  } n  | r'| |  | | f S| Sd  S(   Ni    i   c           ` s     d c d 7<d  S(   Ni    i   (    (    (   t   dummy_name_index(    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt   next_dummy_name  s    c          ` s6   x/ t  r1 d   d }  |   k r' |  S   q Wd  S(   Ns   f%di    (   Rn   (   R)   (   R   R-   R   (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt   get_dummy_name  s
    	t   }t   (t   )t   ,R   R?   R
   R   t   ^t   !i   s   T{t	   byteordert   is_subdtypet   ZR   t   USVs   %ds'   Unknown PEP 3118 data type specifier %rt   :s+   Duplicate field name '%s' in PEP3118 formatt   f0(   R   R?   R
   R   R   R   (   R   R   (   Rp   R   t   indexR   t   mapR   t   splitt   _pep3118_native_mapt   _pep3118_native_typecharst   _pep3118_standard_mapt   _pep3118_standard_typecharst   isdigitt   rangeR   t   _dtype_from_pep3118Rn   RK   R   t	   alignmentR   R3   t   _prodt   _add_trailing_paddingt   _gcdt
   startswitht   RuntimeError(   t   specR   R   R8   t   explicit_namet   this_explicit_namet   common_alignmentt
   is_paddingR   t   valueR=   t   jt   type_mapt   type_map_charsR3   R   t   next_byteordert   typechart	   dtypechart   numpy_byteordert   extra_offsett   start_paddingt   intra_paddingRX   R)   t   rett   padding(    (   R   R-   R   s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyR     s    		
%
		(	


	 
*		c         C` s2  |  j  d	 k r% i |  d f d 6} n t |  j   } |  j r |  j d d k r |  d j d k r d | d d j | | d d f | d <t |  }  n d } xE t r d | } | | k r d | |  j f | | <Pn  | d 7} q Wt |  }  d | k r.t |  j  } d | d <t	 |  |  _ n  |  S(
   sB   Inject the specified number of padding bytes at the end of a dtypei    R   iR,   R   s   V%di   s   pad%dN(
   R-   R   t   dictR#   R]   R3   R   Rn   R   R   (   R   R   t   vfieldsR   R)   R#   (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyR   K  s*    	

c         C` s%   d } x |  D] } | | 9} q W| S(   Ni   (    (   t   aRW   R   (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyR   j  s    c         C` s"   x | r | |  | }  } q W|  S(   s0   Calculate the greatest common divisor of a and b(    (   R   R   (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyR   p  s    	t   TooHardErrorc           B` s   e  Z RS(    (   Rg   Rh   (    (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyR   w  s   (4   t   __doc__t
   __future__R    R   R   t   ret   syst   numpy.compatR   R   t
   multiarrayR   R   R   R^   t   numerictypesR   R   RL   R'   R+   R2   R>   t   compileRB   RI   RH   RJ   RV   R[   R   R\   t   objectRc   Ri   R   R   R   R   R   t   joinR   R   R   R   Rp   R   R   R   R   R   R   (    (    (    s3   /tmp/pip-build-2Vcwy8/numpy/numpy/core/_internal.pyt   <module>   s   		 	0			/		3			 	 

			