
Xc           @` s  d  Z  d d l m Z m Z m Z d d l m Z d d l Z d d l Z d d l	 Z	 d d l
 m Z d d l m Z d d l Z d d l Z d d l m Z d d l m Z d d	 l m Z d d
 l m Z m Z m Z m Z d d l m Z d d l m Z d d l m Z m Z 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 d l m+ Z+ m, Z, d d l- m. Z. m/ Z/ d d l0 m1 Z1 m2 Z2 m3 Z3 d d l4 Z d d l5 m6 Z6 d d l5 m7 Z7 d d l5 m8 Z8 d d l9 m: Z: m; Z; m< Z< m= Z= d d l> Z> e> j? d  Z@ d ZA eB ZC eD ZE eF ZG eH eI eJ e( jK   ZL eH eI eJ e( jM   ZN eH eI eJ e( jO   ZP eH eI eJ e( j   ZQ eH eI eJ e( jR   ZS eH eI eJ e( jT   ZU eH eI eJ e( jV   ZW eH eI eJ e( jX   ZY d eZ f d     YZ[ d   Z\ e+ j] e\  g  Z^ d   Z_ d   Z` ea ea d   Zb eb Zc eb Zd ea ea ea d!  Ze ea ea ea d"  Zf eg ef _h i  Zi d#   Zj ek e jl jm  d$ k rd% Zn d& Zo d' Zp d( Zq d) Zr d( Zs n] ek e jl jm  rd* Zn d% Zo d) Zp d( Zq d) Zr d( Zs n$ d( Zn d( Zo d+ Zp d+ Zq d+ Zr d, Zs d-   Zt ea ea d.  Zu d/ eZ f d0     YZv d1 ev f d2     YZw d3   Zx e( jy e( jz e( j{ e( j| e( j} e( j~ e( j e( j e( j e( j e( j e( j e( j e( j e( j e( j f Z eg e d4 d5  Z d6   Zl d7   Z e# d8 f   Z e# d9 f   Z e# d: f   Z e# d; f   Z e# d< f   Z e# d= f   Z e# d> f   Z e# d? f   Z ea ea d@  Z' e e' e e e e  \ Z Z Z Z Z e e e e f ZV e e f ZO e e f ZK eV Z eO Z eK Z e# d8 e f  Z e# d9 e f  Z e# d: e f  Z e# d; e f  Z e# d< e f  Z e# d= e f  Z e# d> e f  Z e# d? e f  Z ea ea dA  Z e e e e e e  \ Z Z Z Z Z e e e e f Z e e f Z e e f Z e# d8 e e f  Z e# d9 e e f  Z e# d: e e f  Z e# d; e e f  Z e# d< e e f  Z e# d= e e f  Z e# d> e e f  Z e# d? e e f  Z ea ea dB  Z e e e e e e  \ Z Z Z Z Z e e e e f Z e e f Z e e f Z e# d8 eg e f  Z e# d9 eg e f  Z e# d: eg e f  Z e# d; eg e f  Z e# d< eg e f  Z e# d= eg e f  Z e# d> eg e f  Z e# d? eg e f  Z ea ea dC  Z e e e e e e  \ Z Z Z Z Z e# d8 e eg f  Z e# d9 e eg f  Z e# d: e eg f  Z e# d; e eg f  Z e# d< e eg f  Z e# d= e eg f  Z e# d> e eg f  Z e# d? e eg f  Z ea ea dD  Z e e e e e e  \ Z Z Z Z Z e# d8 e f dE  Z e# d9 e f dE  Z e# d: e f dE  Z e# d; e f dE  Z e# d< e f dE  Z e# d= e f dE  Z e# d> e f dE  Z e# d? e f dE  Z ea ea dF  Z e e e e e e  \ Z Z Z Z Z e# d8 e f dG  Z e# d9 e f dG  Z e# d: e f dG  Z e# d; e f dG  Z e# d< e f dG  Z e# d= e f dG  Z e# d> e f dG  Z e# d? e f dG  Z ea ea dH  Z e e e e e e  \ Z Z Z Z Z e# d8 e f dI  Z e# d9 e f dI  Z e# d: e f dI  Z e# d; e f dI  Z e# d< e f dI  Z e# d= e f dI  Z e# d> e f dI  Z e# d? e f dI  Z ea ea dJ  Z e e e e e e  \ Z ZZZZe# Zeb e _b e# e _# e e _ e  e _  dK   Zeea ea ea  ZdL   ZdM e f dN     YZ	e	  Z
dO e f dP     YZe  ZdQ   Zee j: e( j dR  Zee j: e( j d<  Zee j: e( j d=  Zee j: e( j d>  Zee j: e( j d?  Zee j: e( j dS  Zee j: e( j dT  Zee j: e( j dU  Zee j: e( j dV  Zee j: e( j  dW  Z!ee j: e( j" d:  Z#ee j: e( j$ d;  Z%ee j: e( j& d8  Z'ee j: e( j( d9  Z)i edR 6ed< 6ed= 6ed> 6ed? 6edS 6edT 6edU 6edV 6e!dW 6e#d: 6e%d; 6e'd8 6e)d9 6Z*e_ dX    Z+dY e f dZ     YZ,d[ e f d\     YZ-e-  Z.d]   Z/e_ ea e d^   Z0e_ ea e d_   Z1e_ ea e d`   Z2e_ ea e da   Z3e_ ea e db   Z4e_ dc    Z5e_ dd    Z6ede    Z7edf    Z8edg    Z9edh    Z:edi    Z;edj    Z<edk    Z=e=Z>dl   Z=edm    Z?e?Z@dn   Z?d+ d, e do  ZAd+ d, e dp  ZBedq    ZCeCZDedr    ZEeEZFeds    ZGeGZHedt    ZIeIZJedu    ZKeKZLedv    ZMe. jNeMe, jOdw dx f   edy    ZPedz    ZQed{    ZRed|    ZSed}    ZTed~    ZUed    ZVed    ZWed    ZXed    ZYed    ZZed    Z[ed    Z\e_ ea d   Z]e_ ea d   Z^ed    Z_ed    Z`ed    ZaeaZbed    Zced    Zded    Zeed    Zfed    Zged    Zhed    Zied    Zjed    Zked    Zled    Zmed    Zned    Zoed    Zped    Zqed    Zred    Zsed    Zted    Zued    Zved    Zwed    Zxed    Zyed    Zzed    Z{ed    Z|ed    Z}ed    Z~ee~ e! _~ed    Zee e! _ed    Zed    ZB ed    Zed    Zed    ZeZe. jNee, jd   e_ ea e d   Ze_ ea e d   Zea d  Zea d  Zd e j f d     YZe  Ze d  Zd   Zd   Zd e j f d     YZea d ea d  Zd d  Zd d  Zd e j f d     YZea d ea d  Zd   Zd   Zd e j f d     YZe  Ze. jNee, jd   d   Zg  e_d   Ze j: e( j Ze. jNee, j   e_ ea ea e ea d   Ze. jNe=   e, jd   e_ ea ea e ea e d   Zd e j< f d     YZe_ ea ea e e ea d   Ze_ ea d e e d   Ze_ ea d e e d   Zd e j f d     YZe  ZeZed    Zed    Zd   Zd   Zed    Zed    Zed    Zed    Zed    ZeZd   Zd   Zed    Zed    Zed    Ze. jNee, jd d d   e. jNee, jd d d   e. jNee, jd d d   e. jNeSe, jd d d   e. jNee, jd d d   e. jNee, jd d d   e. jNee, jd d$ d   eg e d  Zea d  Zd   Zd d  Zd d  Zd e f d     YZd   Zd   Zd   Zd e f d     YZe  Ze. jNee, jd   d   Zea d  Ze_ d$ d   Ze_ d$ d   Ze_ d    Ze_ d    Ze_ d d   Zd   Ze_ d    Ze_ d    Zde f d    YZea d Zde f d    YZd$ d Zd$ d Zde f d	    YZea d
 Zde f d    YZi  Zea d$ ea d Zdef d    YZe  Zedeg  Zde f d    YZe  Zd d Zd  Zde f d    YZe  Ze. jNee, je, jdd d   d  Zd  Zd d Zd  Zea e d ZD ea e d ZF e	 jdG dG f  Ze	 je	 je e Z[de f d    YZd d d$ d  Zd!e f d"    YZd d# Zd$  Zea d% Zd&  Zd'  Zea d(d) Zd*e f d+    YZd,e j f d-    YZd S(.  sC   A `Type` and `Op` classes to work with numpy.ndarrays symbolically.i    (   t   absolute_importt   print_functiont   division(   t   builtinsN(   t   integer_types(   t   xrange(   t   izip(   t   config(   t   gof(   t   Applyt   Constantt   Opt   Variable(   t   Generic(   t   elemwise(   t   AsTensorErrort   TensorVariablet   TensorConstantt   _tensor_py_operators(   t
   TensorTypet   values_eq_approx_always_true(   t	   NoneConst(   t   scalar(   t   partial(   t   compilet   printing(   t   pprintt   min_informative_str(   t   Rebroadcastt   Shapet   shape(   t   grad_undefined(   t   grad_not_implemented(   t   DisconnectedType(   t   Elemwiset
   DimShufflet   CAReducet   Sums   theano.tensor.basics   restructuredtext ent
   ShapeErrorc           B` s   e  Z d  Z RS(   s)   Raised when the shape cannot be computed.(   t   __name__t
   __module__t   __doc__(    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR&   ?   s   c         C` s   t  |  t j  re t  | t j  re |  j | j k od |  j | j k od t j t |  |  d k   St  |  t j j  r t  | t j j  r t	 d   t
 |  j   | j    D  S|  | k Sd S(   su   
    Return True iff x and y are equal.

    Checks the dtype and shape if x and y are numpy.ndarray instances.

    g|=c         s` s*   |  ]  \ } } t  j | | k  Vq d  S(   N(   t   numpyt   all(   t   .0t   at   b(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pys	   <genexpr>P   s    N(   t
   isinstanceR*   t   ndarrayt   dtypeR   R+   t   abst   randomt   RandomStatet
   python_allR   t   __getstate__(   t   xt   y(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   check_equal_numpyD   s    $$	 c         C` s   t  j |   |  S(   sw   Add `f` to :doc:`oplist`.

    Make `f` appear as a constructor in the oplist (`gen_oplist`,
    doc/oplist.txt).

    (   t   __oplist_constructor_listt   append(   t   f(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   constructor]   s    c         C` s,   t  |  d g   } | j |  | |  _ d  S(   Nt   __oplist_tags(   t   getattrR;   R>   (   t   thingt   tagt   tags(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   __oplist_tagh   s    c         C` s  t  |  d  r |  j   St |  t j  rs |  j j d k rd t |  j	  d k rd t
 d |    n  |  j   }  n  t |  t  rt |  j t j  r t |   }  n  t |  j t  s t d |  |  j   n  | d k r |  S|  j j | k rsg  t |  j  D] } |  j | s| ^ qd } |  j t t |  j   |  }  |  j | k rot
 d | |  j   n  |  S|  j j | k  rt |  d | |  j j S|  Sn  t |  t t f  rt d   |  D  ry t |   SWqt t
 f k
 rqXn  t |  t  rt d	   n  y t |  d
 | d | SWnZ t k
 ry t |   } Wn t  k
 rst! |   } n Xt d | t |     n Xd S(   s  Return `x`, transformed into a `TensorType`.

    This function is often used by `make_node` methods of `Op` subclasses
    to turn ndarrays, numbers, `Scalar` instances, `Apply` instances and
    `TensorType` instances into valid input list elements.

    Parameters
    ----------
    x : Apply instance, Variable instance, numpy.ndarray, or number
        This thing will be transformed into a `Variable` in a sensible way. An
        ndarray argument will not be copied, but a list of numbers will be
        copied to make an ndarray.
    name : str or None
        If a new `Variable` instance is created, it will be named with this
        string.
    ndim : None or integer
        Return a Variable with this many dimensions.

    Raises
    ------
    ValueError
        If an `Apply` with more than one output is fetched or
        if `x` cannot be made into a Variable with `ndim` dimensions.
    AsTensorError
        If `x` cannot be converted to a TensorType Variable.

    t   _as_TensorVariablei   sD   It is ambiguous which output of a multi-output Op has to be fetched.s)   Variable type field must be a TensorType.i    s2   TensorType could not be cast to have %i dimensionst   n_onesc         s` s   |  ] } t  | t  Vq d  S(   N(   R/   R   (   R,   t   xi(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pys	   <genexpr>   s   s   Cannot cast True or False as a tensor variable. Please use 1 or 0. This error might be caused by using the == operator on Variables. v == w does not do what you think it does, use theano.tensor.eq(v, w) instead.t   namet   ndims   Cannot convert %s to TensorTypeN("   t   hasattrRD   R/   R   R	   t   opt   default_outputt   Nonet   lent   outputst
   ValueErrorR   t   typet   scalt   Scalart   tensor_from_scalarR   R   RH   R   t   broadcastablet
   dimshufflet   listt   ranget   shape_padleftt   tuplet
   python_anyt   stackt	   TypeErrort   boolt   constantt   strt	   Exceptiont   repr(   R7   RG   RH   t   idxt   first_non_broadcastablet   str_x(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   as_tensor_variable~   sZ    
'"c   	      C` sJ  t  j |  d | } g  | j D] } | d k ^ q } | d k	 r t |  | k  rs t g | t |  | } n% t |  | k r t d |   n  t |  | k s t  n  yf | t k r | t	 d | j
 d |  | j   d | } | S| t	 d | j
 d |  | d | SWn* t k
 rEt d |  t |     n Xd S(   s   Return a symbolic `Constant` with value `x`.

    Raises
    ------
    TypeError
        `x` could not be converted to a numpy.ndarray.
    ValueError
        `x` could not be expanded to have ndim dimensions.

    R1   i   s8   ndarray could not be cast to constant with %i dimensionsRT   RG   s"   Could not convert %s to TensorTypeN(   RQ   t   convertR   RL   RM   t   TrueRO   t   AssertionErrorR   R   R1   t   copyR`   R\   RP   (	   R7   t   rtypeRG   RH   R1   t   x_t   dt	   bcastablet   rval(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   constant_or_value   s*    "	c      
   C` s   t  |  d t d | d | d | } t j s1 | S| j   } | t k r | j j d k r d | j k ou d k n r | j t	 k s | j t
 k s | j t k r t t  d k  r | t | <t | _ n  t j | |  S(	   NRj   RG   RH   R1   i   ii
   i'  (   Ro   R   R^   t   enablet	   signaturet   constant_cachet   datat   sizeR1   t
   int_dtypest   uint_dtypest   float_dtypesRM   Rg   t   cachedt   get(   R7   RG   RH   R1   t   rett   sig(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR^     s    			
c         C` s+   y t  |   t SWn t k
 r& t SXd  S(   N(   R^   Rg   R\   t   False(   R7   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   _obj_is_wrappable_as_tensor#  s
    
i   g{Gz?g?gMb@?gMbP?g-C6?g{Gzt?gh㈵>g:0yE>c         C` s   d } d } t  |  j  | k s6 t  | j  | k rE t } t } nE t  |  j  | k so t  | j  | k r~ t } t } n t } t } | | f S(   Nt   float16t   float32t	   complex64(   R~   (   R   R   (   R_   R1   t   float16_atolt   float16_rtolt   float32_atolt   float32_rtolt   float64_atolt   float64_rtol(   R-   R.   t   tinyt   narrowt   atolt   rtol(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   _get_atol_rtolU  s    *	*	c         C` sy   t  j |   }  t  j |  } t |  |  \ } } | d  k	 rH | } n  | d  k	 r] | } n  t  j |  | d | d | S(   NR   R   (   R*   t   asarrayR   RL   t   allclose(   R-   R.   R   R   t   atol_t   rtol_(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt	   _allclosed  s    		t   NotScalarConstantErrorc           B` s   e  Z d  Z RS(   sg   
    Raised by get_scalar_constant_value if called on something that is
    not a scalar constant.
    (   R'   R(   R)   (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   p  s   t   EmptyConstantErrorc           B` s   e  Z d  Z RS(   sj   
    Raised by get_scalar_const_value if called on something that is a
    zero dimensional constant.
    (   R'   R(   R)   (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   w  s   c         C` s   |  j  d k rl t |  j  d k s< t j |  j  d k rl t j t j g   |  k  s` t  t	    n  y t j
 |   |  SWn  t k
 r t d |    n Xd S(   s    Return a scalar stored in a numpy ndarray.

    Raises
    ------
     NotScalarConstantError
        If the numpy ndarray is not a scalar.

    i    sD   v.data is non-numeric, non-scalar, or has more than one unique valueN(   RH   RM   R   R   t   maxR*   R+   t   arrayRh   R   t   complexR`   R   (   Rs   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   numpy_scalar~  s    $i
   c          C` sH
  |  } x;
t  rC
| d k r' t    n  t | t j t t f  rO t j |  St | t j	  rq t
 |  j   St | t  r t | j d d  d k	 r | j j } n	 | j } t
 |  j   S| r4
t | d d  r4
| d k r4
| d 8} t | j j t t t t j j t j f  r5| j j d } q	 q4
t | j j t j j j  r| j j j } | j j d } t | t  rt j | j j |  St | j  d  r1
| j  j! | r1
t j d  Sq4
t | j j t" t# f  r| j j d } q	 q4
t | j j t j$ j% j&  rg  | j j d D] } t' | d | ^ q*}	 t( j) g  |	 D]! } d | j* k os| d k ^ qU r1
| j j d } q	 q1
q4
t | j j t+ j,  rct | j j t+ j-  r| j j \ }
 } | } q	 n  t | j j t.  r1
g  | j j D] } t' | d | ^ q} d g g } | j j j/ | j | |  | d d j   Sq4
t | j j t0  r7t | j j j1 t+ j-  r| j j \ }
 } | } q	 q1
| r1
t | j j j1 t.  r1
g  | j j D] } t' | d | ^ q} d g g } | j j j/ | j | |  | d d j   Sq4
t | j j t j$ j2 j3  r4
| j* d k r4
t | j j d t4  rt5 | j j j6 | j j   } y$ | j j d j j7 |  j   SWqt8 k
 rt8 t9 t5 | j j j:   d t9 | j j d j    qXn  t; | j j j:  | j j d j* k sCt<  | j j d j r^t | j j d j j t=  r^t; | j j j:  d k r^t> d   | j j d j j d D  rG| j j j: d } t | t? j@  rt' | j j d d | } n  | j j d j j | d } t' | d | } t jA | d	 | j  jB St> d
   | j j d j j d D  ro| j j j: d } t | t? j@  rt' | j j d d | } n  y d } tC } x` | j j d j j d D]D } tD |  } | | | k  r| | | } t  } Pn  | | 7} qW| r3w	 n  Wq[tE k
 rGq[tF k
 rWq[Xqon| j j d j rot | j j d j j t j$ j% jG  rot> d   | j j d j j D  rot; | j j j:  d k ro| j j j: d } t | t? j@  rt' | j j d d | } n  tH |  } | j j d j j | } t' | d | } t jA | d	 | j  jB S| j } | j d } | j r1
t | j j t j$ jI  r1
| j } | j: } | d } t | t? j@  rt' | j d d | } n  | j j d } | j  j! } | j  j* } | j r	t | j j t  r	| j j d j! } g  tJ | |  D] \ } } | pq	| ^ q\	} t5 |  } n  | t; |  k s	t<  | t; |  k  s
d d d | | f } tK jL d k r	| d tM |  7} n | d t9 |  7} tF |   n  | | r.
t j d  Sq1
q4
n  t |   q	 Wd S(   s  Return the constant scalar(0-D) value underlying variable `v`.

    If `v` is the output of dimshuffles, fills, allocs, rebroadcasts,
    cast, OutputGuard, DeepCopyOp, ScalarFromTensor, ScalarOp, Elemwise
    and some pattern with Subtensor, this function digs through them.

    If `v` is not some view of constant scalar data, then raise a
    NotScalarConstantError.

    Parameters
    ----------
    elemwise : bool
        If False, we won't try to go into elemwise. So this call is faster.
        But we still investigate in Second Elemwise (as this is a substitute
        for Alloc)
    only_process_constants : bool
        If True, we only attempt to obtain the value of `orig_v` if it's
        directly constant and don't try to dig through dimshuffles, fills,
        allocs, and other to figure out its value.
    max_recur : int
        The maximum number of recursion.

    Notes
    -----
        There may be another function similar to this one in the code,
        but I'm not sure where it is.

    t   unique_valuet   owneri    i   RT   t	   max_recurs    is not a valid index into c         s` s   |  ] } | j  d  k Vq d S(   i    N(   RH   (   R,   t   var(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pys	   <genexpr>+  s    R1   c         s` s   |  ] } | j  d  k Vq d S(   i   N(   RH   (   R,   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pys	   <genexpr>7  s    c         s` s   |  ] } | j  d  k Vq d S(   i    N(   RH   (   R,   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pys	   <genexpr>T  s    s#   get_scalar_constant_value detected s&   deterministic IndexError: x.shape[%d] s   when x.ndim=%d.t   highs    x=%sN(N   Rg   RL   R   R/   R*   t   integerR   t   floatR   R0   R   Ri   R
   R?   RA   R   Rs   R   RJ   t   AllocR#   R   R   t   opst   OutputGuardt
   DeepCopyOpt   inputst   theanot   Shape_it   iR   RI   RP   RT   t   ScalarFromTensort   TensorFromScalart   tensort   optt   Assertt   get_scalar_constant_valueR   R+   RH   RQ   t   ScalarOpt   Secondt#   get_scalar_constant_value_elemwisest   performR"   t	   scalar_opt	   subtensort	   SubtensorR   RY   t   get_constant_idxt   __getitem__t
   IndexErrorR_   t   idx_listRM   Rh   t   JoinR5   R   t   Typet   _asarrayR1   R|   t   get_vector_lengthR\   RO   t
   MakeVectort   intR   t   zipR   t   exception_verbosityR   (    t   orig_vR   t   only_process_constantsR   t   vRs   R   t   inpt   ct   condt   shpt   valt   constRz   t   cdataRb   t   lengtht   loopt   joinedt   llR   t   leftmost_parentRJ   R   t   grandparentt   gp_broadcastableRH   t   ggp_broadcastablet   b1t   b2t   lt   msg(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s2   		
	,7	(		(!$$.	!	!!

					
		%
c          O` s(   | j  d d   } t |  |   d |  S(   NRG   (   t   popRL   R   (   t   argst   kwargsRG   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s    c          G` sL   d   } t  |   d k r( t | |   Sg  |  D] } t | |  ^ q/ Sd  S(   Nc         W` s   | rS t  | d t  rS | d k r, |    Sg  t | d  D] } |    ^ q= Sn  t  | t  r t |  d k r | d } q n  t |  d k r |  |  Sg  | D] } |  |  ^ q Sd  S(   Ni    i   (   R/   R   R   RY   RM   (   R<   t   namesR   RG   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   f2  s    '
i   (   RM   R   (   t   fnsR   R<   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   _multi  s    	R   t
   complex128R   t   float64t   int8t   int16t   int32t   int64c         C` s1   | d k r t j } n  t | d  } | |   S(   s   Return a symbolic scalar variable.

    Parameters
    ----------
    dtype: numeric
        None means to use theano.config.floatX.
    name
        A name to attach to this variable.

    N(    (   RL   R   t   floatXR   (   RG   R1   RP   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s    c         C` s4   | d k r t j } n  t | t f  } | |   S(   s   Return a symbolic vector variable.

    Parameters
    ----------
    dtype: numeric
        None means to use theano.config.floatX.
    name
        A name to attach to this variable

    N(   RL   R   R   R   R|   (   RG   R1   RP   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   vector  s    c         C` s7   | d k r t j } n  t | t t f  } | |   S(   s   Return a symbolic matrix variable.

    Parameters
    ----------
    dtype: numeric
        None means to use theano.config.floatX.
    name
        A name to attach to this variable.

    N(   RL   R   R   R   R|   (   RG   R1   RP   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   matrix  s    c         C` s7   | d k r t j } n  t | t t f  } | |   S(   s   Return a symbolic row variable (ndim=2, broadcastable=[True,False]).

    Parameters
    ----------
    dtype: numeric type
        None means to use theano.config.floatX.
    name
        A name to attach to this variable.

    N(   RL   R   R   R   Rg   R|   (   RG   R1   RP   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   row  s    c         C` s7   | d k r t j } n  t | t t f  } | |   S(   s   Return a symbolic column variable (ndim=2, broadcastable=[False,True]).

    Parameters
    ----------
    dtype : numeric
        None means to use theano.config.floatX.
    name
        A name to attach to this variable.

    N(   RL   R   R   R   R|   Rg   (   RG   R1   RP   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   col2  s    i   c         C` s:   | d k r t j } n  t | t t t f  } | |   S(   s   Return a symbolic 3-D variable.

    Parameters
    ----------
    dtype: numeric type
        None means to use theano.config.floatX.
    name
        A name to attach to this variable.

    N(   RL   R   R   R   R|   (   RG   R1   RP   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   tensor3M  s    i   c         C` s=   | d k r t j } n  t | t t t t f  } | |   S(   s   Return a symbolic 4-D variable.

    Parameters
    ----------
    dtype: numeric type
        None means to use theano.config.floatX.
    name
        A name to attach to this variable.

    N(   RL   R   R   R   R|   (   RG   R1   RP   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   tensor4j  s    i   c         C` s@   | d k r t j } n  t | t t t t t f  } | |   S(   s   Return a symbolic 5-D variable.

    Parameters
    ----------
    dtype: numeric type
        None means to use theano.config.floatX.
    name
        A name to attach to this variable.

    N(   RL   R   R   R   R|   (   RG   R1   RP   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   tensor5  s    c         ` s       f d   } | S(   s  
    Replace a symbol definition with an elementwise version of the
    corresponding scalar Op.  If it is not None, the nfunc argument
    should be a string such that getattr(numpy, nfunc) implements
    a vectorized version of the elemwise operation. nin is the number
    of inputs expected by that function, and nout is the number of
    **destination** inputs it takes. That is, the function should
    take nin+nout inputs. nout == 0 means that the numpy function
    does not take a numpy array argument to put its result in.

    c      	   ` s@  |  j  } | j d  } | r' d } n d } d | | f } | r t t | t d    } | j t j d   } t j | i d d 6d | d   o     f } n9 t t |  } t j | d | d   o     f } t |  d t	  r|  j
 d	 | j
 | _
 n  |  | _ d
 | _ t j | t j |   | S(   Nt   _inplacet   inplacet
   no_inplaces   Elemwise{%s,%s}i    RG   t
   nfunc_specR)   s   
R   (   R'   t   endswithR?   RQ   RM   t	   __class__t   transfer_typeR   R"   R|   R)   t   __epydoc_asRoutineR(   R   t   assignR   t   FunctionPrinter(   t   symbolt
   symbolnameR   R   t   nR   t   inplace_scalar_opRn   (   t   nfunct   nint   nout(    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt	   construct  s(    				(    (   R   R   R   R   (    (   R   R   R   s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   _scal_elemwise_with_nfunc  s    c         C` s*   y t  |   SWn t k
 r% |  g SXd S(   sP   
    Convert x to a list if it is an iterable, otherwise wrap it in a list.
    N(   RV   R\   (   R7   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   _pack  s    R   c           B` s2   e  Z d Z d    Z d   Z d   Z d   Z RS(   c         C` sF   t  | j t j  s t  t |  | g t d | j j d d  g  S(   NR1   RT   (    (   R/   RP   RQ   RR   Rh   R	   R   R1   (   t   selft   s(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt	   make_node  s
    c         C` s)   | \ } | \ } t  j |  | d <d  S(   Ni    (   R*   R   (   R   t   nodeR   t   out_R   t   out(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s    		c         C` s   d g S(   N(    (    (   R   R  t	   in_shapes(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   infer_shape  s    c         C` s   | \ } | \ } | j  j t k rI | j  j t k s< t  t |  g S| j  j t k rw | j   j t j	 j
  g St d   d  S(   Ns'   grad not implemented for complex dtypes(   RP   R1   Rw   Rh   t   scalar_from_tensort   discrete_dtypest
   zeros_liket   astypeR   R   R   t   NotImplementedError(   R   R   t   gradsR   t   dt(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   grad  s    		(    (   R'   R(   t	   __props__R   R   R  R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s
   			R   c           B` sM   e  Z d Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   c         C` s^   t  | j t  s t  | j j d k s0 t  t |  | g t j d | j j  j	   g  S(   NR1   (    (
   R/   RP   R   Rh   RT   R	   RQ   t   get_scalar_typeR1   t   make_variable(   R   t   t(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s
    c         C` s*   | \ } | \ } | j    d | d <d  S(   Ni    (   t   flatten(   R   R  R   R  R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s    		c         C` s   d g S(   N(    (    (   R   R  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    c         C` s   | \ } | \ } t  |  g S(   N(   RS   (   R   R   R  R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    		c         C` s#   d  | k r d  g S|  j |   j S(   N(   RL   R   RN   (   R   R   t   eval_points(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   R_op$  s    c   	      C` s'   | \ } | \ } | d } d t    S(   Nt   failsC   
        %(z)s = ((dtype_%(x)s*)(PyArray_DATA(%(x)s)))[0];
        (   t   locals(	   R   R  RG   R   RN   t   subR7   t   zR  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   c_code)  s    		
c         C` s   d S(   Ni   (   i   (    (   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   c_code_cache_version1  s    (    (
   R'   R(   R  R   R   R  R  R  R  R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s   						c         C` s3   t  |  d  d |  _ t j |  t j |   |  S(   Nt   castings   tensor.basic(   RC   R(   R   R   R   R   (   t
   real_valueRG   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   _conversion9  s    	R]   t   uint8t   uint16t   uint32t   uint64R~   c         C` s|   | d k r t  j } n  t |   } | j j | k r: | S| j j j d  rn | j d  rn t d   n  t | |   S(   s2   Symbolically cast `x` to a Tensor of type `dtype`.R   R   sT   Casting from complex to real is ambiguous: consider real(), imag(), angle() or abs()(   R   R   Re   RP   R1   t
   startswithR\   t   _cast_mapping(   R7   R1   t   _x(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   cast  s    %t   MaxAndArgmaxc           B` s   e  Z d  Z d Z d Z d Z e   Z d Z d   Z	 d   Z
 d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z RS(   sK   
    Calculate the max and argmax over a given axis or over all axes.

    i   s   invalid axist   axisc         C` s(   t  | t  s t  t |  |  _ d  S(   N(   R/   RV   Rh   RY   R'  (   R   R'  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   __init__  s    c         C` s   |  j  S(   N(   R'  (   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt
   get_params  s    c         C` s   t  |  } t |  j  } g  t | j j  D] \ } } | | k r. | ^ q. } | g } t | j j | d d t d | d d g } t |  | |  S(   NRG   R   R   t   argmax(	   t   _as_tensor_variablet   setR'  t	   enumerateRP   RT   R   R1   R	   (   R   R7   t   all_axesR   R.   RT   R   RN   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s    	c         C` s`  | d } | } | \ } } | d  k r@ t t | j   } n t d   | D  } t j t j | |  d | j d j	 | d <t j
 g  t | j  D] }	 |	 | k r |	 ^ q d d }
 t j | t j |
 | f   } | j t |
   } | j t |
  } | t j | d d f } | j |  } t j t j | d d d d | d <d  S(   Ni    c         s` s   |  ] } t  |  Vq d  S(   N(   R   (   R,   t   ax(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pys	   <genexpr>  s    R1   R   R'  i(   RL   RY   RW   RH   R   R   R*   R   RN   R1   R   t	   transposet   concatenateR   RM   t   prodt   reshapeR*  (   R   R  R   t   outst   paramsR7   t   axesR   t   max_idxR   t	   keep_axest   transposed_xt
   kept_shapet   reduced_shapet	   new_shapet
   reshaped_x(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s"    
4	!c         C` s~   t  |  j  d k rC t  |  j  | j d j k rC t d   n  | d } | d } | \ } }	 | d }
 d } | t   S(   Ni   i    sG   NumPy C-API can compute max and argmax only for 1 axis or for all axes.R5  R  s   
        #if PY_MAJOR_VERSION >= 3
            #ifndef PyInt_AS_LONG
                #define PyInt_AS_LONG PyLong_AS_LONG
            #endif
        #endif

        int axis;

        if (PyTuple_GET_SIZE(%(axis)s) == PyArray_NDIM(%(x)s)) {
            axis = NPY_MAXDIMS;
        } else if(PyTuple_GET_SIZE(%(axis)s) == 1) {
            PyObject* axis_object = PyTuple_GET_ITEM(%(axis)s, 0);
            axis = (int)PyInt_AS_LONG(axis_object);
            if (axis > PyArray_NDIM(%(x)s)-1 || axis < -PyArray_NDIM(%(x)s)) {
                PyErr_SetString(PyExc_ValueError,
                "MaxAndArgmax: bad axis argument");
                %(fail)s
            }
        } else {
            PyErr_SetString(PyExc_NotImplementedError,
            "MaxAndArgmax: NumPy C-API can compute max and argmax only for 1 axis or for all axes.");
            %(fail)s
        }

        Py_CLEAR(%(max)s);
        Py_CLEAR(%(argmax)s);//todo pass them as out parameter.

        %(max)s = (PyArrayObject*)PyArray_Max(%(x)s, axis, NULL);
        if (%(max)s == NULL) {
            %(fail)s;
        }
        if (!PyArray_CheckExact(%(max)s)) {
            %(max)s = (PyArrayObject*)PyArray_FromAny((PyObject*)%(max)s, NULL, 0, 0, NPY_ARRAY_ENSUREARRAY, NULL);
            if(%(max)s == NULL){
                %(fail)s;
            }
        }

        %(argmax)s = (PyArrayObject*)PyArray_ArgMax(%(x)s, axis, NULL);
        if (%(argmax)s == NULL) {
            Py_CLEAR(%(max)s);
            %(fail)s;
        }
        if (!PyArray_CheckExact(%(argmax)s)) {
            %(argmax)s = (PyArrayObject*)PyArray_FromAny((PyObject*)%(argmax)s, NULL, 0, 0, NPY_ARRAY_ENSUREARRAY, NULL);
            if(%(argmax)s == NULL){
                %(fail)s;
            }
        }
        if (PyArray_TYPE(%(argmax)s) != NPY_INT64) {
            PyObject * tmp = PyArray_Cast(%(argmax)s, NPY_INT64);
            if (NULL == tmp){
                %(fail)s;
            }
            Py_DECREF(%(argmax)s);
            %(argmax)s = (PyArrayObject*)tmp;
        }
        (   RM   R'  R   RH   R
  R  (   R   R  RG   R   R  R  R7   R'  R   R*  R  Rz   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    4


;c         C` s   d S(   Ni   (   i   (    (   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s    c         ` sF   | d   t     f d   t | j d j j  D  } | | g S(   Ni    c         3` s.   |  ]$ \ } } |  j  k r   | Vq d  S(   N(   R'  (   R,   R   R.   (   t   ishapeR   (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pys	   <genexpr>%  s    	(   RY   R-  R   RP   RT   (   R   R  t   shapesRn   (    (   R>  R   s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  #  s    
c         C` s  | d d  k r d  d  g St |  j  d k r> t d   n  |  j d d k r` t d   n  | d j d k r t d   n  |  j |   j \ } } |  j d d k r | d | t | d j d  f d  g S| d t | d j d  | f d  g Sd  S(   Ni    i   s-   R_op supported for arg_max only for one axis!s4   R_op supported for arg_max only when  axis is 0 or 1i   s7   R_op supported for arg_max only when  input is a matrix(	   RL   RM   R'  RO   RH   R   RN   t   arangeR   (   R   R   R  t   max_valst   max_pos(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  )  s    

c         C` s  | d } t  |  j  } | \ } } t | j t  } t | j t  } | rk | rk t     t     g S| r~ | j   g St j |  r t t	 | j
   }	 n | }	 t | |	  }
 g  } d } t j |  r d  } n  xY t | j
  D]H } | d  k s| | j k r| j d  q | j |  | d 7} q Wt | j |  |  } t |
 j |  |
  } t | |  | } | f S(   Ni    R7   i   (   R+  R'  R/   RP   R!   R  R   t   equalsRV   RW   RH   R   RL   R   Rs   R;   R#   RT   t   eq(   R   R   R  R7   R'  t   g_maxt	   g_max_idxt   g_max_disconnectedt   g_max_idx_disconnectedt   axis_t   xmaxt   patternt   out_dimR   t	   g_max_padt   xmax_padt   g_x(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  =  s4    
	(   s   axis(   R'   R(   R)   R   R   t   E_axisR   t   params_typeR  R(  R)  R   R   R  R  R  R  R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR&    s   						D			t   Argmaxc           B` s_   e  Z d  Z d Z d Z d Z d
 Z d d  Z d   Z	 d   Z
 d   Z d   Z d	   Z RS(   sB   
    Calculate the argmax over a given axis or over all axes.
    i   i   s   invalid axisc         C` s  t  |  } t | t t j f  r6 t |  g } nt | t j  ri | j d k ri t |  g } n\t | t t	 t j f  r g  | D] } t |  ^ q } | t	 t
 | j j   k rd  } qn t | t  rt j |  r d  } qt | t  st d |   q| j t k s+t  t | j t t j f  smt | j t j  r| j j d k rt | j  g } qt | j t	 t j f  rg  | j D] } t |  ^ q} qn  t | t	  r'xC t t |   D]/ } | | d k  r| | c | j j 7<qqW| j   n  g  } t | t	  rx | D]_ } | d k  sg| | j j k rt d | | j j f   n  | | k rC| j |  qCqCWn t	 t
 | j   } | d  k s| t	 t
 | j j   k rt j   } n! t  |  } | j d k st  | | g } g  t | j j  D] \ } }	 | | k r7|	 ^ q7}
 t d |
 d d g } t |  | |  S(   Ni    s$   Argmax needs a constant axis. Got %ss?   Invalid axis: %s (the number of dimensions of the input is: %s)i   R   RG   R*  (    R+  R/   R   R*   R   R   R0   RH   RY   RV   RW   RP   RL   R   R   RC  R   R\   R1   t   integer_dtypesRh   Rs   R   RM   t   sortRO   R;   t   cloneR-  RT   R   R	   (   R   R7   R'  R-   R   Rb   R.  R/  R   R.   RT   RN   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   }  s\    !	(*c         C` s$  | \ } } | \ } | d  k r9 t t | j   } n t d   | D  } t j g  t | j  D] } | | k re | ^ qe d d } t j | t j | | f   }	 |	 j t	 |   }
 |	 j t	 |  } |
 t j
 |  f } |	 j |  } t j t j | d d d d | d <d  S(   Nc         s` s   |  ] } t  |  Vq d  S(   N(   R   (   R,   R/  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pys	   <genexpr>  s    R1   R   R'  ii    (   RL   RY   RW   RH   R*   R   R0  R1  R   RM   R2  R3  R   R   R*  (   R   R  R   R4  R7   R6  R7  R   R8  R9  R:  R;  R<  R=  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s    	4	c         C` s   | \ } } | \ } | d }	 t  j | j d  r> d }
 nQ | j d j d k sZ t  t | j d j  d k r t    n  d t   }
 d } | t   S(   NR  i   s   axis = NPY_MAXDIMS;s"  
            axis = ((dtype_%(axis)s*)PyArray_DATA(%(axis)s))[0];
            if(axis > PyArray_NDIM(%(x)s)-1 || axis < -PyArray_NDIM(%(x)s)){
                PyErr_SetString(PyExc_ValueError,
                "Argmax, bad axis argument");
                %(fail)s
            }
            s  
        int axis;

        Py_CLEAR(%(argmax)s);//todo pass them as out parameter.
        %(axis_code)s

        %(argmax)s = (PyArrayObject*)PyArray_ArgMax(%(x)s, axis, NULL);
        if(%(argmax)s == NULL){
            %(fail)s;
        }
        if(!PyArray_CheckExact(%(argmax)s)){
            %(argmax)s = (PyArrayObject*)PyArray_FromAny((PyObject*)%(argmax)s, NULL, 0, 0, NPY_ARRAY_ENSUREARRAY, NULL);
            if(%(argmax)s == NULL){
                %(fail)s;
            }
        }
        if(PyArray_TYPE(%(argmax)s) != NPY_INT64){
            PyObject * tmp = PyArray_Cast(%(argmax)s, NPY_INT64);
            if (NULL == tmp){
                %(fail)s;
            }
            Py_DECREF(%(argmax)s);
            %(argmax)s = (PyArrayObject*)tmp;
        }
        (	   R   RC  R   RH   Rh   RM   Rs   R
  R  (   R   R  RG   R   R  R  R7   R'  R*  R  t	   axis_codeRz   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    	
	c         C` s   d S(   Ni    (   i    (    (   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    c   	      C` s   | \ } } | j  d } | j d  k r/ d g St g  t | j  d j j  D]% \ } } | | j k rL | | ^ qL  } | g S(   Ni   i    (    (   R   Rs   RL   RY   R-  RP   RT   (	   R   R  R?  R>  t
   axis_shapeR'  R   R.   Rn   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    	Bc         C` s1   | \ } } t  |  d | d  } | j   | g S(   Ni   sN   argmax is not defined for non-integer axes so argmax(x, axis+eps) is undefined(   R   R  (   R   R   R  R7   R'  t	   axis_grad(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  
  s
    		(    N(   R'   R(   R)   R   R   RP  R  RL   R   R   R  R  R  R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRR  t  s   <		.			c   	      C` s  t  |   }  t  |  } | d k r? t t |  j j   } nv t | t t j	 f  rc | g } nR t | t j
  r | j d k r t |  g } n g  | D] } t |  ^ q } g  } xX | D]P } t | t  s t d   n  | d k  r| |  j j 7} n  | j |  q Wd } g  } xS t |  j j  D]? \ } } | | k r]| j d  q5| j |  | d 7} q5Wt | j j |  |  S(   s   
    Reintroduces in y with length one the axes of x which have been left out
    in a prior reduction of x. With this option, the resulting tensor will
    broadcast correctly against the original tensor x.

    i    s3   keepdims option can be used only with constant axisR7   i   N(   Re   RL   RV   RW   RP   RH   R/   R   R*   R   R0   R   RO   R;   R-  RT   R#   (	   R7   R8   R'  R-   t   newaxisR   t   new_dimst   jt   _(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   makeKeepDims  s2    !c         C` s  t  |   }  | d k r3 t t |  j j   } nt | t t j	 f  sl t | t j
  r~ | j d k r~ t |  g } nGt | t t t j
 f  r g  | D] } t |  ^ q } n
t | t  rt j |  r t t |  j j   } qt | t  st d |   q| j t k s+t  t | j t t j	 f  smt | j t j
  r| j j d k rt | j  g } qt | j t t j
 f  rg  | j D] } t |  ^ q} qn  t |  d k rt t |  j j   } n x t t |   D]x } | | d k  r4| | c |  j j 7<n  | | d k  sZ| | |  j j k rt d |  j j | | f   qqWt t |   } | j   t |  |   \ } } | rt |  | |  } t |  | |  } n  | | g S(   s  
    Returns maximum elements and their indices obtained by iterating over
    given axis.

    When axis is None (the default value), the max is performed
    over the flattened tensor.

    Parameters
    ----------
    keepdims : bool
        If this is set to True, the axes which are reduced are left in
        the result as dimensions with size one. With this option, the result
        will broadcast correctly against the original tensor.

    i    s8   max and argmax computation needs a constant axis. Got %ssL   max and argmax computation needs a valid axis number for %d-D tensor. Got %dN(   Re   RL   RV   RW   RP   RH   R/   R   R*   R   R0   R   RY   R   R   RC  R   R\   R1   RS  Rh   Rs   RM   RO   R,  RT  R&  R]  (   R-   R'  t   keepdimsR   R  t   argout(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   max_and_argmax<  sD    !"'(&!
c         C` sb   y t  |  |  d } Wn) t k
 rB t t j |  |   } n X| r^ t |  | |  } n  | S(   s  
    Returns maximum elements obtained by iterating over given axis.

    When axis is None (the default value), the max is performed
    over the flattened tensor.

    Parameters
    ----------
    keepdims: bool
        If this is set to True, the axes which are reduced are left in
        the result as dimensions with size one. With this option, the result
        will broadcast correctly against the original tensor.

    Notes
    -----
    We return an error as numpy when we reduce a dim with a shape of 0.

    i    (   R`  R`   R$   RQ   t   maximumR]  (   R7   R'  R^  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   v  s    !c         C` s2   t  |  |  d } | r. t |  | |  } n  | S(   s  
    Returns indices of maximum elements obtained by iterating over given axis.

    When axis is None (the default value), the argmax is performed
    over the flattened tensor.

    Parameters
    ----------
    keepdims : bool
        If this is set to True, the axes which are reduced are left in
        the result as dimensions with size one. With this option, the result
        will broadcast correctly against the original tensor.

    i   (   R`  R]  (   R7   R'  R^  R_  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR*    s    c         C` s[   t  |   }  t |  j  } | j d  s6 | t k rN t |  d | d | St    d S(   s  
    Returns minimum elements obtained by iterating over given axis.

    When axis is None (the default value), the min is performed
    over the flattened tensor.

    Parameters
    ----------
    keepdims: bool
        If this is set to True, the axes which are reduced are left in
        the result as dimensions with size one. With this option, the result
        will broadcast correctly against the original tensor.

    R   R'  R^  N(   Re   R_   R1   R"  Ru   R   R
  (   R7   R'  R^  t
   str_x_type(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   min  s
    c         C` sZ   t  |   }  t |  j  } | j d  s6 | t k rM t |  d | d | St    d S(   s  
    Returns indices of minimum elements obtained by iterating over given axis.

    When axis is None (the default value), the argmin is performed
    over the flattened tensor.

    Parameters
    ----------
    keepdims: bool
        If this is set to True, the axes which are reduced are left in
        the result as dimensions with size one. With this option, the result
        will broadcast correctly against the original tensor.

    R   R'  R^  N(   Re   R_   R1   R"  Ru   R*  R
  (   R7   R'  R^  Rb  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   argmin  s
    c          G` sN   t  |   d k r4 |  \ } } t | | k  | |  St t |   d d Sd S(   sg   
    Return the [elementwise] smallest of a variable number of arguments.

    Like python's min.

    i   R'  i    N(   RM   t   switchRc  R[   (   R   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   smallest  s    c          G` sN   t  |   d k r4 |  \ } } t | | k | |  St t |   d d Sd S(   sf   
    Return the [elementwise] largest of a variable number of arguments.

    Like python's max.

    i   R'  i    N(   RM   Re  R   R[   (   R   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   largest  s    c         C` s   d S(   s   a < bN(    (   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   lt  s    c         C` s   d S(   s   a > bN(    (   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   gt  s    c         C` s   d S(   s   a <= bN(    (   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   le  s    c         C` s   d S(   s   a >= bN(    (   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   ge  s    c         C` s   d S(   s   a == bN(    (   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRD     s    c         C` s   d S(   s   a != bN(    (   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   neq%  s    c         C` s   d S(   s   isnan(a)N(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   isnan*  s    c         C` sd   t  |   }  |  j t k rZ t t j t d d g  t |  j  D] } |  j	 | ^ q@  St
 |   S(   s   isnan(a)R1   R]   (   Re   R1   R  t   allocR*   R   R|   RW   RH   R   t   isnan_(   R-   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRm  3  s
    *c         C` s   d S(   s   isinf(a)N(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   isinf<  s    c         C` sd   t  |   }  |  j t k rZ t t j t d d g  t |  j  D] } |  j	 | ^ q@  St
 |   S(   s   isinf(a)R1   R]   (   Re   R1   R  Rn  R*   R   R|   RW   RH   R   t   isinf_(   R-   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRp  F  s
    *c         C` s   t  t |  | | | |   S(   s  
    Implement Numpy's ``allclose`` on tensors.

    ``absolute(a - b) <= (atol + rtol * absolute(b))``

    Parameters
    ----------
    a : tensor
        Input to compare.
    b : tensor
        Input to compare.
    rtol : float
        The relative tolerance parameter.
    atol : float
        The absolute tolerance parameter.
    equal_nan: bool
        Whether to consider nan's in the same place to be close.

    Returns
    -------
    bool
        A boolean value (of type int8 returned by the tensor elementwise `all`
        function) whether all elements in a and b are in the tolerance range
        defined above.

    Notes
    -----
    Not a symmetric equation. See Numpy's documentation.

    (   R+   t   isclose(   R-   R.   R   R   t	   equal_nan(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   O  s    c         C` s  t  |  |  } | | t  |  } t | |  } t |   } t |  }	 t | |	  }
 t |   } t |  } t | |  } t |
 |  } t | t |   } t | |  } t | t |   | t |   } t | |  } t | |  } | rt | |	  } t | |  S| Sd S(   s#	  
    Implements Numpy's ``isclose`` on tensors.

    The tolerance values are positive, typically very small numbers. The
    relative difference (`rtol` * abs(`b`)) and the absolute difference
    `atol` are added together to compare against the absolute difference
    between `a` and `b`.

    ``absolute(a - b) <= (atol + rtol * absolute(b))``

    Parameters
    ----------
    a : tensor
        Input to compare.
    b : tensor
        Input to compare.
    rtol : float
        The relative tolerance parameter.
    atol : float
        The absolute tolerance parameter.
    equal_nan : bool
        Whether to consider nan's in the same place to be close

    Returns
    -------
    int8
        A boolean (int8) array where two arrays are element-wise equal
        within a tolerance.

    Notes
    -----
    Not a symmetric equation. See Numpy's documentation.

    Examples
    --------
    >>> import theano
    >>> import numpy as np
    >>> a = theano._asarray([1e10, 1e-7], dtype="float64")
    >>> b = theano._asarray([1.00001e10, 1e-8], dtype="float64")
    >>> theano.tensor.isclose(a, b).eval()
    array([1, 0], dtype=int8)
    >>> a = theano._asarray([1e10, 1e-8], dtype="float64")
    >>> b = theano._asarray([1.00001e10, 1e-9], dtype="float64")
    >>> theano.tensor.isclose(a, b).eval()
    array([1, 1], dtype=int8)
    >>> a = theano._asarray([1e10, 1e-8], dtype="float64")
    >>> b = theano._asarray([1.0001e10, 1e-9], dtype="float64")
    >>> theano.tensor.isclose(a, b).eval()
    array([0, 1], dtype=int8)
    >>> a = theano._asarray([1.0, np.nan], dtype="float64")
    >>> b = theano._asarray([1.0, np.nan], dtype="float64")
    >>> theano.tensor.isclose(a, b).eval()
    array([1, 0], dtype==int8)
    >>> a = theano._asarray([1.0, np.nan], dtype="float64")
    >>> b = theano._asarray([1.0, np.nan], dtype="float64")
    >>> theano.tensor.isclose(a, b, equal_nan=True).eval()
    array([1, 1], dtype==int8)
    >>> a = theano._asarray([1.0, np.inf], dtype="float64")
    >>> b = theano._asarray([1.0, -np.inf], dtype="float64")
    >>> theano.tensor.isclose(a, b).eval()
    array([1, 0], dtype==int8)
    >>> a = theano._asarray([1.0, np.inf], dtype="float64")
    >>> b = theano._asarray([1.0, np.inf], dtype="float64")
    >>> theano.tensor.isclose(a, b).eval()
    array([1, 1], dtype==int8)

    N(	   R2   Rj  Rm  t
   bitwise_orRp  t   bitwise_andt   bitwise_notRD  t   sgn(   R-   R.   R   R   Rs  t   difft	   tolerancet   close_prelimt   a_nant   b_nant   nanst   a_inft   b_inft   infst   nans_or_infst   closet	   both_infst   inf_signs_eqt   inf_eqt   close_with_infst	   both_nans(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRr  q  s&    F#c         C` s   d S(   s   if cond then ift else iffN(    (   R   t   iftt   iff(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRe    s    c         C` s   d S(   s   bitwise a & bN(    (   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   and_  s    c         C` s   d S(   s   bitwise a | bN(    (   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   or_  s    c         C` s   d S(   s   bitwise a ^ bN(    (   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   xor  s    c         C` s   d S(   s
   bitwise ~aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   invert  s    c         C` s   d S(   s   |`a`|

    TensorVariable overloads the `TensorVariable.__abs__` operator so that
    this function is called when you type abs(a).

    N(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   abs_  s    s   |%(0)s|ic         C` s   d S(   s   e^`a`N(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   exp  s    c         C` s   d S(   s   2^`a`N(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   exp2  s    c         C` s   d S(   s	   e^`a` - 1N(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   expm1  s    c         C` s   d S(   s   -aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   neg   s    c         C` s   d S(   s   1.0/aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   inv'  s    c         C` s   d S(   s   base e logarithm of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   log,  s    c         C` s   d S(   s   base 2 logarithm of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   log21  s    c         C` s   d S(   s   base 10 logarithm of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   log106  s    c         C` s   d S(   s   log(1+a)N(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   log1p;  s    c         C` s   d S(   s	   sign of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRw  @  s    c         C` s   d S(   s   ceiling of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   ceilE  s    c         C` s   d S(   s
   floor of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   floorJ  s    c         C` s   d S(   s
   trunc of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   truncO  s    c         C` s   t  t |  |  d  S(   s   cast(round(a,mode),'int64')R   (   R%  t   round(   R-   t   mode(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   iroundT  s    c         C` sq   | d k r1 d } t j j r1 t j d  q1 n  | d k rG t |   S| d k r] t |   St d |   d S(   s\   round_mode(a) with mode in [half_away_from_zero, half_to_even].
    Default to half_to_even.t   half_to_evens   theano.tensor.round() changed its default from `half_away_from_zero` to `half_to_even` to have the same default as NumPy. Use the Theano flag `warn.round=False` to disable this warning.t   half_away_from_zeros!   round mode %s is not implemented.N(   RL   R   t   warnR  t   warningst   round_half_away_from_zerot   round_half_to_evenR`   (   R-   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  Z  s    

c         C` s   d S(   s   round_half_to_even(a)N(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  n  s    c         C` s   d S(   s   round_half_away_from_zero(a)N(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  s  s    c         C` s   d S(   s   square of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   sqrx  s    c         C` s   d S(   s   square root of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   sqrt  s    c         C` s   d S(   s   convert degree a to radianN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   deg2rad  s    c         C` s   d S(   s   convert radian a to degreeN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   rad2deg  s    c         C` s   d S(   s   cosine of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   cos  s    c         C` s   d S(   s   arccosine of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   arccos  s    c         C` s   d S(   s	   sine of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   sin  s    c         C` s   d S(   s   arcsine of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   arcsin  s    c         C` s   d S(   s   tangent of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   tan  s    c         C` s   d S(   s   arctangent of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   arctan  s    c         C` s   d S(   s   arctangent of a / bN(    (   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   arctan2  s    c         C` s   d S(   s   hyperbolic cosine of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   cosh  s    c         C` s   d S(   s   hyperbolic arc cosine of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   arccosh  s    c         C` s   d S(   s   hyperbolic sine of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   sinh  s    c         C` s   d S(   s   hyperbolic arc sine of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   arcsinh  s    c         C` s   d S(   s   hyperbolic tangent of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   tanh  s    c         C` s   d S(   s   hyperbolic arc tangent of aN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   arctanh  s    c         C` s   d S(   s   error functionN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   erf  s    c         C` s   d S(   s   complementary error functionN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   erfc  s    c         C` s   d S(   s#   scaled complementary error functionN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   erfcx  s    c         C` s   d S(   s   inverse error functionN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   erfinv  s    c         C` s   d S(   s$   inverse complementary error functionN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   erfcinv  s    c         C` s   d S(   s   gamma functionN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   gamma  s    c         C` s   d S(   s   log gamma functionN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   gammaln  s    c         C` s   d S(   s    derivative of log gamma functionN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   psi  s    c         C` s   d S(   s   chi squared survival functionN(    (   R7   t   k(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   chi2sf  s    c         C` s   d S(   s    Bessel function of the 0'th kindN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   j0  s    c         C` s   d S(   s    Bessel function of the 1'th kindN(    (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   j1	  s    c         C` s   d S(   s2   Return real component of complex-valued tensor `z`N(    (   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   real	  s    c         C` s   d S(   s7   Return imaginary component of complex-valued tensor `z`N(    (   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   imag	  s    c         C` s   d S(   s:   Return polar-coordinate angle of complex-valued tensor `z`N(    (   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   angle	  s    c         C` s   d S(   s>   Return complex-valued tensor with `real` and `imag` componentsN(    (   R  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   	  s    c         C` s   d S(   s$   Return the complex conjugate of `z`.N(    (   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   conj	  s    c         C` s   d S(   sA   Return complex-valued tensor from polar coordinate specification.N(    (   R2   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   complex_from_polar#	  s    c         C` s   d S(   s0   Create a matrix by filling the shape of a with bN(    (   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   second.	  s    t   fillc         C` sV   | d k r |  j j } n  t d d | } | rI | j |  j k rI | St |  |  S(   s  equivalent of numpy.ones_like
    Parameters
    ----------
    model : tensor
    dtype : data-type, optional
    opt : If True, we will return a constant instead of a graph when possible.
          Useful for Theano optimization, not for user building a graph as this
          have the consequence that model isn't always in the graph.

    Returns
    -------
    tensor
        tensor the shape of model containing ones of the type of dtype.
    g      ?R1   N(   RL   RP   R1   R^   R  (   t   modelR1   R   Rz   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt	   ones_like6	  s    c         C` sV   | d k r |  j j } n  t d d | } | rI | j |  j k rI | St |  |  S(   s  equivalent of numpy.zeros_like
    Parameters
    ----------
    model : tensor
    dtype : data-type, optional
    opt : If True, we will return a constant instead of a graph when possible.
          Useful for Theano optimization, not for user building a graph as this
          have the consequence that model isn't always in the graph.

    Returns
    -------
    tensor
        tensor the shape of model containing zeros of the type of dtype.
    g        R1   N(   RL   RP   R1   R^   R  (   R  R1   R   Rz   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  N	  s    c         C` sX   t  |  t t t f  s$ |  g }  n  | d k r< t j } n  t t j	 d d | |   S(   sU   
    Create a Tensor filled with zeros, closer to Numpy's syntax than ``alloc``.
    i    R1   N(
   R/   RV   RY   R   RL   R   R   Rn  R*   R   (   R   R1   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   zerosg	  s
    c         C` sX   t  |  t t t f  s$ |  g }  n  | d k r< t j } n  t t j	 d d | |   S(   sT   
    Create a Tensor filled with ones, closer to Numpy's syntax than ``alloc``.
    i   R1   N(
   R/   RV   RY   R   RL   R   R   Rn  R*   R   (   R   R1   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   onesr	  s
    t   Nonzeroc           B` s/   e  Z d  Z d Z d   Z d   Z d   Z RS(   s  
    Return the indices of the elements that are non-zero.

    Returns a matrix of shape (ndim, number of nonzero elements) such that
    element (i,j) is the index in the ith dimension of the jth non-zero
    element.

    Note this is different than NumPy, which returns a tuple of arrays, one for
    each dimension of the input array.

    Parameters
    ----------
    a : array_like
        Input array.

    Returns
    -------
    matrix
        Matrix containing the indices of the non-zero elements of a.

    See Also
    --------
    nonzero_values : Return the non-zero elements of the input array
    flatnonzero : Return the indices of the non-zero elements of the
        flattened input array.

    c         C` sa   t  |  } | j d k r* t d   n  t d d d t t f    g } t j |  | g |  S(   Ni    s(   Nonzero only supports non-scalar arrays.R1   R   RT   (   Re   RH   RO   R   R|   R   R	   (   R   R-   t   output(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   	  s
    !c         C` s|   | d } | \ } t  j |  } t | d  d k rJ t  j |  } n t  j t |  d f  } | j d  | d <d  S(   Ni    R   (   R*   t   nonzeroRM   t   vstackR  R	  (   R   R  R   R  R-   R  t   result_tuplet   result(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   	  s    
	c         C` s   t  |  d | d  g S(   Ni    (   R   (   R   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  	  s    (    (   R'   R(   R)   R  R   R   R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  }	  s
   		c         C` so   t  |   } | r | S|  j d k rT t g  t |  j  D] } | | ^ q8  } n t | d g  } | Sd S(   s  
    Returns one of the following:

        If return_matrix is False (default, same as NumPy):
            A tuple of vector arrays such that the ith element of the jth array
            is the index of the ith non-zero element of the input array in the
            jth dimension.

        If return_matrix is True (same as Theano Op):
            Returns a matrix of shape (ndim, number of nonzero elements) such
            that element (i,j) is the index in the ith dimension of the jth
            non-zero element.

    Parameters
    ----------
    a : array_like
        Input array.
    return_matrix : bool
        If True, returns a symbolic matrix. If False, returns a tuple of
        arrays. Defaults to False.

    Returns
    -------
    tuple of vectors or matrix

    See Also
    --------
    nonzero_values : Return the non-zero elements of the input array
    flatnonzero : Return the indices of the non-zero elements of the
        flattened input array.

    i    N(   t   _nonzeroRH   RY   R   (   R-   t   return_matrixt   matrix_resultR   t   tuple_result(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  	  s    !/c         C` s8   |  j  d k r t d   n  t |  j   d t d S(   s  
    Return a vector of indices that are non-zero in the flattened version of a.

    This is equivalent to nonzero(a.flatten(), return_matrix=True)[0]

    Parameters
    ----------
    a : tensor
        Input tensor

    Returns
    -------
    vector
        Output vector, containing the indices of the elements of `a.flatten()`
        that are non-zero.

    See Also
    --------
    nonzero : Return the indices of the non-zero elements of the input array.
    nonzero_values : Return the non-zero elements of the input array

    i    s(   Nonzero only supports non-scalar arrays.R  (   RH   RO   R  R  Rg   (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   flatnonzero	  s    c         C` s   |  j    t |   S(   s/  
    Return a vector of non-zero elements contained in the input array.

    The following behavior works to extract non-zero elements from an array
    in NumPy but is *NOT* supported by Theano:

        a[numpy.nonzero(a)]

    Instead, the nonzero_values function or method should be used:

        tensor.nonzero_values(a)
        a.nonzero_values()

    This is equivalent to the following:

        a.flatten()[tensor.flatnonzero(a)]

    Parameters
    ----------
    a : tensor
        Input tensor

    Returns
    -------
    vector
        Output vector, containing the non-zero elements of a.

    See Also
    --------
    nonzero : Return the indices of the non-zero elements of the input array.
    flatnonzero : Return the indices of the non-zero elements of the
        flattened input array.

    (   R  R  (   R-   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   nonzero_values	  s    #t   Tric           B` s>   e  Z d Z d d  Z d   Z d   Z d   Z d   Z RS(   R1   c         C` s%   | d  k r t j } n  | |  _ d  S(   N(   RL   R   R   R1   (   R   R1   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR(  '
  s    c      	   C` s^   t  |  } t  |  } t  |  } t j |  | | | g t d |  j d t t f    g  S(   NR1   RT   (   Re   R   R	   R   R1   R|   (   R   t   Nt   MR  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   ,
  s    c         C` s>   | \ } } } | \ } t  j | | | d |  j | d <d  S(   NR1   i    (   R*   t   triR1   (   R   R  R   R  R  R  R  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   5
  s    	c         C` s!   | j  d | j  d g } | g S(   Ni    i   (   R   (   R   R  R  t	   out_shape(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  :
  s    c         C` s-   g  t  d  D] } t |  | | |  ^ q S(   Ni   (   R   R   (   R   R   R  R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  >
  s    (   s   dtypeN(	   R'   R(   R  RL   R(  R   R   R  R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  #
  s   				c         C` sI   | d k r t j } n  | d k r- |  } n  t |  } | |  | |  S(   s  
    An array with ones at and below the given diagonal and zeros elsewhere.

    Parameters
    ----------
    N : int
        Number of rows in the array.
    M : int, optional
        Number of columns in the array.
        By default, `M` is taken equal to `N`.
    k : int, optional
        The sub-diagonal at and below which the array is filled.
        `k` = 0 is the main diagonal, while `k` < 0 is below it,
        and `k` > 0 is above.  The default is 0.
    dtype : dtype, optional
        Data type of the returned array.  The default is float.

    Returns
    -------
    Array of shape (N, M)
        Array with its lower triangle filled with ones and zero elsewhere;
        in other words ``T[i,j] == 1`` for ``i <= j + k``, 0 otherwise.

    N(   RL   R   R   R  (   R  R  R  R1   RJ   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  B
  s    	c         C` s.   |  t  |  j d |  j d d | d |  j S(   s1  
    Lower triangle of an array.

    Return a copy of an array with elements above the `k`-th diagonal zeroed.

    Parameters
    ----------
    m : array_like, shape (M, N)
        Input array.
    k : int, optional
        Diagonal above which to zero elements.  `k = 0` (the default) is the
        main diagonal, `k < 0` is below it and `k > 0` is above.

    Returns
    -------
    array, shape (M, N)
        Lower triangle of `m`, of same shape and data-type as `m`.

    See Also
    --------
    triu : Same thing, only for the upper triangle.

    i    i   R  R1   (   R  R   R1   (   t   mR  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   trilc
  s    c      	   C` s6   |  d t  |  j d |  j d d | d d |  j S(   s  
    Upper triangle of an array.

    Return a copy of a matrix with the elements below the `k`-th diagonal
    zeroed.

    Please refer to the documentation for `tril` for further details.

    See Also
    --------
    tril : Lower triangle of an array.

    i   i    R  R1   (   R  R   R1   (   R  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   triu~
  s    t   Eyec           B` s>   e  Z d Z d d  Z d   Z d   Z d   Z d   Z RS(   R1   c         C` s%   | d  k r t j } n  | |  _ d  S(   N(   RL   R   R   R1   (   R   R1   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR(  
  s    c      	   C` s   t  |  } t  |  } t  |  } | j d k s9 t  | j d k sN t  | j d k sc t  t j |  | | | g t d |  j d t t f    g  S(   Ni    R1   RT   (   Re   RH   Rh   R   R	   R   R1   R|   (   R   R   R  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   
  s    c         C` s>   | \ } } } | \ } t  j | | | d |  j | d <d  S(   NR1   i    (   R*   t   eyeR1   (   R   R  R   R  R   R  R  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   
  s    	c         C` s!   | j  d | j  d g } | g S(   Ni    i   (   R   (   R   R  R  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  
  s    c         C` s-   g  t  d  D] } t |  | | |  ^ q S(   Ni   (   R   R   (   R   R   R  R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  
  s    (   s   dtypeN(	   R'   R(   R  RL   R(  R   R   R  R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  
  s   			c         C` sI   | d k r t j } n  | d k r- |  } n  t |  } | |  | |  S(   s  Return a 2-D array with ones on the diagonal and zeros elsewhere.

    Parameters
    ----------
    n : int
        Number of rows in the output.
    m : int, optional
        Number of columns in the output. If None, defaults to `N`.
    k : int, optional
        Index of the diagonal: 0 (the default) refers to the main diagonal,
        a positive value refers to an upper diagonal, and a negative value
        to a lower diagonal.
    dtype : data-type, optional
        Data-type of the returned array.

    Returns
    -------
    ndarray of shape (N,M)
        An array where all elements are equal to zero, except for the `k`-th
        diagonal, whose values are equal to one.

    N(   RL   R   R   R  (   R   R  R  R1   t   localop(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  
  s    	c         C` s*   t  |  j d |  j d d d d |  j S(   Ni    i   R  R1   (   R  R   R1   (   R7   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   identity_like
  s    c         ` s  g  |  D]   t     ^ q } g  } x t |  D] \ }     f d   }   j j t k r |   } t d | | f   n    j d k r |   } t d d |   j | f   n  y t    } Wn t k
 r d  } n X| j
 d | k  q2 W| | f S(   Nc           ` s+   t  j d k r d t    St    Sd  S(   NR   s   
(   R   R   R   R_   (    (   R   (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   err_str
  s    sT   Shape arguments to Alloc must be integers, but argument %s is not for apply node: %si    s0   Each shape dimension to Alloc must be a scalar, s6   but dimension %s have %d dimensions for apply node: %si   (   Re   R-  RP   R1   RS  R\   RH   R   R   RL   R;   (   R   t   sht   bcastR   R  t   s_as_strt	   const_shp(    (   R   s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   alloc_validate_shape
  s(    		
R   c           B` s}   e  Z d  Z e Z d Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d   Z d	   Z d
   Z d   Z RS(   s+  Create a Tensor from an initial value and a desired shape.

    alloc(value, shape0, shape1, ..., shapeN)

    Returns an N-dimensional tensor initialized by `value` using something
    equivalent to

        z = numpy.zeros(shape, value.dtype)
        z += value

    The result has N dimensions, has the dtype of `value` and is obtained by
    broadcasting value over the output ndarray.

    This Op is used to replace fill() during optimizations because after shapes
    are lifted, the first argument to fill can often be pruned from the graph.

    c         C` s
   t  |  S(   N(   R  (   R   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   validate_shape  s    c         G` s   t  |  } t |  \ } } | j t |  k rQ t d | j t |    n  t d | j d |  } t j |  | g | |   g  S(   NsH   The Alloc value to use has more dimensions than the specified dimensionsR1   RT   (	   Re   R  RH   RM   R\   R   R1   R   R	   (   R   t   valueR   R   R  R  t   otype(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   
  s    c         C` s   | \ } | d } t  g  | d D] } t |  ^ q!  } | d d  k s_ | d j | k r | j d k r | j   d k r t j | d | j | d <q t j	 | d | j | d <| | d d <n | | d d <d  S(   Ni    i   R1   .(
   RY   R   RL   R   Rt   t   itemR*   R  R1   t   empty(   R   R  R   R  R  R   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s    	
)#!c         C` s   | d } t  | d  } | \ } | d }	 d t d |  }
 x; t | d  D]) \ } } |
 d t d | d |  7}
 qQ W|
 d	 t d
 | d | d | d |	  7}
 |
 S(   Ni    i   R  s3   
            npy_intp shape[%(ndim)s];
            RH   sa   
                shape[%(i)s] = ((dtype_%(shp_i)s*) PyArray_DATA(%(shp_i)s))[0];
                R   t   shp_is  
            int need_new_out = (NULL == %(zz)s);
            for (int i = 0; i < %(ndim)s; i++)
                need_new_out = (need_new_out
                                || (PyArray_DIMS(%(zz)s)[i] != shape[i]));

            if (need_new_out)
            {
                Py_XDECREF(%(zz)s);
                %(zz)s = (PyArrayObject*) PyArray_SimpleNew(%(ndim)s,
                    shape, PyArray_TYPE((PyArrayObject*) py_%(vv)s));
                if (!%(zz)s)
                {
                    PyErr_SetString(PyExc_MemoryError, "alloc failed");
                    %(fail)s
                }
            }

            // This function takes care of broadcasting
            if (PyArray_CopyInto(%(zz)s, %(vv)s) == -1)
              %(fail)s
            t   vvt   zz(   RM   t   dictR-  (   R   R  RG   R   R  R  R  RH   R  R  t   codeR   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  "  s    
	
&c         C` s   d S(   Ni   (   i   (    (   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  K  s    c         C` s   | j  d g S(   Ni   (   R   (   R   R  t   input_shapes(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  N  s    c         C` s8   t  g g } x% | j d D] } | j t g  q W| S(   Ni   (   Rg   R   R;   R|   (   R   R  Rn   t   ipt(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   connection_patternQ  s    c         C` sC  | d } | d } | j  | j  } t t |   } g  } g  } xq t t | d j | d j | d j    D]@ \ }	 \ }
 } |
 r | r | j |	 |  qr | j |	  qr W| j d | |  } | rd g | j  } x$ t |  D] \ } } | | | <q W| j |  } n  | g g  | d D] }	 t	     ^ q,S(   Ni    R'  R7   i   (
   RH   RV   RW   R-  R   RT   R;   t   sumRU   R!   (   R   R   R  R7   t   gzt   n_axes_to_sumR'  t   axis_broadcastedt	   axis_keptR   t   ibt   gbt   gxt	   new_orderRb   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  Z  s&    

/c         O` s_   t  t |   j | | |  } y) t | d  rF | j | j k rF | SWn t k
 rZ n X| S(   s  
        If the alloc would be useless, this function returns val.

        If this function is called outside of a graph optimization context
        (for instance, it is manually called by a user building a graph),
        then we always return an Alloc node, to allow for DebugMode to check
        for size mismatches.

        If you always want an Alloc node, call make_node.

        t   fgraph(   t   superR   t   __call__RI   RP   t   AttributeError(   R   R   R?  R   Rz   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  x  s    !c         C` s8   | d d  k r d  g S|  | d | d t d t   S(   Ni    i   t   return_list(   RL   R  Rg   (   R   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    c         C` s   t  | j d d g   s t Sx | j d j D] } | d d k rH t S| d d k r t | d j t j j j	 t j j j
 t j j j t j j j t j j j t j j j t j j j t j j j f  r t S| d j j j j   j d  r. t Sq. Wt S(   Ni    t   clientsR  i   t   gpu(   R?   RN   R|   R  R/   RJ   R   R   R   t   IncSubtensort   AdvancedIncSubtensor1t   AdvancedIncSubtensort   blast   Gemvt   blas_ct   CGemvt   Gert   CGert
   blas_scipyt   ScipyGerR   R'   t   lowerR"  Rg   (   R   R  t   client(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   do_constant_folding  s&    "(    (   R'   R(   R)   Rg   t   _f16_okR  R  R   R   R  R  R  R  R  R  R  R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   
  s   		
		)							Rn  c         C` s`   | d k r t  |   Sx0 t j D]% } | |  |  } | d k	 r  | Sq  Wt d | f   d S(   s  
    Return a version of `var` transferred to `target`.

    `cpu` mean a TensorType (on the CPU).  Other types may define
    additional targets.

    Parameters
    ----------
    var : variable
        A theano variable
    target : str
        The target of the transfer
    t   cpus   Can't transfer to target %sN(   Re   t   transfert   _othersRL   RO   (   R   t   targett   transt   res(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    
c         C` s   t  j j |   d S(   sp   
    Register a transfer function for alternative targets.

    Parameters
    ----------
    fn : callable
    N(   R  R  R;   (   t   fn(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   register_transfer  s    c         C` sC   t  j d | d | d |  |   } | r? t |  | |  } n  | S(   sI  
    Computes the sum along the given axis(es) of a tensor `input`.

    When axis is None (the default value), the sum is performed
    over the flattened tensor.

    For full documentation see ``tensor.elemwise.Sum``.
    In particular please pay attention to the important warning when using
    a custom acc_dtype.

    Parameters
    ----------
    keepdims: bool
        If this is set to True, the axes which are reduced are left in
        the result as dimensions with size one. With this option, the result
        will broadcast correctly against the original tensor.

    R'  R1   t	   acc_dtype(   R   R%   R]  (   t   inputR'  R1   R^  R  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    $R  c         C` sF   t  j | d | d | d | |   } | rB t |  | |  } n  | S(   s  
    Computes the product along the given axis(es) of a tensor `input`.

    When axis is None (the default value), the product is performed
    over the flattened tensor.

    For full documentation see ``tensor.elemwise.Prod``.

    Parameters
    ----------
    keepdims: bool
        If this is set to True, the axes which are reduced are left in
        the result as dimensions with size one. With this option, the result
        will broadcast correctly against the original tensor.

    R1   R  t   no_zeros_in_input(   R   t   ProdR]  (   R  R'  R1   R^  R  R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR2    s
    t   Meanc           B` s8   e  Z d d   Z d   Z d   Z d   Z d   Z RS(   c         C` sG   t  j j |  t j |  |  j d  k sC t |  j  d k sC t  d  S(   Ni   (	   R   R$   R(  RQ   t   addR'  RL   RM   Rh   (   R   R'  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR(  !  s    c         C` s5   |  j  d  k	 r- d d j d   |  j  D  Sd Sd  S(   Ns   Mean{%s}s   , c         s` s   |  ] } t  |  Vq d  S(   N(   R_   (   R,   R7   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pys	   <genexpr>'  s    R"  (   R'  RL   t   join(   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   __str__%  s    c         C` s   d S(   NR   (    (   R   t   idtype(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   _output_dtype+  s    c         C` sc   | \ } | \ } |  j  d  k r* d  } n |  j  d } t j t j | d d d |  | d <d  S(   Ni    R1   R   R'  (   R'  RL   R*   R   t   mean(   R   R  R   R  R  R  R'  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   /  s    			c         C` sl   |  j  d  k	 r1 t t |   j | | | | |  St j j |  | | | | |  } | d | d | d f S(   Ns8   
  *((double *)PyArray_DATA(%s)) /= PyArray_SIZE(%s);
  i    (   R'  RL   R  R   R  R   R$   (   R   R  RG   t   inamest   onamesR  Rz   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  ;  s
    "!N(   R'   R(   RL   R(  R%  R'  R   R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR"     s
   			c      
   C` sL  t  |   }  | r | d k r0 t d |   n  | d k rN t d |   n  t |  |   } | r{ t |  | |  } n  | S| d k	 r | } n d } |  j d k r d } n  t |  d | d | d | d	 | } t |   }	 | j d k rt |	 d  }	 n t |	 d  }	 | d k r6t	 t
 |  j   } nv t | t t j f  rZ| g } nR t | t j  r| j d k rt |  g } n g  | D] }
 t |
  ^ q} x! | D] } t | |	 |  } qW| j |	 j k r| j t k rt | |	 j  } n  | d k s-| d k r?|  j d k r?t | d  } n  d | _ | S(   s  
    Computes the mean value along the given axis(es) of a tensor `input`.

    Parameters
    ----------
    axis : None or int or (list of int) (see `Sum`)
        Compute the mean along this axis of the tensor.
        None means all axes (like numpy).
    dtype: None or string
        Dtype to cast the result of the inner summation into.
        For instance, by default, a sum of a float32 tensor will be
        done in float64 (acc_dtype would be float64 by default),
        but that result will be casted back in float32.
    keepdims: bool
        If this is set to True, the axes which are reduced are
        left in the result as dimensions with size one. With this option,
        the result will broadcast correctly against the original tensor.
    acc_dtype: None or string
        Dtype to use for the inner summation. This will not
        necessarily be the dtype of the output (in particular
        if it is a discrete (int/uint) dtype, the output will
        be in a float type). If None, then we use the same rules as `sum()`.

    Notes
    -----
    For gpu, if you specify dtype=float32, everything will be done on the gpu.

    R   s   The Mean op does not support the dtype argument, and will always use float64. If you want to specify the dtype, call tensor.mean(..., op=False).s   The Mean op does not support the acc_dtype argument, and will always use float64. If you want to specify acc_dtype, call tensor.mean(..., op=False).R~   R   R'  R1   R^  R  R   i    R(  N(   Ns   float64(   Ns   float64(   s   float16s   float32s	   complex64(   Re   RL   R
  R"  R]  R1   R  R   R%  RV   RW   RH   R/   R   R*   R   R0   R   t   true_divR  RG   (   R  R'  R1   RJ   R^  R  R  t	   sum_dtypeR   R   R-   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR(  K  sP    			!!'	c         C` s  t  | t  r t d   n  |  j j } | d k rK t t |   } nv t  | t t	 j
 f  ro | g } nR t  | t	 j  r | j d k r t |  g } n g  | D] } t |  ^ q } t |  | d t } |  | } t d d | j }	 | d k rt | |	 | d | }
 nP t |   | } t | |	 d | d | }
 x! | D] } t |
 | |  }
 qPW| r| d k rt | | d | d } nd t |   | } t |   } t | d | d | d } x) | D]! } t | | | | |  } qW|
 | }
 n  d |
 _ |
 S(	   s  
    Computes the variance along the given axis(es) of a tensor `input`.

    Parameters
    ----------
    axis: None or int or (list of int) (see `Sum`)
        Compute the variance along this axis of the tensor.
        None means all axes (like numpy).
    ddof: Degrees of freedom; 0 would compute the ML estimate, 1 would compute
        the unbiased estimate.
    keepdims : bool
        If this is set to True, the axes which are reduced are
        left in the result as dimensions with size one. With this option,
        the result will broadcast correctly against the original tensor.
    corrected : bool
        If this is set to True, the 'corrected_two_pass' algorithm is
        used to compute the variance.
        Refer : http://www.cs.yale.edu/publications/techreports/tr222.pdf

    Notes
    -----
    Default uses the two-pass algorithm (reference below).
    https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Two-pass_algorithm
    Also supports 'corrected_two_pass' algorithm (using the 'corrected' flag)
    which is numerically more stable. There exist other implementations that
    offer better stability, but probably slower.

    s{   Parameter keepdims is now at index 3: (input,                           axis=None, ddof=0, keepdims=False, corrected=False)i    R^  i   R1   R'  R   N(   R/   R]   RO   RP   RH   RL   RV   RW   R   R*   R   R0   R   R(  Rg   R^   R1   R   R  R+  RG   (   R  R'  t   ddofR^  t	   correctedt
   input_ndimR-   t
   mean_inputt   centered_inputt   twoR   R   R   t   errort   shp_inp(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s>    !
	c         C` sX   t  | t  r t d   n  t t d |  d | d | d | d |   } d | _ | S(   s  
    Computes the standard deviation along the given axis(es) of a tensor `input`.

    Parameters
    ----------
    axis: None or int or (list of int) (see `Sum`)
        Compute the variance along this axis of the tensor.
        None means all axes (like numpy).
    ddof: Degrees of freedom; 0 would compute the ML estimate, 1 would compute
        the unbiased estimate.
    keepdims : bool
        If this is set to True, the axes which are reduced are
        left in the result as dimensions with size one. With this option,
        the result will broadcast correctly against the original tensor.
    corrected : bool
        If this is set to True, the 'corrected_two_pass' algorithm is
        used to compute the variance.
        Refer : http://www.cs.yale.edu/publications/techreports/tr222.pdf

    Notes
    -----
    It calls 'var()' and 'var()' uses the two-pass algorithm (reference below).
    https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Two-pass_algorithm
    Function 'var()' also supports 'corrected_two_pass' algorithm (using the
    'corrected' flag) which is numerically more stable. There exist other
    implementations that offer better stability, but probably slower.

    s{   Parameter keepdims is now at index 3: (input,                           axis=None, ddof=0, keepdims=False, corrected=False)R  R'  R-  R^  R.  t   std(   R/   R]   RO   R  R   RG   (   R  R'  R-  R^  R.  Rz   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR5    s    	t   Defaultc           B` s6   e  Z d  Z i d g d 6Z d Z d   Z d   Z RS(   s   
    Takes an input x and a default value.

    If the input is not None, a reference to it is returned.
    If the input is None, a copy of the default value is returned instead.
    The input and the default must have exactly the same type.

    i    c         C` sb   t  |  t  |  } } | j | j k r@ t d | |   n  t j |  | | g | j   g  S(   Ns,   Both default() arguments must have same type(   Re   RP   R\   R   R	   (   R   R7   t   default(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   ,  s
    c         C` sB   | \ } } | \ } | d  k r4 | j   | d <n
 | | d <d  S(   Ni    (   RL   Ri   (   R   R  R   R  R7   R7  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   3  s
    	(    (   R'   R(   R)   t   view_mapR  R   R   (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR6     s
   	c         C` s   d S(   s7   elemwise maximum. See max for the maximum in one tensorN(    (   R7   R8   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRa  D  s    c         C` s   d S(   s7   elemwise minimum. See min for the minimum in one tensorN(    (   R7   R8   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   minimumJ  s    c         C` s]   t  j t |   j t k t |  j t k  } | t  j k rL t |  |  St |  |  Sd S(   sA   Proxy for either true_div or int_div, depending on types of x, y.N(   RQ   t   int_or_true_divRe   R1   R  t   int_divR+  (   R7   R8   R<   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt	   div_proxyP  s    c         C` s   t  |  |  t |  |  f S(   s1   elementvise divmod, using floor_div and mod_check(   t	   floor_divt	   mod_check(   R7   R8   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   divmod[  s    c         G` s   d S(   s   elementwise additionN(    (   R-   t   other_terms(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR#  `  s    c         C` s   d S(   s   elementwise subtractionN(    (   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  f  s    c         G` s   d S(   s   elementwise multiplicationN(    (   R-   R@  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   mull  s    c         C` s   d S(   s7   elementwise [true] division (inverse of multiplication)N(    (   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR+  r  s    c         C` s   d S(   s8   elementwise [floor] division (inverse of multiplication)N(    (   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR;  x  s    c         C` sk   t  |  |  } t t |  | d  | j  | } | j t j | j j d | j j d  k sg t  | S(   sx   
    Safely compute ceil(float_division(a, b)).

    Works for all dtypes, but mostly useful when a and b are int.

    i    i   (	   R;  R%  Rl  R1   RQ   t   upcastR   R   Rh   (   R-   R.   t   divRz   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   ceil_intdiv  s    #5c         C` sJ   t  |   j t k s* t  |  j t k r9 t j j  n t |  |  Sd S(   s/   Make sure we do not try to use complex numbers.N(   Re   R1   t   complex_dtypesRQ   t   Modt   complex_errort   mod(   R7   R8   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR>    s    c         C` s   d S(   s   elementwise moduloN(    (   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRH    s    c         C` s   d S(   s   elementwise powerN(    (   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   pow  s    c         C` s   d S(   s  
    Clip x to be between min and max.

    Notes
    -----
    When `x` is equal to the boundaries, the output is considered
    to be `x`, so at these points, the gradient of the cost wrt the output
    will be propagated to `x`, not to `min` nor `max`. In other words,
    on these points, the gradient wrt `x` will be equal to the gradient wrt
    the output, and the gradient wrt `min` and `max` will be zero.

    N(    (   R7   Rc  R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   clip  s    t   +it   eithert   *it   -t   leftt   /s   //s   **t   rightc         C` s   y t  |  | |  }  Wn t k
 r) n Xt |  t j  sQ t |  t j j  r |  j r t |  j j t	  r |  j j
 d }  q t |   }  n  |  S(   s  
    This function is basically a call to tensor.get_scalar_constant_value.

    The main difference is the behaviour in case of failure. While
    get_scalar_constant_value raises an TypeError, this function returns x,
    as a tensor if possible. If x is a ScalarVariable from a
    scalar_from_tensor, we remove the conversion. If x is just a
    ScalarVariable, we convert it to a tensor with tensor_from_scalar.

    i    (   R   R   R/   RQ   t   ScalarVariablet	   sharedvart   ScalarSharedVariableR   RJ   R   R   RS   (   R7   R   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   extract_constant  s    c         C` s   | d k r. t t |  j d d d   } n  t |  j |  |   } |  j r | t t |  j d d d   k r |  j d | _ n  | S(   s   
    Reorder the dimensions of x. (Default: reverse them)

    This is a macro around dimshuffle that matches the numpy.transpose function.

    i   is   .TN(   RL   RV   RW   RH   R#   RT   RG   (   R7   R6  Rz   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR0    s    ".c         C` s0  t  |   t  |  }  } |  j d k r7 t d   n | j d k rU t d   n |  j d k r |  j d g d g | j d   | S| j d k r |  | j d g d g |  j d   S|  j d k s | j d k rt |  | |  j d g t j d | j d  g g  St j j	 j
   |  |  Sd S(	   s7  
    Compute the batched dot product of two variables:

        batched_dot(a, b)[i] = dot(a[i], b[i])

    Note that this batched_dot function does one of three things, in the
    following sequence:

        1.  If either a or b is a vector, it returns the batched elementwise
            product without calling the Theano BatchedDot op.

        2.  If both a and b have either 2 or 3 dimensions, it calls Theano's
            BatchedDot op on a and b.

        3.  If either a or b has more than 3 dimensions, it calls Theano's
            batched_tensordot function with appropriate axes. The
            batched_tensordot function expresses high-dimensional batched
            dot products in terms of batched matrix-matrix dot products, so
            it may be possible to futherize optimize for performance.
    i    s%   a must have at least one (batch) axiss%   b must have at least one (batch) axisi   R7   i   i   N(   Re   RH   R\   RU   t   batched_tensordotR*   Ra  R   R   R
  t
   BatchedDot(   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   batched_dot  s    &&3i   c         C` s   t  |  | | d t d t S(   s  
    Compute a batched tensordot product.

    A hybrid of batched_dot and tensordot, this function computes the
    tensordot product between the two tensors, by iterating over the
    first dimension to perform a sequence of tensordots.

    Parameters
    ----------
    x : tensor
        A Tensor with sizes e.g.: for 3D (dim1, dim3, dim2)
    y : tensor
        A Tensor with sizes e.g.: for 3D (dim1, dim2, dim4)
    axes: int or array-like of length 2
        If an integer, the number of axes to sum over.
        If an array, it must have two array elements containing the axes to sum
        over in each tensor.

        If an integer i, it is converted to an array containing
        the last i dimensions of the first tensor and the first
        i dimensions of the second tensor (excluding the first
        (batch) dimension):
            axes = [list(range(a.ndim - i, b.ndim)), list(range(1,i+1))]

        If an array, its two elements must contain compatible axes
        of the two tensors. For example, [[1, 2], [2, 4]] means sum
        over the 2nd and 3rd axes of a and the 3rd and 5th axes of b.
        (Remember axes are zero-indexed!) The 2nd axis of a and the
        3rd axis of b must have the same shape; the same is true for
        the 3rd axis of a and the 5th axis of b.

    Like tensordot, this function uses a series of dimshuffles and
    reshapes to reduce the tensor dot product to a matrix or vector
    dot product.  Finally, it calls batched_dot to compute the result.
    t   dott   batched(   t   _tensordot_as_dotRX  Rg   (   R7   R8   R6  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRV    s    $c         C` s   t  |  } | |  | |  S(   N(   t   Split(   R7   t   splits_sizet   n_splitsR'  t	   the_split(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   splitC  s    R\  c           B` st   e  Z d  Z d Z d Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d	   Z d
   Z d   Z RS(   s  Partition a `TensorVariable` along some axis.

    Examples
    --------
    >>> x = vector()
    >>> splits = lvector()
    You have to declare right away how many split_points there will be.
    >>> ra, rb, rc = split(x, splits, n_splits = 3, axis = 0)
    >>> f = function([x, splits], [ra, rb, rc])
    >>> a, b, c = f([0,1,2,3,4,5], [3, 2, 1])
    a == [0,1,2]
    b == [3, 4]
    c == [5]

    t
   len_splitsc         C` s   t  |  |  _ d  S(   N(   R   Ra  (   R   Ra  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR(  _  s    c         C` s   |  j  j d |  j S(   Ns   {%s}(   R   R'   Ra  (   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR%  b  s    c         C` s   t  |  } t  |  } t  |  } | j t k rH t d | j   n  | j t k rl t d | j   n  | | | g } g  t |  j  D] } | j   ^ q } t |  | |  S(   t   WRITEMEs$   splits must have type tensor.lvectors   axis must have type lscalar(   Re   RP   t   int_vector_typesR\   t	   int_typesR   Ra  R	   (   R   R7   R'  t   splitsR   R   RN   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   e  s    (c         C` s  | \ } } } t  j d d !d
 k rC | j d k rC t |  } n  y | j | } Wn  t d | | j f   n Xt |  |  j k r t d t |  |  j f   n  t j	 |  | k r t d t j	 |  | f   n  t
 g  | D] } | d k  ^ q  rt d   n  g  | j D] }	 t d	 d	 d	  ^ q"}
 d } xd t |  j  D]S } | | | } t | | d	  |
 | <| j t |
   j   | | d <| } qVWd	 S(   Rb  i    i   i   i   s;   Split.perform() with axis=(%s) is invalid for x.shape==(%s)s.   In Split.perform(), len(splits) != len_splits.s!   The splits sum to %s, expected %ssG   Split: you tried to make an ndarray with a negative number of elements.N(   i   i   (   t   syst   version_infoRt   R   R   RO   RM   Ra  R*   R  RZ   t   sliceRL   R   R   RY   Ri   (   R   R  R   RN   R7   R'  Re  t   len_along_axist   nbR   t   general_keyt	   lower_idxR   t	   upper_idx(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   |  s.    %%(#c         C` s   | j  d } | j  d } | \ } } } g  } xy t |  j  D]h }	 t |  }
 t j j j |
 | | |	  }
 g  t t |   D] }	 |
 |	 ^ q }
 | j	 |
  q? W| S(   Ni   i   (
   R   R   Ra  Re   R   R   R   t   set_subtensorRM   R;   (   R   R  R  R'  Re  t   shp_xt   shp_axist
   shp_splitst
   out_shapesR   t   temp(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s     )c   
      C` s  | \ } } } |  | t  d t    } t g  | D] } t | j t  ^ q1  r} t     t |  d |  t |  d |  g Sg  } xR t | |  D]A \ }	 } t | j t  r | j |	 j	    q | j |  q Wt
 | |  t |  d |  t |  d |  g S(   s;   Join the gradients along the axis that was used to split x.R  i   i   (   R  Rg   R5   R/   RP   R!   R   R   R;   R  R$  (
   R   R   t	   g_outputsR7   R'  R   RN   t   gt   new_g_outputst   o(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    %	c         C` sE   | d d  k r* g  |  j D] } d  ^ q S|  j | d | d  j S(   Ni    i   (   RL   Ra  R   RN   (   R   R   R  R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    c         C` s   d S(   Ni   (   i   (    (   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    c         C` s   d S(   Ns\  
        /* Return 1 if output has the correct shape. */
        int split_output_shape_is_correct (
            PyArrayObject* output, PyArrayObject* array_to_split, int axis_to_split, npy_intp split_size
        ) {
            return
                PyArray_NDIM(output) == PyArray_NDIM(array_to_split)
                && memcmp(
                    PyArray_DIMS(output),
                    PyArray_DIMS(array_to_split),
                    axis_to_split * sizeof(npy_intp)
                ) == 0
                && memcmp(
                    PyArray_DIMS(output) + axis_to_split + 1,
                    PyArray_DIMS(array_to_split) + axis_to_split + 1,
                    (PyArray_NDIM(array_to_split) - axis_to_split - 1) * sizeof(npy_intp)
                ) == 0
                && split_size == PyArray_DIM(output, axis_to_split);
        }
        (    (   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   c_support_code  s    c         C` s   |  j  d k r d Sd d j |  } | \ } } }	 | d }
 t j | j d j  j } t j | j d j  j } | j d j j   d } | j d j j   d } |  j  } d t	   S(	   Ni    t    t   &s   , &R  i   i   s   
        int ndim = PyArray_NDIM(%(x)s);
        int axis = (int)(*(%(axis_dtype)s*)PyArray_GETPTR1(%(axis)s, 0));
        int splits_count = PyArray_DIM(%(splits)s, 0);
        npy_intp len_along_axis, sum_of_splits = 0, current_split_length = 0, current_split_start = 0;
        npy_intp* split_dims = NULL;
        PyObject* split_view = NULL;
        npy_intp data_offset;
        int i;
        PyArrayObject** outputs[] = {%(outputs_pointers)s};

        /* Check inputs. */

        if (splits_count != %(expected_splits_count)s) {
            PyErr_Format(PyExc_ValueError,
                "Split: splits count (%%d) != expected count (%%d).", splits_count, %(expected_splits_count)s);
            %(fail)s
        }

        if (axis < 0) {
            axis += ndim;
        }
        if (axis < 0 || axis >= ndim) {
            PyErr_Format(PyExc_IndexError, "Split: invalid axis %%d for a %%d-D array.", axis, ndim);
            %(fail)s
        }
        len_along_axis = PyArray_DIM(%(x)s, axis);

        for (i = 0; i < splits_count; ++i) {
            current_split_length = (npy_intp)(*(%(splits_dtype)s*)PyArray_GETPTR1(%(splits)s, i));
            if (current_split_length < 0) {
                PyErr_Format(PyExc_ValueError,
                    "Split: you try to take a negative number (%%ld) of elements.", current_split_length);
                %(fail)s
            }
            sum_of_splits += current_split_length;
        }
        if (sum_of_splits != len_along_axis) {
            PyErr_Format(PyExc_ValueError, "Split: the splits sums to %%ld, expected %%ld.", sum_of_splits, len_along_axis);
            %(fail)s
        }

        /* Check outputs. */

        split_dims = (npy_intp*) malloc(ndim * sizeof(npy_intp));
        if (split_dims == NULL) {
            PyErr_NoMemory();
            %(fail)s
        }

        memcpy(split_dims, PyArray_DIMS(%(x)s), ndim * sizeof(npy_intp));

        for (i = 0; i < splits_count; ++i) {
            PyArrayObject** output = outputs[i];
            current_split_length = (npy_intp) (* (%(splits_dtype)s*) PyArray_GETPTR1(%(splits)s, i));
            if (*output == NULL || !split_output_shape_is_correct(*output, %(x)s, axis, current_split_length)) {
                Py_XDECREF(*output);
                split_dims[axis] = current_split_length;
                *output = (PyArrayObject*)PyArray_EMPTY(ndim, split_dims, %(x_typenum)s, PyArray_IS_F_CONTIGUOUS(%(x)s));
                if (outputs == NULL) {
                    PyErr_SetString(PyExc_RuntimeError, "Split: unable to allocate an output.");
                    free(split_dims);
                    %(fail)s
                }
            }
        }

        /* Compute split. */

        for (i = 0; i < splits_count; ++i) {
            current_split_length = (npy_intp) (* (%(splits_dtype)s*) PyArray_GETPTR1(%(splits)s, i));
            data_offset = PyArray_STRIDE(%(x)s, axis) * current_split_start;
            split_dims[axis] = current_split_length;
            split_view = PyArray_New(&PyArray_Type,
                                    ndim, split_dims,
                                    %(x_typenum)s,
                                    PyArray_STRIDES(%(x)s),
                                    PyArray_BYTES(%(x)s) + data_offset,
                                    %(x_itemsize)s,
                                    PyArray_FLAGS(%(x)s),
                                    NULL);
            if (split_view == NULL) {
                PyErr_SetString(PyExc_RuntimeError, "Split: unable to create a view for a split.");
                free(split_dims);
                %(fail)s
            }
            if (PyArray_CopyInto(*outputs[i], (PyArrayObject*)split_view) != 0) {
                PyErr_SetString(PyExc_RuntimeError, "Split: unable to copy a split view into the output.");
                Py_XDECREF(split_view);
                free(split_dims);
                %(fail)s
            }
            Py_XDECREF(split_view);
            current_split_start += current_split_length;
        }

        free(split_dims);
        (
   Ra  R$  R*   R1   R   t   numt   itemsizeRP   t   dtype_specsR  (   R   R  RG   R   RN   R  t   outputs_pointersR7   R'  Re  R  t	   x_typenumt
   x_itemsizet
   axis_dtypet   splits_dtypet   expected_splits_count(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    
	cN(   s
   len_splits(   R'   R(   R)   RL   Ra  R  R(  R%  R   R   R  R  R  R  Rx  R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR\  H  s   				$					c         G` s>   t  g  | D] } | t f ^ q
   |   } t j j j |  S(   s"  
    Make the input broadcastable in the specified axes.

    For example, addbroadcast(x, 0) will make the first dimension of
    x broadcastable. When performing the function, if the length of
    x along that dimension is not 1, a ValueError will be raised.

    We apply the opt here not to pollute the graph especially during
    the gpu optimization

    Parameters
    ----------
    x : tensor_like
        Input theano tensor.
    axis : an int or an iterable object such as list or tuple of int values
        The dimension along which the tensor x should be broadcastable.
        If the length of x along these dimensions is not 1, a ValueError will
        be raised.

    Returns
    -------
    tensor
        A theano tensor, which is broadcastable along the specified dimensions.

    (   R   Rg   R   R   R   t   apply_rebroadcast_opt(   R7   R6  R'  Rn   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   addbroadcastS  s    +c         G` s>   t  g  | D] } | t f ^ q
   |   } t j j j |  S(   s0  
    Make the input impossible to broadcast in the specified axes.

    For example, addbroadcast(x, 0) will make the first dimension
    of x broadcastable. When performing the function, if the length
    of x along that dimension is not 1, a ValueError will be raised.

    We apply the opt here not to pollute the graph especially during
    the gpu optimization

    Parameters
    ----------
    x : tensor_like
        Input theano tensor.
    axis : an int or an iterable object such as list or tuple of int values
        The dimension along which the tensor x should be unbroadcastable.
        If the length of x along these dimensions is not 1, a ValueError will
        be raised.

    Returns
    -------
    tensor
        A theano tensor, which is unbroadcastable along the specified dimensions.

    (   R   R|   R   R   R   R  (   R7   R6  R'  Rn   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   unbroadcastq  s    +c         C` sN   t  g  t t |   D] } | | | f ^ q   |   } t j j j |  S(   sH  
    Make the input adopt a specific broadcasting pattern.

    Broadcastable must be iterable. For example,
    patternbroadcast(x, (True, False)) will make the first
    dimension of x broadcastable and the second dimension
    not broadcastable, so x will now be a row.

    We apply the opt here not to pollute the graph especially during the gpu
    optimization.

    Parameters
    ----------
    x : tensor_like
        Input theano tensor.
    broadcastable : an iterable object such as list or tuple of bool values
        A set of boolean values indicating whether a dimension should be
        broadcastable or not. If the length of x along these dimensions is
        not 1, a ValueError will be raised.

    Returns
    -------
    tensor
        A theano tensor, which is unbroadcastable along the specified dimensions.

    (   R   R   RM   R   R   R   R  (   R7   RT   R   Rn   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   patternbroadcast  s    5R   c           B` s   e  Z d  Z e Z d Z d d  Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z d   Z RS(   s  
    Concatenate multiple `TensorVariable`s along some axis.

    The axis must be given as first argument. All tensors must have the same
    shape along all dimensions other than this axis.
    Of course, TensorVariable instances do not have a shape, so this error
    cannot be caught until runtime.  See `perform()`.

    See Also
    --------
    stack : For joins involving scalar values

    Examples
    --------
    >>> x, y, z = tensor.matrix(), tensor.matrix(), tensor.matrix()
    >>> u = tensor.vector()

    >>> r = join(0, x, y, z)
    >>> c = join(1, x, y, z)
    >>> join(2, x, y, z)    # WRONG: the axis has to be an index into the shape
    >>> join(0, x, u)       # WRONG: joined tensors must have the same rank

    t   viewic         C` s3   | |  _  | d k r/ i d | g d 6|  _ n  d  S(   Nii   i    (   R  R8  (   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR(    s    	c         ` sM     j  d k r   j j Sd   j j d j   f d     j D  f Sd  S(   Nis   %s{%s}s   , c         3` s(   |  ] } d  | t    |  f Vq d S(   s   %s=%rN(   R?   (   R,   t   p(   R   (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pys	   <genexpr>  s   (   R  R   R'   R$  R  (   R   (    (   R   s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR%    s    
	c         C` s/   |  j  j |  t |  d  s+ d |  _ n  d  S(   NR  i(   t   __dict__t   updateRI   R  (   R   Rl   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   __setstate__  s    c         ` s   | d | d } } | s* t  d   n  g  | D] } t |  ^ q1 } g  | D] } | j j ^ qP } t j |       f d   } |  j | | | |  S(   s  
        Parameters
        ----------
        axis: an Int or integer-valued Variable
        tensors
            A variable number (but not zero) of tensors to
            concatenate along the specified axis.  These tensors must have
            the same shape along all dimensions other than this axis.

        Returns
        -------
        A symbolic Variable
            It has the same ndim as the input tensors, and the most inclusive
            dtype.

        i    i   s$   Cannot join an empty list of tensorsc         ` s   t  d   d |   S(   NR1   RT   (   R   (   Rm   (   t	   out_dtype(    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   output_maker  s    (   RO   Re   RP   R1   RQ   RB  t   _make_node_internal(   R   t   axis_and_tensorsR'  t   tensorsR7   t   as_tensor_variable_argst   dtypesR  (    (   R  s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s    c         C` s[  t  d   | D  s% t d   n  t |  d k rP t | d j j  } nZt g t | d j j  } t |  } t | t  s y t	 t
 |   } Wq t k
 r q Xn  t | t  r| | k  r t d | | f   n  | d k  r| | 7} n  xV | D]N } xE t | j j  D]1 \ } }	 | | k rAq#n  |	 r#t | | <q#q#Wq
Wy t | | <Wqt k
 rt d   qXn t g t | d j j  } t  g  | d D] } | j t |  k ^ q st d   n  t |  g t |  }
 |
 d j t k r6t d | |
 d j t   n  | |  g } t |  |
 |  } | S(	   Nc         s` s   |  ] } | j  j Vq d  S(   N(   RP   RH   (   R,   t   targs(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pys	   <genexpr>   s    sR   Join cannot handle arguments of dimension 0. For joining scalar values, see @stacki   i    s"   Join axis %d out of bounds [0, %d)s=   Join argument "axis" is out of range (given input dimensions)s@   Join() can only join tensors with the same number of dimensions.s)   Axis could not be cast to an integer type(   R5   R\   RM   RV   RP   RT   R|   R/   R   R   R   R   R   R-  Rg   RO   RH   Re   Rd  R	   (   R   R'  R  R  R  Rm   RH   R7   t   current_axist   bflagR   RN   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    sR    				,c   
      C` s   | \ } |  j  } | d | d } } | d k r t j g  | d | !| | d D] } | j | d k ^ qS  r | | | d <nh | d j }	 | |	 k  r t d | |	 f   n  t j t j | d | d | j	 d j
 j | d <d  S(   Ni    i   is"   Join axis %d out of bounds [0, %d)R'  R1   (   R  R*   R+   R   RH   R   R   R   R1  RN   RP   R1   (
   R   R  R  R  R  R  R'  R  R   RH   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   K  s    		9c         C` s   d S(   Ni   (   i   (    (   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  ^  s    c         C` s   | d | d } } |  j  } | | }	 | d }
 t |  } | \ } | d } | j d j j   d } g  } x4 t |  D]& \ } } | j d | | | f  q~ Wd j |  } t |  } d t   } | S(   Ni    i   R  sJ   Py_INCREF(%s);
                   PyList_SetItem(list, %s, (PyObject*)%s);s   
s  
        int axis = ((%(adtype)s *)PyArray_DATA(%(axis)s))[0];
        PyObject* list = PyList_New(%(l)s);
        %(copy_inputs_to_list)s
        int tensors_lens_sum;
        if(%(view)s != -1) {
            tensors_lens_sum = 0;

            for(int i=0; i < %(n)s; i++){
                tensors_lens_sum += PyArray_DIM((PyArrayObject *)(PyList_GetItem(list, i)), axis);
            }
            tensors_lens_sum -= PyArray_DIM(%(non_empty_tensor)s, axis);
        }
        if(%(view)s != -1 && tensors_lens_sum == 0) {
            Py_XDECREF(%(out)s);
            Py_INCREF(%(non_empty_tensor)s);
            %(out)s = %(non_empty_tensor)s;
        }else{
            //PyObject* PyArray_Concatenate(PyObject* obj, int axis)
            int ndim = PyArray_NDIM(%(input_1)s);
            if( axis < -ndim ){
                PyErr_Format(PyExc_IndexError,
                             "Join axis %%d out of bounds [0, %%d)", axis, ndim);
                %(fail)s
            }
            Py_XDECREF(%(out)s);
            %(out)s = (PyArrayObject *)PyArray_Concatenate(list, axis);
            Py_DECREF(list);
            if(!%(out)s){
                %(fail)s
            }
        }
        (	   R  RM   R   RP   R}  R-  R;   R$  R  (   R   R  RG   R   RN   R  R'  R  R  t   non_empty_tensort   input_1R   R  R  t   adtypet   copy_to_listR   R   t   copy_inputs_to_listR   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  a  s"    	

	
"c         C` s2   d  | d k r d  g S|  j | d | d  j S(   Ni   i    (   RL   R   RN   (   R   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    c         C` sR  | \ } | d | d } } t  |  d |  g } g  | D] } t |  j j ^ q: } t j |   }	 d |	 k s d |	 k r"t t |   }
 |
 | | t g  | D] } t	 |  | ^ q   } t
 | t  s | g } n  g  t | |  D] \ } } t | | j  ^ q } | | } n, | g  | D] } | j d t j  ^ q,} | S(   s    The gradient wrt a join op is a `Split`, used to partition
        the gradient along the `axis` which was used for joining.
        i    i   R   R   R1   (   R   Re   RP   R1   RQ   RB  R\  RM   R[   R   R/   RV   R   R  RT   R  R   R   (   R   R  R  R  R'  R  Rn   R7   R  R  R`  t   split_gzR  Ru  R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s"    	%&1&c   
      C` s&  t  |  d k s t  t  | d  } x< | d D]0 } | d  k	 sK t  t  |  | k s3 t  q3 Wt t | j d d  | j d | j d |  } g  } xu t |  D]g } | d | } | d | }	 x  | d D] } | | | } q W| j t t | |  | |	   q Wt	 |  g S(   Ni   i    i   (
   RM   Rh   RL   Re  Rk  R   R   R;   RD  RY   (
   R   R  t   ishapest   n_dimR   t   join_dimRr  t   dimt   t_sidet   f_side(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s"    

(   s   view(   R'   R(   R)   R|   t   check_inputR  R(  R%  R  R   R  R   R  R  R  R  R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s   					M			7		"R$  c         G` s+   t  |  d k r | d St |  |  Sd S(   s/  
    Convenience function to concatenate `TensorType`s along the given axis.

    This function will not add the op in the graph when it is not useful.
    For example, in the case that the list of tensors to be concatenated
    is one, it will just return the tensor.

    Parameters
    ----------
    tensors : list of tensors (or list-like)
        A list of tensors to be concatenated along the given axis.
        The shapes of the tensors to be concatenated must be all
        identical, except in the dimension (`axis`) on which they are to
        be joined.
    axis : int (symbolic or literal)
        On which dimension should the tensors be joined?  The `axis`
        must be a valid index into the shape of the tensors to be
        concatenated.
        The `axis` parameter may either be an integer or an object that
        can be converted to a scalar using `as_scalar`(`axis`). In the
        former case, the axis is fixed at construction, while in the
        latter it may vary over time depending on the value of the
        `axis` variable.
    i   i    N(   RM   t   join_(   R'  t   tensors_list(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR$    s    c   	      C` s*  | d k rO |  j d k rF |  j   } t | | d d j |  j  Sd } n  | d k  rk | |  j 7} n  | |  j | } t d  } t | d  } | g | | g | g |  j | d } t d |  } | g | | g | g |  j | d } t | |  j t	 |   |  j t	 |    S(   sG  
    Convenience function to roll TensorTypes along the given axis.

    Syntax copies numpy.roll function.

    Parameters
    ----------
    x : tensor_like
        Input tensor.
    shift : int (symbolic or literal)
        The number of places by which elements are shifted.
    axis : int (symbolic or literal), optional
        The axis along which elements are shifted. By default, the array
        is flattened before shifting, after which the original
        shape is restored.

    Returns
    -------
    tensor
        Output tensor, with the same shape as ``x``.

    i   R'  i    N(
   RL   RH   R  t   rollR3  R   Rh  R$  R   RY   (	   R7   t   shiftR'  R8   t   allslicet   front_slicet
   front_listt	   end_slicet   end_list(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  
  s$    	c         C` sR   t  |   } d g | g  t | j j  D] } | ^ q) } t | j |  |  S(   s   Reshape `t` by left-padding the shape with `n_ones` 1s.

    See Also
    --------
    shape_padaxis
    shape_padright
    Dimshuffle

    R7   (   Re   R   RP   RH   R#   RT   (   R  RE   t   _tR   RK  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRX   ?  s    0c         C` sR   t  |   } g  t | j j  D] } | ^ q d g | } t | j |  |  S(   s   Reshape `t` by right-padding the shape with `n_ones` 1s.

    See Also
    --------
    shape_padaxis
    shape_padleft
    Dimshuffle

    R7   (   Re   R   RP   RH   R#   RT   (   R  RE   R  R   RK  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   shape_padrightP  s    0c         C` s   t  |   } | j d } | | k o1 | k  n sW d j | |  } t |   n  | d k  rp | | 7} n  g  t | j j  D] } | ^ q } | j | d  t | j |  |  S(   s  Reshape `t` by inserting 1 at the dimension `axis`.

    Example
    -------
    >>> tensor = theano.tensor.tensor3()
    >>> theano.tensor.shape_padaxis(tensor, axis=0)
    DimShuffle{x,0,1,2}.0
    >>> theano.tensor.shape_padaxis(tensor, axis=1)
    DimShuffle{0,x,1,2}.0
    >>> theano.tensor.shape_padaxis(tensor, axis=3)
    DimShuffle{0,1,2,x}.0
    >>> theano.tensor.shape_padaxis(tensor, axis=-1)
    DimShuffle{0,1,2,x}.0

    See Also
    --------
    shape_padleft
    shape_padright
    Dimshuffle

    i   s%   axis {0} is out of bounds [-{1}, {1})i    R7   (	   Re   RH   t   formatR   R   RP   t   insertR#   RT   (   R  R'  R  RH   R   R   RK  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   shape_padaxisa  s    %c       	   O` s  |  r | r t  d   n  | r] t |  d t t f  r] t j d t d d d } n d | k r | d }  d | k r | d } q d } nH t |   d k r |  d	 } n d | k r | d } n d } |  d }  t |   d k r t  d
   n  t j	 g  |  D]T } t | t j
 t t t f  p\t | t  o\t | j t  o\| j d k ^ q rt t t |    }  t j g  |  D] } | j ^ q  } t j j j |  |    St | g  |  D] } t | |  ^ q S(   s  Stack tensors in sequence on given axis (default is 0).

    Take a sequence of tensors and stack them on given axis to make a single
    tensor. The size in dimension `axis` of the result will be equal to the number
    of tensors passed.

    Note: The interface stack(*tensors) is deprecated, you should use
    stack(tensors, axis=0) insted.

    Parameters
    ----------
    tensors : list or tuple of tensors
        A list of tensors to be stacked.
    axis : int
        The index of the new axis. Default value is 0.

    Examples
    --------
    >>> a = theano.tensor.scalar()
    >>> b = theano.tensor.scalar()
    >>> c = theano.tensor.scalar()
    >>> x = theano.tensor.stack([a, b, c])
    >>> x.ndim # x is a vector of length 3.
    1
    >>> a = theano.tensor.tensor4()
    >>> b = theano.tensor.tensor4()
    >>> c = theano.tensor.tensor4()
    >>> x = theano.tensor.stack([a, b, c])
    >>> x.ndim # x is a 5d tensor.
    5
    >>> rval = x.eval(dict((t, np.zeros((2, 2, 2, 2))) for t in [a, b, c]))
    >>> rval.shape # 3 tensors are stacked on axis 0
    (3, 2, 2, 2, 2)
    >>> x = theano.tensor.stack([a, b, c], axis=3)
    >>> x.ndim
    5
    >>> rval = x.eval(dict((t, np.zeros((2, 2, 2, 2))) for t in [a, b, c]))
    >>> rval.shape # 3 tensors are stacked on axis 3
    (2, 2, 2, 3, 2)
    >>> x = theano.tensor.stack([a, b, c], axis=-2)
    >>> x.ndim
    5
    >>> rval = x.eval(dict((t, np.zeros((2, 2, 2, 2))) for t in [a, b, c]))
    >>> rval.shape # 3 tensors are stacked on axis -2
    (2, 2, 2, 3, 2)
    sC   theano.tensor.stack(tensors, axis) must have at least one parameteri    sL   stack(*tensors) interface is deprecated, use stack(tensors, axis=0) instead.t
   stackleveli   R  R'  i   i   s_   tensors is empty. You should at least provide one tensor to theano.tensor.stack(tensors, axis).(   R`   R/   RV   RY   R  R  t   DeprecationWarningRM   R*   R+   t   numberR   R   t   python_complexR   RP   R   RH   t   mapRe   RQ   RB  R1   R   R   R   R   R$  R  (   R  R   R'  R  R   R1   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR[     s6    1!		
	
a%c         C` s4   t  |  t t f  s' t d |    n  t | |   S(   s   Alias for `join`(axis, *tensor_list).

    This function is similar to `join`, but uses the signature of
    numpy's concatenate function.

    Raises
    ------
    TypeError
        The tensor_list must be a tuple or list.

    s   The 'tensors' argument must be either a tuple or a list, make sure you did not forget () or [] around arguments of concatenate.(   R/   RY   RV   R\   R$  (   t   tensor_listR'  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR1    s
    c         C` s  t  |   }  |  j d k r. t d |    n  |  j j d rB d St |  t j  rs |  j j d k rs t |  j	  S|  j
 r t |  j
 j t j j j  r t |  j
 j  S|  j
 r t |  j
 j t  r |  j
 j d j j S|  j
 rUt |  j
 j t j j j  rUt |  j
 j j d t  rU|  j
 j d j
 rUt |  j
 j d j
 j t j j j  rUt t j j j |  j
 j |  j
 j j  d j  } t t j j j |  j
 j |  j
 j j  d j  } t t j j j |  j
 j |  j
 j j  d j  } |  j
 j d j
 j d j } t j t j  f } | d k r:d } n= t | |  rw| d k  rw| | 7} | d k  rwd } qwn  | d k r| } n@ t | |  r| | k r| } q| d k  r| | 7} qn  | d k rd } n  t | |  rUt | |  rUt | |  rU| d k rU| d k rU| d k rU| | k rU| | d | d Sn  t |  t"  rt j# j$ |  d d } n t% |   } t& d |   d S(   s  Return the run-time length of a symbolic vector.

    Parameters
    ----------
    v
        A rank-1 TensorType variable.

    Raises
    ------
    TypeError
        `v` hasn't the proper type.
    ValueError
        No special case applies, the length is not known.
        In general this is not possible, but for a number of special cases
        the length can be determined at compile / graph-construction time.
        This function implements these special cases.

    i   s*   argument must be symbolic vector, got '%s'i    t   fileR_   s   length not known: %sN('   Re   RH   R\   RP   RT   R/   R   R
   RM   Rs   R   RJ   R   R   R   R   R   R   R   R   R   Rh  R   R   RU  t   get_idx_listt   startt   stopt   stept   numberst   IntegralR*   R   RL   R   R   t
   debugprintR_   RO   (   R   R  R  R  RH   t   typesR   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     sd    $'	(%%%	
			c          G` sQ   t  |   d k s t  x& |  D] } | j j d k s t  q Wt |  d d S(   s   
    Horizontally stack two L{TensorType}s.

    Stack two L{TensorType}s along the second axis (column wise). These
    L{TensorType}s must have the same shape along all dimensions but the
    second.

    i   R'  i   (   RM   Rh   RP   RH   R1  (   R   t   arg(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   horizontal_stackP  s    c          G` sQ   t  |   d k s t  x& |  D] } | j j d k s t  q Wt |  d d S(   Ni   R'  i    (   RM   Rh   RP   RH   R1  (   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   vertical_stackf  s    t   Reshapec           B` s   e  Z d  Z i d g d 6Z e Z e Z d Z d d  Z
 d   Z d   Z d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z RS(   s   Perform a reshape operation of the input x to the new shape shp.

    The number of dimensions to which to reshape to (ndim) must be
    known at graph build time.

    i    RH   c         C` s%   | |  _  | d  k s! t d   d  S(   Ns.   name attribute for Reshape has been deprecated(   RH   RL   Rh   (   R   RH   RG   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR(  |  s    	c         C` s   d |  j  j |  j f S(   Ns   %s{%s}(   R   R'   RH   (   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR%    s    c   
      C` s  t  |  } | } t  | d d } | j t k pQ t | t  oQ | j j d k sl t d | | j   n  | j d k s t	  t | t  r g  | j D] } | d k ^ q } t
 j |  | | g t | j j |  g  St g |  j } | } t | d  r| j d k r| g } n  xj t |  j  D]Y } | | }	 t  |	  }	 y) t |	 d  oj|	 j   d k | | <Wq-t k
 rq-Xq-Wt
 j |  | | g t | j j |  g  Sd  S(   NRH   i   i    s   Shape must be integersR   (   Re   R1   Ru   R/   R   Rs   Rt   R\   RH   Rh   R   R	   R   RP   R|   RI   R   R   R   (
   R   R7   R   t   shp_origR   R  t   bcastst   shp_listt   indexR8   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s.    !"+
c         C` s   | \ } } | \ } t  |  |  j k rO t d t  |  |  j f |   n  y t j | |  | d <Wn* t k
 r t d | j | f   n Xd  S(   NsG   shape argument to Reshape.perform has incorrect length %i, should be %ii    s,   Cannot reshape input of shape %s to shape %s(   RM   RH   RO   R*   R3  R`   R   (   R   R  R   R  R7   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s    	c         C` s   t  g t g g S(   N(   Rg   R|   (   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    c         C` s=   | \ } } | \ } t  | t |  d | j t     g S(   NRH   (   R3  R   RH   R!   (   R   R   R  R7   R   t   g_out(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    	c         C` s8   | d d  k r d  g S|  | d | d t d t   S(   Ni    i   R  (   RL   R  Rg   (   R   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    c         C` s  t  | d  d k r$ d |  j g S| j d } t | t j j  rXt | j  } g  | D] } | d k r\ | ^ q\ } t  |  t  |  } | d k rt  |  d k rt	 | d   t	 |   } x t
 |  D]% \ } } | d k r | | | <q q WnP | d k r6| d r*t	 | d   g n d g } n | d k rQt d   n  | g Sg  t |  j  D] } | j d | ^ qh}	 |  j rt	 | d   t	 |	   }
 n  t g  t |  j  D]) } t t |	 | d  |
 |	 |  ^ q g Sd  S(   Ni    i   isI   shape argument to Reshape.perform must have at most one entry equal to -1(   i   (   RM   RH   R   R/   R   R   R   RV   Rs   RA  R-  RO   R   RY   Re  RD  (   R   R  R  t   requt   elet	   requ_partt   critt   missingR   RZ  t	   rest_size(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s,    %)-	c         C` s   d S(   Ni   (   i   (    (   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    c         C` s   t  | j d t  rc | \ } } | \ } |  j }	 | j d j j   d }
 | d } d t   St j |  | | | | |  Sd  S(   Ni    i   R  s)  
            assert (PyArray_NDIM(%(shp)s) == 1);
            npy_intp new_dims[%(new_ndim)s];
            PyArray_Dims newshape;
            newshape.ptr = new_dims;
            newshape.len = %(new_ndim)s;
            for (int ii = 0; ii < %(new_ndim)s; ++ii)
            {
                // -- We do not want an explicit cast here. the shp can be any
                // -- int* dtype. The compiler will explicitly upcast it, but
                // -- will err if this will downcast. This could happen if the
                // -- user pass an int64 dtype, but npy_intp endup being int32.
                new_dims[ii] = ((%(sdtype)s*)(
                        PyArray_BYTES(%(shp)s) +
                        ii * PyArray_STRIDES(%(shp)s)[0]))[0];
            }
            Py_XDECREF(%(z)s);
            %(z)s = (PyArrayObject *) PyArray_Newshape(%(x)s, &newshape,
                NPY_CORDER);
            if (!%(z)s)
            {
                //The error message should have been set by PyArray_Newshape
                %(fail)s;
            }
            (	   R/   R   R   RH   RP   R}  R  R   R  (   R   R  RG   R   RN   R  R7   R   R  t   new_ndimt   sdtypeR  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    		
(   s   ndimN(   R'   R(   R)   R8  Rg   R  R|   R  R  RL   R(  R%  R   R   R  R  R  R  R  R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  n  s   		 					8	c         C` s   | d  k rq t |  } | j d k r: t d |   n  y t |  } Wqq t k
 rm t d |   qq Xn  t |  } | |  |  } | S(   Ni   se   New shape in reshape must be a vector or a list/tuple of scalar. Got %s after conversion to a vector.s   The length of the provided shape (%s) cannot be automatically determined, so Theano is not able to know what the number of dimensions of the reshaped variable will be. You can provide the 'ndim' keyword argument to 'reshape' to avoid this problem.(   RL   Re   RH   R\   R   RO   R  (   R7   t   newshapeRH   RJ   Rn   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR3    s    t   Flattenc           B` s~   e  Z d  Z i d g d 6Z e Z d Z d d  Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z RS(   s   
    Flatten a tensor.

    Flattens a tensor to `outdim` dimensions by preserving the leading
    outdim - 1 shape components.

    .. note:: The interface Flatten(Op) is deprecated, you should use flatten.
    i    t   outdimi   c         C` s)   t  j d t d d t |  |  _ d  S(   Ns?   Flatten class is deprecated, please use flatten method instead.R  i   (   R  R  R  R   R  (   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR(  @  s
    c         C` s   d |  j  j |  j f S(   Ns   %s{%s}(   R   R'   R  (   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR%  H  s    c         C` s   t  |  } |  j d k  s6 | j rU |  j | j k rU t d |  j | j f   n  | j |  j d  } t | j |  j d  } | | f } t j |  | g t | j	 j
 |  g  S(   Ni   s5   invalid output ndimensions (%i) for tensor of rank %i(   Re   R  RH   RO   RT   R5   R   R	   R   RP   R1   (   R   R7   t   t_xt   bcast_kept_dimst   bcast_new_dimRT   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   K  s    *c         C` s   | \ } | \ } |  j  } | d k rz y | j | j  | d <Wq t k
 rv | j t j | j  f  | d <q Xna | t | j  k r | | d <n? | j | d  t j | j | d  f } | j |  | d <d  S(   Ni   i    (   R  R3  Rt   R  R*   R2  R   RM   (   R   R  R   R  R7   R  R  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   ]  s    			)c         C` s   | \ } | |  j  d  } | |  j  d } t |  d k rU t | d d f } n^ t |  d k rj nI t |  d k r |  j  d k r d } n t d |  j  t |  f   | | } | g S(   Ni   R1   R   i    s5   invalid output ndimensions (%i) for tensor of rank %i(   i   (   R  RM   R2  RO   (   R   R  R  t   in_shpt   part1t   part2R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  m  s    	!	
c         C` s.   | \ } | \ } t  | t |  | j  g S(   N(   R3  R   RH   (   R   R   R  R7   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    		c         C` s#   d  | k r d  g S|  j |   j S(   N(   RL   R   RN   (   R   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    c         C` s   d S(   Ni   (   i   i   (    (   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    c   
      C` s0   | \ } | \ } |  j  } | d }	 d t   S(   NR  sJ  
        if (%(outdim)s == PyArray_NDIM(%(x)s))
        {
            Py_XDECREF(%(out)s);
            Py_XINCREF(%(x)s);
            %(out)s = %(x)s;
        }
        else
        {
            Py_XDECREF(%(out)s);

            if (%(outdim)s == 1)
            {
                npy_intp size = PyArray_SIZE(%(x)s);
                PyArray_Dims newshape;
                newshape.ptr = &size;
                newshape.len = 1;
                %(out)s = (PyArrayObject*)PyArray_Newshape(%(x)s,
                                                           &newshape,
                                                           NPY_CORDER);
            }
            else
            {
                npy_intp *oldshape = PyArray_DIMS(%(x)s);
                npy_intp newshape_dims[%(outdim)s];

                int i;
                for (i = 0; i < %(outdim)s - 1; ++i)
                    newshape_dims[i] = oldshape[i];

                newshape_dims[i] = 1;

                for (int j = %(outdim)s - 1; j < PyArray_NDIM(%(x)s); ++j)
                    newshape_dims[i] *= oldshape[j];

                PyArray_Dims newshape;
                newshape.ptr = newshape_dims;
                newshape.len = %(outdim)s;
                %(out)s = (PyArrayObject*)PyArray_Newshape(%(x)s,
                                                           &newshape,
                                                           NPY_CORDER);
            }
        }
        if (!%(out)s)
        {
            //The error message should have been set by
            // PyArray_Newshape
            %(fail)s;
        }
        (   R  R  (
   R   R  RG   R   RN   R  R7   R  R  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s
    			
2(   s   outdim(   R'   R(   R)   R8  R|   R  R  R(  R%  R   R   R  R  R  R  R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  2  s   							c         C` s   |  j  | k S(   s  
    Verifies the dimensionality of the var is equal to
    outdim. This method is usually called after flatten method on a
    variable, where the first outdim-1 dimension size(s) of the variable
    is kept intact, and the last dimension size of the variable is made
    equal to the multiplication of its remaining dimension size(s), such that
    the variable would end up with as many dimension as outdim.

    Parameters
    ----------
        var : theano.tensor.var.TensorVariable
            the theano var on which the dimensionality is checked.

        outdim : int
            the expected dimensionality of var.

    Returns
    -------
    bool
        the comparison result of var's dim
        and the expected outdim.
    (   RH   (   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   is_flat  s    c         ` s   | d k  s' | d k rG | |  j  k rG t d | |  j  d f   n  | d k rq t |  j | d   d } n d } |  j |  } |  j | d  } t |  j | d  } | | f   t j j	 | t
   f d   t |    } | S(   s   
    Reshapes the variable x by keeping
    the first outdim-1 dimension size(s) of x the same,
    and making the last dimension size of x equal to
    the multiplication of its remaining dimension size(s).

    Parameters
    ----------
        x : theano.tensor.var.TensorVariable
            the variable that should be reshaped.

        outdim : int
            the number of dimensions of the returned variable

    Returns
    -------
    theano.tensor.var.TensorVariable
        the flattend variable with dimensionality of outdim
    i   s   outdim %s out of bound [1, %d)ic         ` s     |  S(   N(    (   R   (   RT   (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   <lambda>  s    (   i(   i(   RH   RO   RY   R   R3  RT   R5   R   R   R  t   filterRW   (   R7   R  t   dimst
   x_reshapedR  R  (    (   RT   s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    '	$t   Tilec           B` sJ   e  Z d  Z d Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(	   s  
    Construct an array by repeating the input x according to reps pattern.

    .. note:: Deprecated
              Use tile() instead.

    Tiles its input according to reps. The length of reps is the number of
    dimension of x and contains the number of times to tile x in each
    dimension.

    See Also
    --------
    numpy.tile : http://docs.scipy.org/doc/numpy/reference/generated/numpy.tile.html

    RH   c         C` s   | |  _  d  S(   N(   RH   (   R   RH   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR(  0  s    c         C` s   |  j  j d |  j S(   Ns	   {ndim=%d}(   R   R'   RH   (   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR%  3  s    c         C` s`   t  j d d d t |  } t |  } t j |  | | g t | j j t g |  j	  g  S(   Ns1   Tile op is deprecated, use tile function instead.R  i   (
   R  R  Re   R   R	   R   RP   R1   R|   RH   (   R   R7   t   reps(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   6  s    $c         C` s   | \ } } | \ } t  j | |  } | j |  j k rH t d   n  t  j |  d k j   r t  j | |  r | j   } q n  | | d <d  S(   Ns4   Tile.perform produced incorrect number of dimensionsi   i    (   R*   t   tileRH   RO   R   R+   t   may_share_memoryRi   (   R   R  R   R  R7   R  R  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   >  s    	c   	      C` s[   | j  \ } } | d } | | } g  } x( t |  j  D] } | j | |  q9 W| g S(   Ni    (   R   R   RH   R;   (	   R   R  R  R7   R  R   t	   tiled_shpR  R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  N  s    

c         C` s"   | \ } } | \ } t     d  S(   N(   R
  (   R   R   R  R7   R  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  b  s    	(   s   ndim(
   R'   R(   R)   R  R(  R%  R   R   R  R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s   					c         C` s  | d
 k	 r* | |  j k  r* t d   n  t | t t f  s:t |  } | j } | j t j	 j
 k rx t d   n  | d k r | g } q| d k r+| d
 k r t d   q7| | j d } t j	 j j | t | d   } g  t |  D]& } t | | k  d | | |  ^ q } | } qt d   n | d
 k	 rgt |  | k rgt d   n  t j g  | D]9 } t | t  pt | t  o| j t j	 j
 k ^ qt st d   n  t |  } | d
 k rt j t |  |  j  } n  t |  | k  r+d g | t |  | } n  d g | |  j g  t |  j  D] } |  j | ^ qL}	 | |	 }
 t |  |
  } t j | d	  j d	 |  } | j   j   } | j |   } g  t |	  D] \ } } | | | ^ q} | j |  } | S(   sX  
    Tile input array `x` according to `reps`.

    See the docstring of `numpy.tile` for details.

    'reps' can be constant integer (e.g. 3), constant vector(e.g. [2 3]),
    symbolic scalar (e.g. tensor.iscalar()), symbolic vector (e.g. tensor.ivector())
    or a list of symbolic scalar (e.g. [tensor.iscalar(), tensor.iscalar()]).

    ndim is the number of the dimensions of the output, if it is provided, ndim
    should be equal or larger than x.ndim and len(reps), otherwise, we will use
    max(x.ndim, len(reps)) as ndim. If reps is symbolic vector, the ndim has to
    be provided.

    s*   ndim should be equal or larger than x.ndims&   elements of reps must be integer dtypei    i   s5   if reps is tensor.vector, you should specify the ndims)   the dimension of reps should not exceed 1s+   len(reps) should be equal or less than ndims1   elements of reps must be scalars of integer dtypei   N(    RL   RH   RO   R/   RV   RY   Re   R1   R   R   R  R   R   t   assert_Rk  RW   Re  RM   R*   R+   R   R   R   R   R   Rn  R@  R3  R0  R  RU   R-  (   R7   R  RH   t   reps_astensort
   ndim_checkt   offsetR   t   reps_t   rR   t   alloc_shapeR8   t   shuffle_indR  t
   new_shapes(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  i  sH    	!9		F;
-t   ARangec           B` sh   e  Z d  Z d Z d   Z d   Z e j j d d  d    Z	 d   Z
 d   Z d	   Z d
   Z RS(   s   Create an array containing evenly spaced values within a given interval.

    Parameters and behaviour are the same as numpy.arange().

    R1   c         C` s   | |  _  d  S(   N(   R1   (   R   R1   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR(    s    c         C` s   t  t | | | f  \ } } } | j d k s6 t  | j d k sK t  | j d k s` t  | | | g } t |  j t f  g } t |  | |  S(   Ni    (   R  Re   RH   Rh   R   R1   R|   R	   (   R   R  R  R  R   RN   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s    !t   warn_float64t   ignorec         C` s   | j  \ } } } d   } d   } | | d  r | | d  rU t | d  f g S| |  } | |  } t t | | d  d  f g SnK | |  } | |  } t t t t | | d  |  d  d  f g Sd  S(   Nc         S` s;   y# t  |   } t j | | k  SWn t k
 r6 n Xt S(   N(   R   R*   R+   R   R|   (   R   R  R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   is_constant_value  s    c         S` s;   |  j  t k r7 t j |  j  d  d k r7 t |  d  S|  S(   NR   (   R1   RS  RQ   RB  R%  (   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRB    s    i   i    R   R   (   R   R%  Ra  R  (   R   R  t   i_shapesR  R  R  R  RB  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    		# c         C` sb   | \ } } } | \ } | j    } | j    } | j    } t j | | | d |  j | d <d  S(   NR1   i    (   R  R*   R@  R1   (   R   R  R   R  R  R  R  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s    	c         C` s   t  g t g t  g g S(   N(   Rg   R|   (   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    c         C` s7   | \ } } } | \ } | j    t     | j    g S(   N(   R  R!   (   R   R   R  R  R  R  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s
    			c         C` s   d  g S(   N(   RL   (   R   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  	  s    (   s   dtype(   R'   R(   R)   R  R(  R   R   t   configparsert   change_flagsR  R   R  R  R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s   		
%			c      
   C` s  | d  k r d |  }  } n  t t |  | | f  \ }  } } | d  k rt j |  j j | j j | j j  } | t k r d } n  | t k r d } n  t	 j
 d k rt j d t j d d |  j d t j d	 d | j d
 t j d	 d | j  j } | | k rt	 j
 d k rt	 j d k r| d k rt d   g  |  | | f D] } | j ^ qOD  r| d k s}t  d } qt |  } qqn  | t k rt |  t | <n  t | |  | |  S(   Ni    R   R!  R*   s   numpy+floatXR  R1   R  i   R  R   R   c         s` s   |  ] } | d  k Vq d S(   R   N(    (   R,   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pys	   <genexpr>/  s   (   s   numpys   numpy+floatX(   RL   R  Re   RQ   RB  RP   R1   Ru   Rv   R   t   cast_policyR*   R@  R   R   R5   Rh   R_   t   _arangeR  (   R  R  R  R1   t   numpy_dtypeR   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR@    s6    !'			,	t   _nd_gridc           B` s#   e  Z d  Z e d  Z d   Z RS(   s  Create a dense n-dimensional 'meshgrid' with equally spaced points.

    Used to create the instance ``mgrid`` and ``ogrid`` which act similarly
    to their numpy equivalents.

    Parameters
    ----------
    sparse : boolean, optional, default=True
        Specifying False leads to the equivalent of numpy's mgrid functionality.
        Specifying True leads to the equivalent of ogrid.

    Examples
    --------
    >>> a = T.mgrid[0:5, 0:3]
    >>> a[0].eval()
    array([[0, 0, 0],
           [1, 1, 1],
           [2, 2, 2],
           [3, 3, 3],
           [4, 4, 4]], dtype=int8)
    >>> a[1].eval()
    array([[0, 1, 2],
           [0, 1, 2],
           [0, 1, 2],
           [0, 1, 2],
           [0, 1, 2]], dtype=int8)
    >>> b = T.ogrid[0:5, 0:3]
    >>> b[0].eval()
    array([[0],
           [1],
           [2],
           [3],
           [4]], dtype=int8)
    >>> b[1].eval()
    array([[0, 1, 2, 3]], dtype=int8)

    c         C` s   | |  _  d  S(   N(   t   sparse(   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR(  e  s    c         G` s  t  | d  } x3 | d D]' } t | j t  r t d   q q Wg  | d D]- } t | j pf d | j | j px d  ^ qQ } g  t |  D]@ \ } } t	 d g | | j
 d g d g | d |  ^ q } g  t | |  D] \ } } | j |  ^ q } |  j r| }	 n g  }	 g  | D] } t |  ^ q'}
 xi t |  D][ } d } x? t |  D]1 } | | k r| | | } qe| |
 | } qeW|	 j |  qLW|	 S(   Ni    s0   Not implemented for slices whose step is complexi   (   RM   R/   R  R  R
  R@  R  R  R-  RY   R   R   R3  R  R  RW   R;   (   R   R   RH   t   slt   rangesR[  R  R?  R   t   gridsR  R   t   grid(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   h  s*    ;P1		(   R'   R(   R)   R|   R(  R   (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  >  s   %R  t   PermuteRowElementsc           B` sA   e  Z d  Z d Z d   Z d   Z d   Z d   Z d   Z RS(   s  Permute the elements of each row (inner-most dim) of a tensor.

    A permutation will be applied to every row (vector) of the input tensor x.
    Depending on the dimensionality of x and the permutation tensor y,
    different cases are possible.
    If y.ndim = 1, y is a single permutation, that will be applied to every
    vector of x. For instance, if x is a matrix, the same permutation will be
    applied to each row of x.
    If x.ndim = y.ndim, each row of x corresponds to a row of y, containing
    a permutation that will be applied to that row. For instance, if x and y
    are two matrices, a different permutation will be applied to each row of x.
    If x.ndim > y.ndim, y will be broadcasted to fit x, then each row (vector)
    of x will be reordered according to the corresponding row of y. (This is
    a generalization of the first case).
    If x.ndim = 1, every permutation in y will be applied to x, and the output
    will contain all the results.
    If x.ndim < y.ndim, x will be broadcasted to fit y, and different
    permutations contained in y will be applied to each vector in x. (This is
    a generalization of the previous case).

    If the "inverse" argument is True, the Op will perform the inverse
    permutation instead.
    c         C` sZ  t  |  } t  |  } | r- t  d  } n t  d  } | j j t k sQ t  | j j d k ru | j j t k s{ t  | j j } | j j } | | k r t | d | | } n% | | k  r t | d | | } n  g  t | j j | j j  D] \ } } | o| ^ q } t	 d | j j d |  }	 | | | g }
 |	 g } t
 |  |
 |  S(   Ni   i    RE   R1   RT   (   Re   RP   R1   RS  Rh   RH   RX   R   RT   R   R	   (   R   R7   R8   t   inverset   x_dimt   y_dimt   xbt   ybt   out_broadcastablet   out_typet	   inputlistt
   outputlist(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s&    *7	c   
   	   C` s  t  | j  d k r7 | r) | | | <q| | | (nT| j d } | j d } | | k r x+t |  D]2 }	 |  j | | |	 | |	 | | |	 | d  qj Wn | d k r| j d j j | rx t |  D]2 }	 |  j | | |	 | d | | |	 | d  q Wn | d k ru| j d j j | ruxY t |  D]2 }	 |  j | | d | |	 | | |	 | d  q<Wn t d | | f   d S(   s`  Perform the permutation by doing a recursion over the input
        dimensions.

        For every dimension, starting with the leftmost, the right set of
        indices is determined (depending if broadcasting or not), then
        the function is recursively called on the appropriate subtensors.

        The terminal case is reached when the current tensors are vector,
        then the permutation contained in y is applied to x.

        Parameters
        ----------
        x : tensor
            The input tensor, on which the permutation is applied.
        y : tensor
            Tensor containing the permutations to apply.
        out : tensor
            Tensor storing the output result.
        curdim : int
            Counter of the current depth of recursion.
        inverse
            Wether to apply permutations or their inverse.

        i   i    s   Dimension mismatch: %s, %sN(   RM   R   R   t   _rec_performR   RP   RT   RO   (
   R   R  R7   R8   R  R  t   curdimt   xs0t   ys0R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s&    !#!#!c         C` s9  | \ } } } | \ } | j  } | j  }	 t |  t |	  k sH t  g  }
 x t | |	  D]n \ } } | | k r | } n@ | d k r | } n+ | d k r | } n t d | | f   |
 j |  q^ W| d d  k s | d j  |
 k rt j |
 d | j	 | d <n  |  j
 | | | | | d d d d  S(   Ni   s   Dimension mismatch: %s, %si    R1   R	  (   R   RM   Rh   R   RO   R;   RL   R*   R  R1   R  (   R   R  R   R  R7   R8   R  R4  t   x_st   y_st   out_st   xdimt   ydimR  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s$    						#c         C` sz   | d } | d } t  |  t  |  k s2 t  g  } x8 t t  |   D]$ } | j t | | | |   qK W| g S(   Ni    i   (   RM   Rh   R   R;   Ra  (   R   R  R  Ro  t   shp_yR  R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    

"c         C` si  | \ } } } | \ } t  | | t | d   } g  t | j j  D]- } | j j | rF | j j | rF | ^ qF }	 t d |	  |  } g  }
 d } xM t | j j  D]9 } | |	 k r |
 j d  q |
 j |  | d 7} q Wt | j j |
  |  } | j j | j j k s#t	  | j j
 t k rD| j   } n  | t |  d |  t |  d |  g S(   Ni    R'  R7   i   (   t   permute_row_elementsRD  R   RP   RH   RT   R%   R;   R#   Rh   R1   R  R  R   (   R   R   R  R7   R8   R  R  R  R  t   broadcasted_dimst   newdimsR   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s(    	(    (	   R'   R(   R)   R  R   R  R   R  R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s   		3			c         C` s   t  |  | |  S(   N(   t   _permute_row_elements(   R7   R8   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  G  s    c         C` s)   t  t |  j d d |  j |  d t S(   sv   Computes the inverse of permutations.

    Each row of input should contain a permutation of the first integers.

    iR1   R  (   R  R@  R   R1   Rg   (   t   perm(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   inverse_permutationK  s    t   Dotc           B` sJ   e  Z d  Z d Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   s  
    Computes the dot product of two variables. For two matrices, this is
    equivalent to matrix multiplication. For two vectors, this is the inner
    product.

    Notes
    -----
    Matrix-matrix products are sometimes optimized to Dot22 or Gemm ops
    (see tensor.blas).
    Vector-vector products are sometimes optimized to Ger or CGer (see
    tensor.blas).
    Matrix-vector products are sometimes optimized to Gemv, CGemv (see
    tensor.blas).

    c   	      G` sU  t  t t |   } t |  d k r@ t d t |    n  | d j d k rm t d | d j   n  | d j d	 k r t d | d j   n  g  | D] } | j j ^ q } | \ } } t |  d k r | d  | d } n t |  d k r| d  } n  g  | D] } | j j ^ q} t	 t
 j |   |  g } t |  | |  S(
   Ni   s2   theano.tensor.Dot: 2 arguments required, %d given i    i   sv   theano.tensor.Dot: input 0 (0-indexed) must have ndim of 1 or 2, %d given. Consider calling theano.tensor.dot instead.sv   theano.tensor.Dot: input 1 (0-indexed) must have ndim of 1 or 2, %d given. Consider calling theano.tensor.dot instead.i(   i   i   (   i   i   (   RV   R  Re   RM   R\   RH   RP   RT   R1   R   RQ   RB  R	   (	   R   R   R  t   i_broadcastablest   bxt   byt   bzt   i_dtypesRN   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   u  s,    c         C` s8   | \ } } | \ } t  j t  j | |   | d <d  S(   Ni    (   R*   R   RY  (   R   R  R   R  R7   R8   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s    	c         C` s  | \ } } | \ } | j  j | j  j | j  j } } } | d k r^ | | }	 | | }
 n | d k r | d k r t | | j  }	 t | j |  }
 n | d k r | d k r t | | j  }	 t | j |  }
 nC | | k o d k n rt | | j  }	 t | j |  }
 n  |	 j | j k rFt |	 | j  }	 n  |
 j | j k rmt |
 | j  }
 n  |	 |
 f } x, | D]$ } | j j d  d k st	  qW| S(   Ni    i   i   R   i(
   RP   RH   RY  t   Tt   outerRT   R  R1   t   findRh   (   R   R   R  R7   R8   R  R  R  t   gdimt   xgradt   ygradRn   t   elem(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s.    	&
"c         C` s  t  |  d k s t  t  |  d k s0 t  | d d  k rW | d d  k rW d  g St j d k } | ry t j j | d  } Wn' t k
 r t j j	 d  t
 } n Xy t j j | d  } Wn' t k
 r t j j	 d  t
 } n X| d rEy t j j | d  } WqEt k
 rAt j j	 d  t
 } qEXn  | d ry t j j | d  } Wqt k
 rt j j	 d  t
 } qXqn  | rJ| | g } | | g }	 x t d  D] }
 |	 |
 d  k	 r| |
 j |	 |
 j k rt d	 t |
  d
 t |
  d t | |
 j  t |	 |
 j  f   qqWn  | d rn|  | d | d  } n  | d r|  | d | d  } n  | d r| d r| | g S| d r| g S| g Sd  S(   Ni   i    i   t   offs0   first input passed to Dot.R_op has no test values1   second input passed to Dot.R_op has no test values5   first eval point passed to Dot.R_op has no test values6   second eval point passed to Dot.R_op has no test values   input s    and eval_point sU    to Dot.R_op should have the same shape, but their shapes are %s and %s, respectively(   RM   Rh   RL   R   t   compute_test_valueR   RJ   t   get_test_valueR  t   missing_test_messageR|   R   R   RO   R_   (   R   R   R  t   debugger_availablet   iv0t   iv1t   ev0t   ev1t   input_valuest   eval_point_valuesR   t   t1t   t2(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    sh     	
	

	
	%


c         C` s   | \ } } | j  \ } } | j d k r@ | j d k r@ d g S| j d k ri | j d k ri | d  g S| j d k r | j d k r | d g S| j d k r | j d k r | d  | d g St    d  S(   Ni   i   i(    (   R   RH   R
  (   R   R  R?  t   xshpt   yshpR7   R8   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  	  s    c         C` s   d S(   NRY  (    (   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR%    s    (    (
   R'   R(   R)   R  R   R   R  R  R  R%  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  `  s   				*	D	t
   middle_dotc         C` s   t  |   t  |  }  } |  j d k s7 | j d k r? |  | S|  j d k s] | j d k r t |  | |  j d g t j d | j d  g g  St |  |  Sd S(   sd  
    Computes the dot product of two variables.

    For two matrices, this is equivalent to matrix multiplication.
    For two vectors, this is the inner product.
    When one variable is a scalar, this is like elementwise multiplication.
    For N dimensions, this is a sum product over the last axis
    of the first array and the second-to-last axis of the second array:

        dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])

    Note that this dot function does one of three things, in the following
    sequence:

        1.  If either a or b is scalar, it returns the elementwise product
            without calling the Theano Dot op.

        2.  If either a or b has more than 2 dimensions, it calls Theano's
            tensordot function with appropriate axes. The tensordot function
            expresses high-dimensional dot products in terms of 2D matrix
            multiplications, so it may be possible to futherize optimize for
            performance.

        3.  If both a and b have either 1 or 2 dimensions, it calls Theano's
            Dot op on a and b.

    Notes
    -----
    Matrix-matrix products are sometimes optimized to Dot22 or Gemm ops
    (see tensor.blas).
    Vector-vector products are sometimes optimized to Ger or CGer (see
    tensor.blas).
    Matrix-vector products are sometimes optimized to Gemv, CGemv (see
    tensor.blas).

    i    i   i   N(   Re   RH   t	   tensordotR*   Ra  t   _dot(   R-   R.   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRY  #  s    %6c         C` s<  t  |   t  |  }  } t j |  rT t |  d k rT t d t |    nt j |  rt |  } x d |  f d | f f D]t \ } } | | j k r t d | | | j | f   n  | r | | j k r t d | | | j | f   q q W| rd n d } t d |  j |  } t | | | j  }	 t	 |  j
 | | j
 |	 g  }
 |  j | | j |	 } t |  } d g d } d g d } xN t d |  D]= } | d c |  j
 | d 9<| d c | j
 | | 9<qWx= t d |  j | |  D]! } | d c |  j
 | | 9<qWx> t d | j | |  D]" } | d c | j
 | d 9<qHW| r| j d |  j
 d  | j d | j
 d  n  |  j |  } | j |  } | | |  } | j |
 |  } t | |  Sg  | D] } t |  ^ q} t | d  t | d  k r?t d	   n  xt d |  f d | f f  D] \ } \ } } t | |  | j k rt d
 | | | | j t | |  f   n  t | |  d k r%t j | |  | j k r%t d | | | | j t j t j | |   f   n  | r^d | | k r^t d | | | f   q^q^W| rkd g n g  } g  t |  | f  D]J \ } } g  t | j  D]( } | | | k r| | k r| ^ q^ q} |  j | | d | d  } | j | | d | d  } t | | t | d  d | d | Sd S(   s  
    Reduces a tensor dot product to a matrix or vector dot product. Based
    on code from Tijmen Tieleman's gnumpy
    (http://www.cs.toronto.edu/~tijmen/gnumpy.html).

    Please see the documentation of tensordot for the meaning of the a, b
    and axes arguments.

    :param dot: a function that accepts two symbolic variables and computes
                the appropriate dot product (e.g. dot, batched_dot)
    :type dot: function

    :param batched: whether to treat the first axis of a and b as a batch
                    axis.  If so, this axis will be preserved in the output,
                    allowing this function to be used also for batched
                    tensor dot products.
    :type batched: boolean

    :returns: a tensor with shape equal to the concatenation of a's shape
              (less any dimensions that were summed over) and b's shape
              (less the first dimension and any dimensions that were summed
              over).
    :rtype: symbolic tensor
    i   sD   Axes should be an integer or a list/tuple of len 2 (%s was provided)R-   R.   sE   axes can not be larger than the dimension of %s (%s.ndim=%i, axes=%i)sL   axes to sum over must not include the batch axis of %s (%s.ndim=%i, axes=%i)i   i    s(   Axes elements must have the same length.sg   axes[%i] should be array_like with length less than the dimensions of %s (%s.ndim=%i, len(axes[0])=%i).s\   axes[%i] contains dimensions greater than or equal to %s.ndim (%s.ndim=%i, max(axes[0])=%i).s>   axes to sum over must not contain the batch axis (axes[%i]=%s)RY  RZ  N(   Re   R*   t   isscalarRM   RO   R_   R   RH   Rh  R1  R   RT   R   R  R3  R  R   R-  R   R   RU   R[  (   R-   R.   R6  RY  RZ  t   operand_namet   operandt
   batch_axest	   a_outaxest	   b_outaxest   outshapet   outbcastt   outndimt   a_shapet   b_shapeR   t
   a_reshapedt
   b_reshapedt   out_reshapedR  t   axes_R7   t
   other_axest
   a_shuffledt
   b_shuffled(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR[  V  s    "%  !!  "2&`c         C` s   t  |  | | d t d t S(   s  
    Compute a generalized dot product over provided axes.

    Given two tensors a and b, tensordot computes a generalized dot product over
    the provided axes. Theano's implementation reduces all expressions to
    matrix or vector dot products and is based on code from Tijmen Tieleman's
    gnumpy (http://www.cs.toronto.edu/~tijmen/gnumpy.html).

    Parameters
    ----------
    a: symbolic tensor
        The first tensor variable.
    b: symbolic tensor
        The second tensor variable
    axes: int or array-like of length 2
        If an integer, the number of axes to sum over.
        If an array, it must have two array elements containing the axes
        to sum over in each tensor.

        Note that the default value of 2 is not guaranteed to work
        for all values of a and b, and an error will be raised if
        that is the case. The reason for keeping the default is to
        maintain the same signature as numpy's tensordot function
        (and np.tensordot raises analogous errors for non-compatible
        inputs).

        If an integer i, it is converted to an array containing
        the last i dimensions of the first tensor and the first
        i dimensions of the second tensor:
            axes = [list(range(a.ndim - i, b.ndim)), list(range(i))]

        If an array, its two elements must contain compatible axes
        of the two tensors. For example, [[1, 2], [2, 0]] means sum
        over the 2nd and 3rd axes of a and the 3rd and 1st axes of b.
        (Remember axes are zero-indexed!) The 2nd axis of a and the
        3rd axis of b must have the same shape; the same is true for
        the 3rd axis of a and the 1st axis of b.

    Returns
    -------
    symbolic tensor
        A tensor with shape equal to the concatenation of a's shape
        (less any dimensions that were summed over) and b's shape
        (less any dimensions that were summed over).

    Examples
    --------
    It may be helpful to consider an example to see what tensordot does.
    Theano's implementation is identical to NumPy's. Here a has shape (2, 3, 4)
    and b has shape (5, 6, 4, 3). The axes to sum over are [[1, 2], [3, 2]] --
    note that a.shape[1] == b.shape[3] and a.shape[2] == b.shape[2]; these axes
    are compatible. The resulting tensor will have shape (2, 5, 6) -- the
    dimensions that are not being summed:

    >>> a = np.random.random((2,3,4))
    >>> b = np.random.random((5,6,4,3))

    #tensordot
    >>> c = np.tensordot(a, b, [[1,2],[3,2]])

    #loop replicating tensordot
    >>> a0, a1, a2 = a.shape
    >>> b0, b1, _, _ = b.shape
    >>> cloop = np.zeros((a0,b0,b1))

    #loop over non-summed indices -- these exist
    #in the tensor product.
    >>> for i in range(a0):
    ...     for j in range(b0):
    ...         for k in range(b1):
    ...             #loop over summed indices -- these don't exist
    ...             #in the tensor product.
    ...             for l in range(a1):
    ...                 for m in range(a2):
    ...                     cloop[i,j,k] += a[i,l,m] * b[j,k,m,l]

    >>> np.allclose(c, cloop)
    true

    This specific implementation avoids a loop by transposing a and b such that
    the summed axes of a are last and the summed axes of b are first. The
    resulting arrays are reshaped to 2 dimensions (or left as vectors, if
    appropriate) and a matrix or vector dot product is taken. The result is
    reshaped back to the required output dimensions.

    In an extreme case, no axes may be specified. The resulting tensor
    will have shape equal to the concatenation of the shapes of a and b:

    >>> c = np.tensordot(a, b, 0)
    >>> print(a.shape)
    (2,3,4)
    >>> print(b.shape)
    (5,6,4,3)
    >>> print(c.shape)
    (2,3,4,5,6,4,3)

    See the documentation of numpy.tensordot for more examples.

    RY  RZ  (   R[  RY  R|   (   R-   R.   R6  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR5    s    dc         C` sa   |  j  d k r |  j   }  n  | j  d k r< | j   } n  t |  j d d  | j d d   S(   s_   Return vector-vector outer product.

    If an input isn't a vector, we flatten it first.

    i   i    R7   (   RH   R  RY  RU   (   R7   R8   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  8  s    c         C` s4   t  j |  |   } | r0 t |  | |  } n  | S(   N(   R   t   AnyR]  (   R7   R'  R^  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   anyG  s    c         C` s4   t  j |  |   } | r0 t |  | |  } n  | S(   N(   R   t   AllR]  (   R7   R'  R^  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR+   O  s    t   ExtractDiagc           B` sM   e  Z d  Z d Z d d d e d  Z d   Z d	   Z d
   Z d   Z	 RS(   s   Return specified diagonals.

    Parameters
    ----------
    x
        A tensor variable with x.ndim >= 2.

    Returns
    -------
    vector
        A vector representing the diagonal elements.

    R  t   axis1t   axis2R  i    i   c         C` sz   | |  _  |  j  r< t r< t j d t j j  t |  _  n  |  j  r[ i d g d 6|  _ n  | |  _ | |  _	 | |  _
 d  S(   Ns   View will forced to False. ExtractDiag property view is set to True but numpy version %s and prior versions of numpy.diagonal() do not return a view. Update numpy to use ExtractDiag(view=True)i    (   R  t   numpy_diagonal_return_viewR  R  R*   t   versionR|   R8  R  RM  RN  (   R   R  RM  RN  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR(  m  s    					c      
   C` sl   t  |  } | j d k  r- t d |   n  t |  | g | j j d | j d t g | j d    g  S(   Ni   s4   ExtractDiag needs an input with 2 or more dimensionsR1   RT   i   (   Re   RH   RO   R	   RP   R   R1   R|   (   R   R7   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   |  s    	c         C` sX   | \ } | \ } | j  |  j |  j |  j  | d <|  j sT | d j   | d <n  d  S(   Ni    (   t   diagonalR  RM  RN  R  Ri   (   R   R  R   RN   R7   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s
    		"	c         C` s%   | \ } | \ } t  |  d |  g S(   Ni    (   R    (   R   R   t   goutR7   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    		c         C` s   | \ } | |  j  } | |  j } g  t |  D]* \ } } | |  j  |  j f k r0 | ^ q0 } |  j }	 |	 d k r t | |	 d |  }
 n4 |	 d k  r t | |	 d |  }
 n t | |  }
 | j |
  t |  g S(   Ni    (   RM  RN  R-  R  RJ  R9  R;   RY   (   R   R  R?  t   in_shapet   dim1t   dim2R   Rl   R  R  t	   diag_size(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    	$	(   s   offsets   axis1s   axis2s   view(
   R'   R(   R)   R  R|   R(  R   R   R  R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRL  ]  s   	
		c         C` s>   | | | f d k r( t  j j j |   St | | |  |   S(   Ni    i   (   i    i    i   (   R   R   t   nlinalgt   extract_diagRL  (   R-   R  RM  RN  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRQ    s    t   Diagc           B` s2   e  Z d Z d    Z d   Z d   Z d   Z RS(   c         C` sU   t  |  } | j j d k r3 t d | j   n  t |  | g t d | j  g  S(   Ni   s   data argument must be a vectorR1   (   Re   RP   RH   R\   R	   R   R1   (   R   t   diag(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s    c         C` s$   | \ } t  j | d  | d <d  S(   Ni    (   R*   RZ  (   R   R  R   RN   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s    	c         C` s   | \ } t  |  g S(   N(   RQ  (   R   R   RR  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    	c         C` s   | d d f d g S(   Ni    i   (    (   R   t   nodesR?  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    (    (   R'   R(   R  R   R   R  R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRY    s
   			c         C` s`   |  j  d k r4 | d k s' t d   t   |   S|  j  d k rP t |  |  St d   d  S(   Ni   i    s-   diagonals other than main are not implementedi   s   Input must be 1- or 2-d.(   RH   Rh   RY  RQ  RO   (   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRZ    s    c         C` s6   t  |  t t f  r. t t t t |     S|  Sd S(   s!  
    Recursively stack lists of tensors to maintain similar structure.

    This function can create a tensor from a shaped list of scalars:

    Examples
    --------
    >>> from theano.tensor import stacklists, scalars, matrices
    >>> from theano import function
    >>> a, b, c, d = scalars('abcd')
    >>> X = stacklists([[a, b], [c, d]])
    >>> f = function([a, b, c, d], X)
    >>> f(1, 2, 3, 4)
    array([[ 1.,  2.],
           [ 3.,  4.]], dtype=float32)

    We can also stack arbitrarily shaped tensors. Here we stack matrices into
    a 2 by 2 grid:

    >>> from numpy import ones
    >>> a, b, c, d = matrices('abcd')
    >>> X = stacklists([[a, b], [c, d]])
    >>> f = function([a, b, c, d], X)
    >>> x = ones((4, 4), 'float32')
    >>> f(x, x, x, x).shape
    (2, 2, 4, 4)

    N(   R/   RY   RV   R[   R  t
   stacklists(   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR\    s    c         C` s,   t  |   }  t |  |  t |  |  } | S(   s^  
    Range of values (maximum - minimum) along an axis.

    The name of the function comes from the acronym for peak to peak.

    Parameters
    ----------
    a
        Input tensor.
    axis
        Axis along which to find the peaks. By default, flatten the array.

    Returns
    -------
    array
        A new array holding the result.

    (   Re   R   Rc  (   R-   R'  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   ptp  s    c         C` s   |  | S(   N(    (   R7   R8   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   power	  s    c         C` sT   t  |   }  |  j } t t d |   } | | | | | | <| | <|  j |  S(   s   swap axes of inputted tensori    (   Re   RH   RV   RW   RU   (   R8   RM  RN  RH   t   li(    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   swapaxes  s
    	t   raisec         C` s%   | d k s t  t |  |  |  S(   s
  
    Construct an array from an index array and a set of arrays to choose from.

    First of all, if confused or uncertain, definitely look at the Examples -
    in its full generality, this function is less simple than it might seem
    from the following code description (below ndi = numpy.lib.index_tricks):

    np.choose(a,c) == np.array([c[a[I]][I] for I in ndi.ndindex(a.shape)]).

    But this omits some subtleties. Here is a fully general summary:

    Given an ``index`` array (a) of integers and a sequence of n arrays
    (choices), a and each choice array are first broadcast, as necessary,
    to arrays of a common shape; calling these Ba and
    Bchoices[i], i = 0,...,n-1 we have that, necessarily,
    Ba.shape == Bchoices[i].shape for each i.
    Then, a new array with shape Ba.shape is created as follows:

    - if mode=raise (the default), then, first of all, each element of a
      (and thus Ba) must be in the range [0, n-1]; now, suppose that
      i (in that range) is the value at the (j0, j1, ..., jm) position in Ba -
      then the value at the same position in the new array is the value in
      Bchoices[i] at that same position;

    - if mode=wrap, values in a (and thus Ba) may be any (signed) integer;
      modular arithmetic is used to map integers outside the range [0, n-1]
      back into that range; and then the new array is constructed as above;

    - if mode=clip, values in a (and thus Ba) may be any (signed) integer;
      negative integers are mapped to 0; values greater than n-1 are mapped
      to n-1; and then the new array is constructed as above.

    Parameters
    ----------
    a : int array
        This array must contain integers in [0, n-1], where n is the number of
        choices, unless mode=wrap or mode=clip, in which cases any integers
        are permissible.
    choices : sequence of arrays
        Choice arrays. a and all of the choices must be broadcastable to
        the same shape. If choices is itself an array (not recommended),
        then its outermost dimension (i.e., the one corresponding to
        choices.shape[0]) is taken as defining the ``sequence``.
    out : array, optional
        If provided, the result will be inserted into this array.
        It should be of the appropriate shape and dtype.
    mode : {``raise`` (default), ``wrap``, ``clip``}, optional
        Specifies how indices outside [0, n-1] will be treated:
        ``raise`` : an exception is raised
        ``wrap`` : value becomes value mod n
        ``clip`` : values < 0 are mapped to 0, values > n-1 are mapped to n-1

    Returns
    -------
    merged_array - array
        The merged result.

    Raises
    ------
    ValueError - shape mismatch
        If a and each choice array are not all broadcastable to the same shape.

    N(   RL   Rh   t   Choose(   R-   t   choicesR  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   choose  s    ARb  c           B` s2   e  Z d Z d   Z d   Z d   Z d   Z RS(   R  c         C` s   | d k s t   | |  _ d  S(   NRa  t   wrapRJ  (   s   raises   wraps   clip(   Rh   R  (   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR(  ^  s    c   
      C` s  t  | j d t  r g  } x\ t | d | d d | j d j  D]2 \ } } } | rj | j |  qE | j |  qE Wt |  g Sd d  l } t  | j d | j j	  s t
  t d   | d } x4 t t | d  d  D] }	 | d |	 | |	 <q W| g Sd  S(   Ni   i    s   Case not implemented(   R/   R   R   R   RT   R;   RY   t   theano.typed_listt
   typed_listt   TypedListVariableRh   R&   R   RM   (
   R   R  R?  R   t   sh1t   sh2R   R   R   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR  b  s"     
!c         C` s  d d  l  } t |  } | j | j j k rC t d | j   n  t | t t | j	 j
 f  r | j	 j |  } | j j } | j j } n& t |  } | j d } | j d } t j | j | g  } t | | | j  } t |  | k rbt | j t  rS| j d d | | t t d | j    } | j d } | j d } qbt d   n  t g | } xT t t | j t f | | |   D]+ \ }	 \ }
 } |
 r| rt | |	 <qqWt | j |  } t |  | | g |   g  S(   Ni    s9   choose first argument must have an [u]int* dtype. Got %s.i   R7   s   We currently didn't implemented that case. To make it work, explicitly add dimensions of size one for dimensions that will be broadcasted(   R7   (   Rf  Re   R1   R   R  R\   R/   RY   RV   Rg  Rh  t	   make_listt   ttypeRH   RT   R*   R   RX   RM   RP   R   RU   RW   R
  R|   R-  R   Rg   R	   (   R   R-   Rc  R   t   choicet   choice_ndimt   choice_bcastt   out_ndimR  Rb   R   R   Rw  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR   z  sB    		+c         C` s@   | \ } | d } | d } t  j | | d |  j | d <d  S(   Ni    i   R  (   R*   Rd  R  (   R   R  R   RN   R  R-   Rm  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s    	

(   s   mode(   R'   R(   R  R(  R  R   R   (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRb  [  s
   			-t
   AllocEmptyc           B` sw   e  Z d  Z d Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z RS(   s<   Implement Alloc on the cpu, but without initializing memory.R1   c         C` s.   t  | t  s t |   | j   |  _ d  S(   N(   R/   R_   Rh   R  R1   (   R   R1   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR(    s    c         G` sj   t  |  \ } } t d |  j d |  } |   } t | j _ t | j _ t | j _	 t
 |  | | g  S(   NR1   RT   (   R  R   R1   R   RA   t   values_eq_approxR|   RP   t   filter_checks_isfinitet   nan_guard_mode_checkR	   (   R   R   R  R  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s    	c         C` s,   |  j  | | |  | d d j d  d  S(   Ni    i2(   R   R  (   R   R  R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   debug_perform  s    c         C` st   | \ } t  g  | D] } t |  ^ q  } | d d  k sQ | d j | k rp t j | d |  j | d <n  d  S(   Ni    R1   (   RY   R   RL   R   R*   R  R1   (   R   R  R   R  R  R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR     s    	%#c         C` s   d |  j  j   } | \ } | d } | }	 t |	  }
 d t   } x+ t |	  D] \ } } | d t   7} qR W| d t   7} x+ t |	  D] \ } } | d t   7} q W| d t   7} | S(   Nt   NPY_R  s   npy_intp dims[%(nd)s];
sF   dims[%(idx)s] =((npy_intp)((dtype_%(sh)s*) PyArray_DATA(%(sh)s))[0]);
s   if(%(out)s==NULL
s/   ||PyArray_DIMS(%(out)s)[%(idx)s]!=dims[%(idx)s]sY  ){
            /* Reference received to invalid output variable.
            Decrease received reference's ref count and allocate new
            output variable */
            Py_XDECREF(%(out)s);
            %(out)s = (PyArrayObject*)PyArray_EMPTY(%(nd)s,
                                                    dims,
                                                    %(dtype)s,
                                                    0);
            if (!%(out)s)
            {
                PyErr_SetString(PyExc_MemoryError, "alloc failed");
                %(fail)s;
            }
        }
        (   R1   t   upperRM   R  R-  (   R   R  RG   R   R  R  R1   R  R  t   shpst   ndR_   Rb   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    	
c         C` s
   | j  g S(   N(   R   (   R   R  R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    c         C` s   d S(   Ni   (   i   (    (   R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    c         C` s   t  S(   N(   R|   (   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    c         C` s   g  | j  D] } t g ^ q
 S(   N(   R   R|   (   R   R  R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    c         C` s   g  | D] } t      ^ q S(   N(   R!   (   R   R   R  R   (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    c         C` s   t  | |  j  g S(   N(   R  R1   (   R   R   R  (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyR    s    (   s   dtype(   R'   R(   R)   R  R(  R   Ru  R   R  R  R  R  R  R  R  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyRq    s   					#					(  R)   t
   __future__R    R   R   t	   six.movesR   Rf  R  R*   t   sixR   R   R  R   t   theano.compatR   t   theano.configparserR   R   t
   theano.gofR	   R
   R   R   t   theano.gof.typeR   t   theano.tensorR   t   theano.tensor.varR   R   R   R   t   theano.tensor.typeR   R   t   theano.tensor.type_otherR   R   RQ   t	   functoolsR   R   R   t   theano.printingR   R   t   theano.compileR   R   R   t   theano.scalar.sharedvart   theano.gradientR   R    R!   t   theano.tensor.elemwiseR"   R#   R$   R%   t   loggingt	   getLoggert   _loggert   __docformat__R   R  RJ  RZ   R+   R5   RV   R  R_   t   complex_typesRE  t   continuous_typest   continuous_dtypest   float_typesRw   RS  t   discrete_typesR  t	   all_typest
   all_dtypesRd  Ru   t
   uint_typesRv   R`   R&   R9   t   register_checkerR:   R=   RC   RL   Re   R+  t	   as_tensorRo   R^   Rg   Rp   Rr   R}   R   R   t
   cmp_sloppyR   R   R   R   R   R   R   R   R   R   R   t   Castt   Switcht   NEQt   EQt   LTt   GTt   LEt   GEt   Subt   AddRF  t   Mult   IntDivt   TrueDivt   Minimumt   MaximumR   R|   R   R   t   cscalart   zscalart   fscalart   dscalart   bscalart   wscalart   iscalart   lscalart   scalarst   fscalarst   dscalarst   iscalarst   lscalarst   int_scalar_typest   float_scalar_typest   complex_scalar_typest   cvectort   zvectort   fvectort   dvectort   bvectort   wvectort   ivectort   lvectorR   t   vectorst   fvectorst   dvectorst   ivectorst   lvectorsRc  t   float_vector_typest   complex_vector_typest   cmatrixt   zmatrixt   fmatrixt   dmatrixt   bmatrixt   wmatrixt   imatrixt   lmatrixR   t   matricest	   fmatricest	   dmatricest	   imatricest	   lmatricest   int_matrix_typest   float_matrix_typest   complex_matrix_typest   crowt   zrowt   frowt   drowt   browt   wrowt   irowt   lrowR   t   rowst   frowst   drowst   irowst   lrowst   ccolt   zcolt   fcolt   dcolt   bcolt   wcolt   icolt   lcolR   t   colst   fcolst   dcolst   icolst   lcolst   ctensor3t   ztensor3t   ftensor3t   dtensor3t   btensor3t   wtensor3t   itensor3t   ltensor3R   t   tensor3st	   ftensor3st	   dtensor3st	   itensor3st	   ltensor3st   ctensor4t   ztensor4t   ftensor4t   dtensor4t   btensor4t   wtensor4t   itensor4t   ltensor4R   t   tensor4st	   ftensor4st	   dtensor4st	   itensor4st	   ltensor4st   ctensor5t   ztensor5t   ftensor5t   dtensor5t   btensor5t   wtensor5t   itensor5t   ltensor5R   t   tensor5st	   ftensor5st	   dtensor5st	   itensor5st	   ltensor5st   TensorR   t   _scal_elemwiseR   R   RS   R   R  R  t   convert_to_boolt   _convert_to_boolt   convert_to_int8t   _convert_to_int8t   convert_to_int16t   _convert_to_int16t   convert_to_int32t   _convert_to_int32t   convert_to_int64t   _convert_to_int64t   convert_to_uint8t   _convert_to_uint8t   convert_to_uint16t   _convert_to_uint16t   convert_to_uint32t   _convert_to_uint32t   convert_to_uint64t   _convert_to_uint64t   convert_to_float16t   _convert_to_float16t   convert_to_float32t   _convert_to_float32t   convert_to_float64t   _convert_to_float64t   convert_to_complex64t   _convert_to_complex64t   convert_to_complex128t   _convert_to_complex128R#  R%  R&  RR  t   _argmaxR]  R`  R   R*  Rc  Rd  Rf  Rg  Rh  Ri  Rj  Rk  RD  Rl  Rm  Ro  Rp  Rq  R   Rr  Re  t   whereR  Ru  R  Rt  R  t   bitwise_xorR  Rv  R  R   t   PatternPrinterR  R  R  R  R  R  R  R  R  Rw  R  R  R  R  R  R  R  R  t   squareR  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  t   propertyR  R  R  R  R  R  R   R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R   Rn  R  R  R  t   identityt   tensor_copyt   IgnorePrinterR  R2  R"  R(  R   R5  R6  R7  t
   setdefaultRa  R9  R<  R?  R#  R  RA  R+  R;  R=  RD  R>  RH  RI  RJ  t   OperatorPrinterRU  R0  RX  RV  R`  R\  R  R  R  R   R  R$  R  RX   R  R  R[   R1  R   R  R  R  R3  R  R  R  R  R  R  R  R@  t   objectR  t   mgridt   ogridR  R  R  R  R  R6  t   specialRY  R[  R5  R  R7   R  RQ  RO  RL  RY  RZ  R\  R]  R^  R`  Rd  Rb  Rq  (    (    (    s3   /tmp/pip-build-X4mzal/theano/theano/tensor/basic.pyt   <module>   s  """			\'									$$$''$$$					-	#	)		
		%9*				"n	5	,		&!"						+]L(					
	'' 			  9		5%f	K=KNT0G					3	{g		G
	#			ET