ó
àÆ÷Xc           @` s¡  d  d l  m Z m Z m Z d  d l Z d  d l m Z d  d l m Z m	 Z	 m
 Z
 d  d l m Z d  d l m Z d  d l Z d e
 f d „  ƒ  YZ d d	 „ Z y d  d
 l m Z Wn e k
 rÏ e Z n Xe j Z e Z d e
 f d „  ƒ  YZ d e
 f d „  ƒ  YZ d e
 f d „  ƒ  YZ d e
 f d „  ƒ  YZ d „  Z d „  Z d „  Z  d „  Z! d „  Z" d „  Z# e e" ƒ Z$ e e# ƒ Z% e" e# f Z& e$ e% f Z' d S(   i    (   t   absolute_importt   print_functiont   divisionN(   t   gof(   t   Constantt   Generict   Op(   t
   key_to_cmp(   t   tensort   LoadFromDiskc           B` s;   e  Z d  Z d Z d	 d „ Z d „  Z d „  Z d „  Z RS(
   s„   
    An operation to load an array from disk.

    See Also
    --------
    load

    Notes
    -----
    Non-differentiable.

    t   dtypet   broadcastablet	   mmap_modec         C` sG   t  j | ƒ |  _ | |  _ | d k r: t d | ƒ ‚ n  | |  _ d  S(   Nt   cs@   The only supported values for mmap_mode are None and 'c', got %s(   NR   (   t   numpyR
   R   t   Nonet
   ValueErrorR   (   t   selfR
   R   R   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyt   __init__   s    	c         C` sO   t  | t ƒ r$ t t ƒ  | ƒ } n  t j |  | g t |  j d |  j ƒg ƒ S(   NR   (	   t
   isinstancet   strR   R   R   t   ApplyR   R
   R   (   R   t   path(    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyt	   make_node%   s    c         C` s‘   | d } | j  d ƒ d d k r6 t d | ƒ ‚ n  t j | d |  j ƒ} | j |  j k r t d |  j | j f ƒ ‚ n  | | d d <d  S(   Ni    t   .iÿÿÿÿt   npzs$   Expected a .npy file, got %s insteadR   s,   Expected an array of type %s, got %s instead(   t   splitR   R   t   loadR   R
   t	   TypeError(   R   t   nodet   inpt   outR   t   result(    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyt   perform+   s    
c         C` s   d |  j  |  j |  j f S(   Ns,   Load{dtype: %s, broadcastable: %s, mmep: %s}(   R
   R   R   (   R   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyt   __str__5   s    (   s   dtypes   broadcastables	   mmap_modeN(	   t   __name__t
   __module__t   __doc__t	   __props__R   R   R   R!   R"   (    (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR	      s   		
c         C` s   t  | | | ƒ |  ƒ S(   s)  
    Load an array from an .npy file.

    Parameters
    ----------
    path
        A Generic symbolic variable, that will contain a string
    dtype : data-type
        The data type of the array to be read.
    broadcastable
        The broadcastable pattern of the loaded array, for instance,
        (False,) for a vector, (False, True) for a column,
        (False, False) for a matrix.
    mmap_mode
        How the file will be loaded. None means that the
        data will be copied into an array in memory, 'c' means that the file
        will be mapped into virtual memory, so only the parts that are
        needed will be actually read from disk and put into memory.
        Other modes supported by numpy.load ('r', 'r+', 'w+') cannot
        be supported by Theano.

    Examples
    --------
    >>> from theano import *
    >>> path = Variable(Generic())
    >>> x = tensor.load(path, 'int64', (False,))
    >>> y = x*2
    >>> fn = function([path], y)
    >>> fn("stored-array.npy")  # doctest: +SKIP
    array([0, 2, 4, 6, 8], dtype=int64)

    (   R	   (   R   R
   R   R   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR   :   s    "(   t   MPIt   MPIRecvc           B` sJ   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z	 RS(   s¶   
    An operation to asynchronously receive an array to a remote host using MPI.

    See Also
    --------
    MPIRecv
    MPIWait

    Notes
    -----
    Non-differentiable.

    t   sourcet   tagt   shapeR
   c         C` sG   | |  _  | |  _ | |  _ t j | ƒ |  _ t f t | ƒ |  _ d  S(   N(   R)   R*   R+   R   R
   t   Falset   lenR   (   R   R)   R*   R+   R
   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR   |   s
    			c         C` s7   t  j |  g  t j t ƒ  ƒ t |  j d |  j ƒg ƒ S(   NR   (   R   R   t   theanot   VariableR   R   R
   R   (   R   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR   ƒ   s    c         C` sV   t  j |  j d |  j ƒ} t j | |  j |  j ƒ } | | d d <| | d d <d  S(   NR
   i    i   (   R   t   zerosR+   R
   t   commt   IrecvR)   R*   (   R   R   R   R   t   datat   request(    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR!   ˆ   s    c         C` s    d |  j  |  j |  j |  j f S(   Ns2   MPIRecv{source: %d, tag: %d, shape: %s, dtype: %s}(   R)   R*   R+   R
   (   R   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR"      s    c         C` s   d  |  j g S(   N(   R   R+   (   R   R   t   shapes(    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyt   infer_shape”   s    c         C` s   t  S(   N(   R,   (   R   R   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyt   do_constant_folding—   s    (   s   sources   tags   shapes   dtype(
   R#   R$   R%   R&   R   R   R!   R"   R6   R7   (    (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR(   k   s   					t   MPIRecvWaitc           B` sH   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z i d g d 6Z RS(	   s   
    An operation to wait on a previously received array using MPI.

    See Also
    --------
    MPIRecv

    Notes
    -----
    Non-differentiable.

    R*   c         C` s   | |  _  d  S(   N(   R*   (   R   R*   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR   «   s    c         C` s.   t  j |  | | g t | j d | j ƒg ƒ S(   NR   (   R   R   R   R
   R   (   R   R4   R3   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR   ®   s    c         C` s0   | d } | d } | j  ƒ  | | d d <d  S(   Ni    i   (   t   wait(   R   R   R   R   R4   R3   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR!   ³   s    


c         C` s   | d g S(   Ni   (    (   R   R   R5   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR6   ¼   s    i   i    (   s   tag(	   R#   R$   R%   R&   R   R   R!   R6   t   view_map(    (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR8   ›   s   					t   MPISendc           B` sH   e  Z d  Z d	 Z d „  Z d „  Z i d g d 6Z d „  Z d „  Z RS(
   s·   
    An operation to asynchronously Send an array to a remote host using MPI.

    See Also
    --------
    MPIRecv
    MPISendWait

    Notes
    -----
    Non-differentiable.

    t   destR*   c         C` s   | |  _  | |  _ d  S(   N(   R<   R*   (   R   R<   R*   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR   Ó   s    	c         C` s.   t  j |  | g t j t ƒ  ƒ | j ƒ  g ƒ S(   N(   R   R   R.   R/   R   t   type(   R   R3   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR   ×   s    i    i   c         C` sE   | d } t  j | |  j |  j ƒ } | | d d <| | d d <d  S(   Ni    i   (   R1   t   IsendR<   R*   (   R   R   R   R   R3   R4   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR!   Ü   s    
c         C` s   d |  j  |  j f S(   Ns   MPISend{dest: %d, tag: %d}(   R<   R*   (   R   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR"   å   s    (   s   dests   tag(	   R#   R$   R%   R&   R   R   R:   R!   R"   (    (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR;   Â   s   				t   MPISendWaitc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   s™   
    An operation to wait on a previously sent array using MPI.

    See Also
    --------
    MPISend

    Notes
    -----
    Non-differentiable.

    R*   c         C` s   | |  _  d  S(   N(   R*   (   R   R*   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR   ù   s    c         C` s(   t  j |  | | g t j t ƒ  ƒ g ƒ S(   N(   R   R   R.   R/   R   (   R   R4   R3   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR   ü   s    c         C` s&   | d } | j  ƒ  t | d d <d  S(   Ni    (   R9   t   True(   R   R   R   R   R4   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR!      s    

(   s   tag(   R#   R$   R%   R&   R   R   R!   (    (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyR?   é   s
   		c         C` s   t  | | ƒ |  ƒ S(   s   
    Non blocking send.
    (   R;   (   t   varR<   R*   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyt   isend  s    c         C` s   t  | ƒ t |  | | ƒ Œ  S(   s   
    Blocking send.
    (   R?   RB   (   RA   R<   R*   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyt   send  s    c         C` s   t  | | |  | ƒ ƒ  S(   s   
    Non-blocking receive.
    (   R(   (   R+   R
   R)   R*   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyt   irecv  s    c         C` s   t  | ƒ t |  | | | ƒ Œ  S(   s   
    Blocking receive.
    (   R8   RD   (   R+   R
   R)   R*   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyt   recv  s    c         C` s<   t  |  j t t f ƒ r d St  |  j t t f ƒ r8 d Sd S(   s:   Wait as long as possible on Waits, Start Send/Recvs early.i   iÿÿÿÿi    (   R   t   opR8   R?   R(   R;   (   t   a(    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyt   mpi_send_wait_key#  s
    c         C` s0   t  |  j t t t t f ƒ r( |  j j Sd Sd S(   sC   Break MPI ties by using the variable tag - prefer lower tags first.i    N(   R   RF   R;   R(   R8   R?   R*   (   RG   (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyt   mpi_tag_key,  s    
((   t
   __future__R    R   R   R   R.   R   t
   theano.gofR   R   R   t   theano.gof.schedR   t   theano.tensorR   R	   R   R   t   mpi4pyR'   t   ImportErrorR,   t   mpi_enabledt
   COMM_WORLDR1   R@   R(   R8   R;   R?   RB   RC   RD   RE   RH   RI   t   mpi_send_wait_cmpt   mpi_tag_cmpt   mpi_keyst   mpi_cmps(    (    (    s0   /tmp/pip-build-X4mzal/theano/theano/tensor/io.pyt   <module>   s8   -(
	0''							