Theano provides a function to print a graph before and after compilation:
>>> x = T.dscalar('x')
>>> y = x**2
>>> gy = T.grad(y, x)
>>> pp(gy) # print out the gradient prior to optimization
'((fill((x ** 2), 1.0) * 2) * (x ** (2 - 1)))'
>>> f = function([x], gy)
>>> pp(f.maker.env.outputs[0])
'(2.0 * x)'
The parameter in T.dscalar('x') in the first line is the name of this variable(in the graph, not in python). This name is reused when printing the graph. Otherwise the variable x is printed as its type as: <TensorType(float64, scalar)>. That is not the most comprehensible. The string 'x' can be any string, but to make the code more comprehensible, try to pass the same name or derivative of the name in python.
The function I compiled is too slow, what's up?
The function I compiled is too slow, what's up?
-----------------------------------------------
-----------------------------------------------
First, make sure you're running in FAST_RUN mode, by passing ``mode='FAST_RUN'``
First, make sure you're running in FAST_RUN mode, by passing
to ``theano.function`` or ``theano.make`` or by setting to ``PROFILE_MODE``
``mode='FAST_RUN'`` to ``theano.function`` or ``theano.make``. Some
the flags :attr:`config.mode`. Some
operations have excruciatingly slow Python implementations and that
operations have excruciatingly slow Python implementations and that
can negatively effect the performance of FAST_COMPILE.
can negatively effect the performance of FAST_COMPILE.
raiseValueError('Shape mismatch: "out" should have shape starting with %s (plus %i extra dimensions), but the value produced by "perform" has shape %s'\
%(shape,self.ndim_added,rval.shape))
out[0]=rval
defgrad(self,inputs,outputs):
defgrad(self,inputs,outputs):
return[Noneforiininputs]
return[Noneforiininputs]
def_infer_ndim(ndim,shape):
def_infer_ndim(ndim,shape,*args):
"""returns int, variable pair, such that the int is the length of the variable, and the
"""
variable is an integer or uint vector
Infer the number of dimensions from the shape or the other arguments.
:rtype: (int, variable) pair, where the variable is an integer vector.
:returns: the first element returned is the inferred number of dimensions.
The second element's length is either the first element, or 0
(if the original shape was None).
In the special case where the shape argument is None, the variable
returned has a length of 0, meaning that the shape will be computed
at runtime from the shape of the other args.
"""
"""
# Find the minimum value of ndim required by the *args