ó
™^c           @   s�   d  d l  Z  d  d l m Z m Z m Z m Z m Z m Z m Z m	 Z	 m
 Z
 m Z m Z d  d l m Z d  d l m Z d d d „  ƒ  YZ d S(   iÿÿÿÿN(   t   Typet   int8_tt   int16_tt   int32_tt   int64_tt   uint8_tt   uint16_tt   uint32_tt   uint64_tt   float_t   double_(   t   parse_assigned_variable_name(   t   Namet   Constantc           B   s5  e  Z d  d d d d d d g Z e e e e e e e	 e
 e e g
 Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z e d „  ƒ Z e d „  ƒ Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d) d „ ƒ Z e d) d) d „ ƒ Z e d) d) d) d) d „ ƒ Z  e d) d) d) d) d) d) d) d) d „ ƒ Z! e d) d „ ƒ Z" e d) d) d „ ƒ Z# e d) d) d) d) d „ ƒ Z$ e d) d) d) d) d) d) d) d) d „ ƒ Z% e d) d) d) d) d) d) d) d) d) d) d) d) d) d) d) d) d „ ƒ Z& e d) d) d) d) d) d) d) d) d „ ƒ Z' e d) d) d) d) d) d) d) d) d) d) d) d) d) d) d) d) d „ ƒ Z( e d) d „ ƒ Z) e d) d) d  „ ƒ Z* e d) d) d) d) d! „ ƒ Z+ e d) d" „ ƒ Z, e d) d) d# „ ƒ Z- e d) d) d) d) d$ „ ƒ Z. e d) d) d) d) d) d) d) d) d% „ ƒ Z/ e d& „  ƒ Z0 e d' „  ƒ Z1 e d( „  ƒ Z2 RS(*   i   i   i   i   i   i    i@   c         C   s?  t  | t j ƒ s t d ƒ ‚ | t j k sd t d t | ƒ d j t t t	 t j ƒ ƒ ƒ f ƒ ‚ t  | t j ƒ s‚ t d ƒ ‚ | | d k sž t d ƒ ‚ t  | t
 ƒ s¹ t d ƒ ‚ | t j k sä t d d j t j ƒ ƒ ‚ t  | t ƒ sù t ‚ | |  _ | |  _ | |  _ | |  _ | f |  _ d  |  _ d  |  _ d  S(	   Ns    Constant size must be an integers4   Unsupported size %s: the only supported sizes are %ss   , s0   The number of contant repeats must be an integeri    sJ   The number of constant repeats must divide constant size without remainders2   Element type must be an instance of peachpy.c.Types   The only supported types are %s(   t
   isinstancet   sixt   integer_typest   AssertionErrorR   t   _supported_sizest   strt   joint   mapt   sortedR    t   _supported_typesR   t   sizet   repeatst   element_ctypet   datat   namet   Nonet   labelt   prefix(   t   selfR   R   R   R   R   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt   __init__   s     1					c            s@   d |  j  |  j d ‰  d d j ‡  f d †  |  j Dƒ ƒ d S(   Ns   %%0%dXi   t   <s   , c         3   s   |  ] } ˆ  | Vq d  S(   N(    (   t   .0R   (   t   format_spec(    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pys	   <genexpr>'   s    t   >(   R   R   R   R   (   R    (    (   R$   s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt   __str__%   s    c         C   s'   t  |  j ƒ t  |  j ƒ At  |  j ƒ AS(   N(   t   hashR   R   R   (   R    (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt   __hash__)   s    c         C   s1   t  | t ƒ o0 |  j | j k o0 |  j | j k S(   N(   R   R   R   R   (   R    t   other(    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt   __eq__,   s    c         C   s�   d d l  m } t | | ƒ s% t ‚ i | j d 6| j d 6| j d 6| j d 6|  j |  j	 } t
 ƒ  j g  |  j D] } | | ƒ ^ qt ƒ S(   Niÿÿÿÿ(   t   Encoderi   i   i   i   (   t   peachpy.encoderR+   R   R   t   uint8t   uint16t   uint32t   uint64R   R   t	   bytearrayR   R   (   R    t   encoderR+   t   encode_functionR   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt   encode/   s    



c         C   s   |  j  d k r d S|  j  Sd  S(   Ni
   i   (   R   (   R    (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt	   alignment:   s    c         C   sE   d d l  m } m } |  j | | j ƒ ƒ } d j d „  | Dƒ ƒ S(   Niÿÿÿÿ(   R+   t
   Endiannesst    c         s   s   |  ] } d  | Vq d S(   s   %02XN(    (   R#   t   byte(    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pys	   <genexpr>E   s    (   R,   R+   R6   R4   t   LittleR   (   R    R+   R6   t
   bytestring(    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt   as_hexA   s    c         C   s)   | d k r d |  j  d St |  ƒ Sd  S(   Nt   got   const0xs   (SB)(   R;   R   (   R    t   assembly_format(    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt   formatG   s    c         G   sk  d d l  m } m } | | ƒ s( t ‚ g  | D] } | d  k	 r/ | ^ q/ } t | ƒ d k rn t d ƒ ‚ n  t | ƒ d k r¥ t | ƒ | k r¥ t d | ƒ ‚ n  x} t | ƒ D]o \ } } | | ƒ sã t d t	 | ƒ ƒ ‚ n  | | ƒ st d | ƒ ‚ n  | d k  r² | | c d	 7<q² q² Wt | ƒ d k rK| d g | } n  t
 d
 | | t | ƒ t |  ƒ S(   Niÿÿÿÿ(   t   is_intt   is_int64i    s-   At least one constant value must be specifiedi   s'   Either 1 or %d values must be specifieds   The value %s is not an integers%   The number %d is not a 64-bit integerl            i   (   t   peachpy.utilR@   RA   R   R   t   lent
   ValueErrort	   enumeratet	   TypeErrorR   R   t   tupleR   (   R   t   nt   argsR@   RA   t   argt   it   number(    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt	   _uint64xNM   s"    %$c         G   sk  d d l  m } m } | | ƒ s( t ‚ g  | D] } | d  k	 r/ | ^ q/ } t | ƒ d k rn t d ƒ ‚ n  t | ƒ d k r¥ t | ƒ | k r¥ t d | ƒ ‚ n  x} t | ƒ D]o \ } } | | ƒ sã t d t	 | ƒ ƒ ‚ n  | | ƒ st d | ƒ ‚ n  | d k  r² | | c d	 7<q² q² Wt | ƒ d k rK| d g | } n  t
 d
 | | t | ƒ t |  ƒ S(   Niÿÿÿÿ(   R@   t   is_int32i    s-   At least one constant value must be specifiedi   s'   Either 1 or %d values must be specifieds   The value %s is not an integers%   The number %d is not a 32-bit integerI       i   (   RB   R@   RN   R   R   RC   RD   RE   RF   R   R   RG   R   (   R   RH   RI   R@   RN   RJ   RK   RL   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt	   _uint32xNa   s"    %$c         G   sk  d d l  m } m } | | ƒ s( t ‚ g  | D] } | d  k	 r/ | ^ q/ } t | ƒ d k rn t d ƒ ‚ n  t | ƒ d k r¥ t | ƒ | k r¥ t d | ƒ ‚ n  x} t | ƒ D]o \ } } | | ƒ sã t d t	 | ƒ ƒ ‚ n  | | ƒ st d | ƒ ‚ n  | d k  r² | | c d	 7<q² q² Wt | ƒ d k rK| d g | } n  t
 d
 | | t | ƒ t |  ƒ S(   Niÿÿÿÿ(   R@   RN   i    s-   At least one constant value must be specifiedi   s'   Either 1 or %d values must be specifieds   The value %s is not an integers%   The number %d is not a 16-bit integerI       i   (   RB   R@   RN   R   R   RC   RD   RE   RF   R   R   RG   R   (   R   RH   RI   R@   RN   RJ   RK   RL   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt	   _uint16xNu   s"    %$c         G   så   g  | D] } | d  k	 r | ^ q } t | ƒ d k rF t d ƒ ‚ n  t | ƒ d k r} t | ƒ | k r} t d | ƒ ‚ n  g  | D] } t j | ƒ ^ q„ } t | ƒ d k rÅ | d g | } n  t d | | t | ƒ t |  ƒ S(   Ni    s-   At least one constant value must be specifiedi   s'   Either 1 or %d values must be specifiedi   (   R   RC   RD   R   t   _parse_float64RG   R
   (   R   RH   RI   RJ   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt
   _float64xN‰   s    %$"c         G   så   g  | D] } | d  k	 r | ^ q } t | ƒ d k rF t d ƒ ‚ n  t | ƒ d k r} t | ƒ | k r} t d | ƒ ‚ n  g  | D] } t j | ƒ ^ q„ } t | ƒ d k rÅ | d g | } n  t d | | t | ƒ t |  ƒ S(   Ni    s-   At least one constant value must be specifiedi   s'   Either 1 or %d values must be specifiedi   (   R   RC   RD   R   t   _parse_float32RG   R
   (   R   RH   RI   RJ   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt
   _float32xN•   s    %$"c         C   sh   | d  k	 r+ t j | ƒ t d | ƒ } n* d d  l } t d t | j ƒ  d ƒ ƒ } t j | d |  ƒ S(   NR   iÿÿÿÿt   prenames   Constant.uint64i   (   R   R   t
   check_namet   inspectR   t   stackR   RM   (   RL   R   RW   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyR0   ¡   s    c         C   sk   | d  k	 r+ t j | ƒ t d | ƒ } n* d d  l } t d t | j ƒ  d ƒ ƒ } t j | d |  | ƒ S(   NR   iÿÿÿÿRU   s   Constant.uint64x2i   (   R   R   RV   RW   R   RX   R   RM   (   t   number1t   number2R   RW   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt   uint64x2¬   s    c         C   sq   | d  k	 r+ t j | ƒ t d | ƒ } n* d d  l } t d t | j ƒ  d ƒ ƒ } t j | d |  | | | ƒ S(   NR   iÿÿÿÿRU   s   Constant.uint64x4i   (   R   R   RV   RW   R   RX   R   RM   (   RY   RZ   t   number3t   number4R   RW   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt   uint64x4·   s    c	   
      C   s}   | d  k	 r+ t j | ƒ t d | ƒ } n* d d  l }	 t d t |	 j ƒ  d ƒ ƒ } t j | d |  | | | | | | | ƒ
 S(   NR   iÿÿÿÿRU   s   Constant.uint64x8i   (   R   R   RV   RW   R   RX   R   RM   (
   RY   RZ   R\   R]   t   number5t   number6t   number7t   number8R   RW   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt   uint64x8Â   s    c         C   sh   | d  k	 r+ t j | ƒ t d | ƒ } n* d d  l } t d t | j ƒ  d ƒ ƒ } t j | d |  ƒ S(   NR   iÿÿÿÿRU   s   Constant.uint32i   (   R   R   RV   RW   R   RX   R   RO   (   RL   R   RW   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyR/   Ð   s    c         C   sk   | d  k	 r+ t j | ƒ t d | ƒ } n* d d  l } t d t | j ƒ  d ƒ ƒ } t j | d |  | ƒ S(   NR   iÿÿÿÿRU   s   Constant.uint32x2i   (   R   R   RV   RW   R   RX   R   RO   (   RY   RZ   R   RW   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt   uint32x2Û   s    c         C   sq   | d  k	 r+ t j | ƒ t d | ƒ } n* d d  l } t d t | j ƒ  d ƒ ƒ } t j | d |  | | | ƒ S(   NR   iÿÿÿÿRU   s   Constant.uint32x4i   (   R   R   RV   RW   R   RX   R   RO   (   RY   RZ   R\   R]   R   RW   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt   uint32x4æ   s    c	   
      C   s}   | d  k	 r+ t j | ƒ t d | ƒ } n* d d  l }	 t d t |	 j ƒ  d ƒ ƒ } t j | d |  | | | | | | | ƒ
 S(   NR   iÿÿÿÿRU   s   Constant.uint32x8i   (   R   R   RV   RW   R   RX   R   RO   (
   RY   RZ   R\   R]   R_   R`   Ra   Rb   R   RW   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt   uint32x8ñ   s    c         C   s•   | d  k	 r+ t j | ƒ t d | ƒ } n* d d  l } t d t | j ƒ  d ƒ ƒ } t j | d |  | | | | | | | | |	 |
 | | | | | ƒ S(   NR   iÿÿÿÿRU   s   Constant.uint32x16i   (   R   R   RV   RW   R   RX   R   RO   (   RY   RZ   R\   R]   R_   R`   Ra   Rb   t   number9t   number10t   number11t   number12t   number13t   number14t   number15t   number16R   RW   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt	   uint32x16ÿ   s    c	   
      C   s}   | d  k	 r+ t j | ƒ t d | ƒ } n* d d  l }	 t d t |	 j ƒ  d ƒ ƒ } t j | d |  | | | | | | | ƒ
 S(   NR   iÿÿÿÿRU   s   Constant.uint16x8i   (   R   R   RV   RW   R   RX   R   RP   (
   RY   RZ   R\   R]   R_   R`   Ra   Rb   R   RW   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt   uint16x8  s    c         C   s•   | d  k	 r+ t j | ƒ t d | ƒ } n* d d  l } t d t | j ƒ  d ƒ ƒ } t j | d |  | | | | | | | | |	 |
 | | | | | ƒ S(   NR   iÿÿÿÿRU   s   Constant.uint16x16i   (   R   R   RV   RW   R   RX   R   RP   (   RY   RZ   R\   R]   R_   R`   Ra   Rb   Rg   Rh   Ri   Rj   Rk   Rl   Rm   Rn   R   RW   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt	   uint16x16  s    c         C   sh   | d  k	 r+ t j | ƒ t d | ƒ } n* d d  l } t d t | j ƒ  d ƒ ƒ } t j | d |  ƒ S(   NR   iÿÿÿÿRU   s   Constant.float64i   (   R   R   RV   RW   R   RX   R   RR   (   RL   R   RW   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt   float64/  s    c         C   sk   | d  k	 r+ t j | ƒ t d | ƒ } n* d d  l } t d t | j ƒ  d ƒ ƒ } t j | d |  | ƒ S(   NR   iÿÿÿÿRU   s   Constant.float64x2i   (   R   R   RV   RW   R   RX   R   RR   (   RY   RZ   R   RW   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt	   float64x2:  s    c         C   sq   | d  k	 r+ t j | ƒ t d | ƒ } n* d d  l } t d t | j ƒ  d ƒ ƒ } t j | d |  | | | ƒ S(   NR   iÿÿÿÿRU   s   Constant.float64x4i   (   R   R   RV   RW   R   RX   R   RR   (   RY   RZ   R\   R]   R   RW   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt	   float64x4E  s    c         C   sh   | d  k	 r+ t j | ƒ t d | ƒ } n* d d  l } t d t | j ƒ  d ƒ ƒ } t j | d |  ƒ S(   NR   iÿÿÿÿRU   s   Constant.float32i   (   R   R   RV   RW   R   RX   R   RT   (   RL   R   RW   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt   float32P  s    c         C   sk   | d  k	 r+ t j | ƒ t d | ƒ } n* d d  l } t d t | j ƒ  d ƒ ƒ } t j | d |  | ƒ S(   NR   iÿÿÿÿRU   s   Constant.float32x2i   (   R   R   RV   RW   R   RX   R   RT   (   RY   RZ   R   RW   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt	   float32x2[  s    c         C   sq   | d  k	 r+ t j | ƒ t d | ƒ } n* d d  l } t d t | j ƒ  d ƒ ƒ } t j | d |  | | | ƒ S(   NR   iÿÿÿÿRU   s   Constant.float32x4i   (   R   R   RV   RW   R   RX   R   RT   (   RY   RZ   R\   R]   R   RW   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt	   float32x4f  s    c	   
      C   s}   | d  k	 r+ t j | ƒ t d | ƒ } n* d d  l }	 t d t |	 j ƒ  d ƒ ƒ } t j | d |  | | | | | | | ƒ
 S(   NR   iÿÿÿÿRU   s   Constant.float32x8i   (   R   R   RV   RW   R   RX   R   RT   (
   RY   RZ   R\   R]   R_   R`   Ra   Rb   R   RW   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt	   float32x8q  s    c         C   s)   d d  l  } | j  d |  g ƒ } | d S(   Niÿÿÿÿt   fi    (   t   array(   RL   Rz   t   float_array(    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt   _convert_to_float32  s    c         C   sG  t  |  t ƒ r* t j t j |  ƒ ƒ }  nq t  |  t ƒ r… y% t j t j t j |  ƒ ƒ ƒ }  Wq› t k
 r� t d |  ƒ ‚ q› Xn t d t |  ƒ ƒ ‚ |  d k s³ |  d k r· d S|  d k rÇ d S|  d k r× d	 S|  j	 d
 ƒ } |  j
 d ƒ } |  j d ƒ } |  t | ƒ | !} | d k s5| d k s5t ‚ |  | d | !} | d k rrt | ƒ d k rrt | ƒ d >S|  | d } t | ƒ d } | d k r®t | d ƒ } n= | d k  rÔt | d ƒ d | >} n t | d ƒ | d ?} t | ƒ } | d k r| d | d ?} d } n  | t | d ƒ d >t | ƒ d >Sd  S(   Ns8   The string %s is not a hexadecimal floating-point numbers&   Unsupported type of constant number %st   infs   +infi  €s   -infI  €ÿ    t   nani  Àt   -t   .t   pt   0x0t   0x1i   i    i   i   i   i   i�ÿÿÿi~   i   i  € (   R   t   floatt   hexR   R|   R   t   fromhexRD   RF   t
   startswitht   indext   rindext   intR   RC   (   RL   t   is_negativet   point_positiont   exp_positiont   number_prefixt   mantissat   exponentt   mantissa_bits(    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyRS   …  sD    %	c         C   sV  t  |  t ƒ r! t j |  ƒ }  nh t  |  t ƒ rs y t j t j |  ƒ ƒ }  Wq‰ t k
 ro t d |  ƒ ‚ q‰ Xn t d t |  ƒ ƒ ‚ |  d k s¡ |  d k r¥ d S|  d k rµ d S|  d k rÅ d	 S|  j d
 ƒ } |  j d ƒ } |  j	 d ƒ } |  t
 | ƒ | !} | d k s#| d k s#t ‚ |  | d | !} | d k rft
 | ƒ d k sXt ‚ t
 | ƒ d >S|  | d } t | ƒ d } | d k r¢t
 | d ƒ } n= | d k  rÈt
 | d ƒ d | >} n t
 | d ƒ | d ?} t
 | ƒ } | d k r| d | d ?} d } n | d k r.d } d } n  | t
 | d ƒ d >t
 | ƒ d >Sd  S(   Ns8   The string %s is not a hexadecimal floating-point numbers&   Unsupported type of constant number %sR}   s   +infI      ðs   -infl         € R~   I      øR   R€   R�   R‚   Rƒ   i   i    i?   i   i4   i   iüÿÿiþ  iÿ  I       (   R   R„   R…   R   R†   RD   RF   R‡   Rˆ   R‰   RŠ   R   RC   (   RL   R‹   RŒ   R�   RŽ   R�   R�   R‘   (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyRQ   °  sL    		N(3   t   __name__t
   __module__R   R   R   R   R   R   R   R   R   R	   R
   R   R!   R&   R(   R*   R4   t   propertyR5   R;   R?   t   staticmethodRM   RO   RP   RR   RT   R   R0   R[   R^   Rc   R/   Rd   Re   Rf   Ro   Rp   Rq   Rr   Rs   Rt   Ru   Rv   Rw   Rx   R|   RS   RQ   (    (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyR   
   s�   						


	


				





	+(    (   R   t   peachpy.c.typesR    R   R   R   R   R   R   R   R   R	   R
   t   peachpy.parseR   t   peachpy.nameR   R   (    (    (    s<   /torch/pytorch/third_party/python-peachpy/peachpy/literal.pyt   <module>   s   L