σ
ΰΖχXc           @` sj   d  d l  m Z m Z m Z d  d l Z d  d l Z d  d l m Z d  d l m	 Z	 d   Z
 d   Z d S(   i    (   t   absolute_importt   print_functiont   divisionN(   t   izip(   t   hash_from_codec         C` sh   |  j  d s t j |   }  n  t t |   t t |  j   t t |  j   t t |  j    S(   sd   
    Return a hash from an ndarray.

    It takes care of the data, shapes, strides and dtype.

    t   C_CONTIGUOUS(   t   flagst   numpyt   ascontiguousarrayR   t   strt   shapet   stridest   dtype(   t   data(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/utils.pyt   hash_from_ndarray	   s
    /c         ` sx  t  |  d  s+ |  j t j j j    n  g  |  j D]# } |  j j | D] } | ^ qI q5 } g  |  j j j	   D] } | D] } | ^ q{ qq } t j
 | |  } t g  | j   D] } | |  j k ^ q²  rί t d   n  g  |  j D] } | | D] }	 |	 ^ qχ qι }
 | |
   } t t | |     i  } x> |  j j D]0 } t   f d   |  j j | D  | | <q@W| S(   s½  
    Compute the numeric shape of all intermediate variables given input shapes.

    Parameters
    ----------
    fgraph
        The theano.FunctionGraph in question.
    input_shapes : dict
        A dict mapping input to shape.

    Returns
    -------
    shapes : dict
        A dict mapping variable to shape

    .. warning:: This modifies the fgraph. Not pure.

    Examples
    --------
    >>> import theano
    >>> x = theano.tensor.matrix('x')
    >>> y = x[512:]; y.name = 'y'
    >>> fgraph = theano.FunctionGraph([x], [y], clone=False)
    >>> d = shape_of_variables(fgraph, {x: (1024, 1024)})
    >>> d[y]
    (array(512), array(1024))
    >>> d[x]
    (array(1024), array(1024))
    t   shape_featuresΖ   input_shapes keys aren't in the fgraph.inputs. FunctionGraph() interface changed. Now by default, it clones the graph it receives. To have the old behavior, give it this new parameter `clone=False`.c         3` s   |  ] }   | Vq d  S(   N(    (   t   .0t   sym(   t   sym_to_num_dict(    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/utils.pys	   <genexpr>Y   s   (   t   hasattrt   attach_featuret   theanot   tensort   optt   ShapeFeaturet   inputsR   t   shape_oft   valuest   functiont   anyt   keyst
   ValueErrort   dictR   t   tuple(   t   fgrapht   input_shapest   inpt	   dimensiont
   input_dimsR
   t   output_dimst   compute_shapest   it   dimt   numeric_input_dimst   numeric_output_dimst   lt   var(    (   R   s3   /tmp/pip-build-X4mzal/theano/theano/tensor/utils.pyt   shape_of_variables!   s&    #.(   t
   __future__R    R   R   R   R   t   theano.compatR   t   theano.gof.utilsR   R   R/   (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/utils.pyt   <module>   s   	