ó
ßüÚ\c           @` sK  d  d l  m Z m Z m Z d  d l Z d d l m Z m Z d d l	 m
 Z
 m Z d d l m Z d d l m Z d d	 l m Z d
 „  Z e
 j e j ƒ d „  ƒ Z e j e j ƒ d „  ƒ Z e
 j e j j j ƒ d „  ƒ Z e j e j j j ƒ d „  ƒ Z e
 j e j j j ƒ d „  ƒ Z e j e j j j ƒ d „  ƒ Z d S(   i    (   t   print_functiont   divisiont   absolute_importNi   (   t   frame_split_sizet   merge_frames(   t   dask_serializet   dask_deserialize(   t   picklei   (   t   gcd(   t
   log_errorsc         C` s%   |  j  j } | d k r! d } n  | S(   sc    Itemsize of dtype

    Try to return the itemsize of the base element, return 8 as a fallback
    iÿ   i   (   t   baset   itemsize(   t   dtt   result(    (    s9   lib/python2.7/site-packages/distributed/protocol/numpy.pyR      s    	c         C` sE  |  j  j r5 i t d 6} t j |  ƒ g } | | f S|  j  j d k rÍ y0 d t j j |  j  ƒ f } t j | d ƒ Wqß t k
 rÉ |  j  j t	 j
 k	 s® |  j  j d k r´ ‚  qÊ d |  j  j f } qß Xn d |  j  j f } |  j s |  j } |  j ƒ  } nZ |  j j s|  j j r6|  j } |  j d d ƒ } n$ t	 j |  ƒ }  |  j } |  j ƒ  } | j  j sx| j  j d k r| j d t |  j  j d ƒ ƒ } n  y | j } Wn6 t k
 râ| j d t |  j  j d ƒ ƒ j } n Xi | d	 6|  j d
 6| d 6} |  j d k r"t | g ƒ } n	 | g } |  j g | d <| | f S(   NR   t   Vi   i    t   ordert   Ki   s   u%dt   dtypet   shapet   stridesg     jø@t   lengths(   R   t	   hasobjectt   TrueR   t   dumpst   kindt   loadst	   Exceptiont   typet   npt   voidt	   alignmentt   descrt   strR   R   t   ravelt   flagst   c_contiguoust   f_contiguoust   ascontiguousarrayt   fieldsR   t   viewR   t   datat
   ValueErrort   nbytesR   (   t   xt   headert   framesR   R   R(   (    (    s9   lib/python2.7/site-packages/distributed/protocol/numpy.pyt   serialize_numpy_ndarray   sD    
'				%)	c         C` sÀ   t  ƒ  ± t | ƒ d k r. t |  | ƒ } n  |  j d ƒ rN t j | d ƒ S|  d \ } } | rv t j | ƒ } n t j | ƒ } t j |  d d | d | d d |  d ƒ} | SWd  QXd  S(   Ni   R   i    R   R   t   bufferR   (	   R	   t   lenR   t   getR   R   R   R   t   ndarray(   R,   R-   t	   is_customR   R+   (    (    s9   lib/python2.7/site-packages/distributed/protocol/numpy.pyt   deserialize_numpy_ndarrayS   s    
'c         C` s
   i  g  f S(   N(    (   R+   (    (    s9   lib/python2.7/site-packages/distributed/protocol/numpy.pyt   serialize_numpy_ma_maskedi   s    c         C` s
   t  j j S(   N(   R   t   mat   masked(   R,   R-   (    (    s9   lib/python2.7/site-packages/distributed/protocol/numpy.pyt   deserialize_numpy_ma_maskedn   s    c         C` sØ   t  |  j ƒ \ } } i | d 6t | ƒ d 6} |  j t j j k	 rp t  |  j ƒ \ } } | | d <| | 7} n  t |  j t j	 t j
 t j f ƒ r¬ t |  j j ƒ  f } n t t j |  j ƒ f } | | d <| | f S(   Ns   data-headert   nframess   mask-headers
   fill-value(   R.   R(   R0   t   maskR   R6   t   nomaskt
   isinstancet
   fill_valuet   integert   floatingt   bool_t   Falset   itemR   R   R   (   R+   t   data_headerR-   R,   t   mask_headert   mask_framest   serialized_fill_value(    (    s9   lib/python2.7/site-packages/distributed/protocol/numpy.pyt   serialize_numpy_maskedarrays   s    
$
c   
      C` s­   |  d } | |  d  } t  | | ƒ } d |  k r] |  d } | |  d } t  | | ƒ } n t j j } |  d \ } }	 | r‘ t j |	 ƒ }	 n  t j j | d | d |	 ƒS(   Ns   data-headerR9   s   mask-headers
   fill-valueR:   R=   (   R4   R   R6   R;   R   R   t   masked_array(
   R,   R-   RC   t   data_framesR(   RD   RE   R:   t
   pickled_fvR=   (    (    s9   lib/python2.7/site-packages/distributed/protocol/numpy.pyt   deserialize_numpy_maskedarrayˆ   s    

(   t
   __future__R    R   R   t   numpyR   t   utilsR   R   t	   serializeR   R   t    R   t   compatibilityR   R	   R   t   registerR2   R.   R4   R6   t   coret   MaskedConstantR5   R8   t   MaskedArrayRG   RK   (    (    (    s9   lib/python2.7/site-packages/distributed/protocol/numpy.pyt   <module>   s   	;!!!