Platforms: Unix, Windows
This module provides function(), commonly accessed as theano.function, the interface for compiling graphs into callable objects.
You’ve already seen example usage in the basic tutorial... something like this:
>>> x = theano.tensor.dscalar()
>>> f = theano.function([x], 2*x)
>>> print f(4) # prints 8.0
The idea here is that we’ve compiled the symbolic graph (2*x) into a function that can be called on a number and will do some computations.
The behaviour of function can be controlled in several ways, such as Param, mode, updates, and givens. These are covered in the tutorial examples and tutorial on modes.
A class for attaching information to function outputs
A class for attaching information to function inputs.
Return a callable object that will calculate outputs from inputs.
| Parameters: |
|
|---|---|
| Return type: | Function instance |
| Returns: | a callable object that will compute the outputs (given the inputs) and update the implicit function arguments according to the updates. |
Inputs can be given as variables or Param instances. Param instances also have a variable, but they attach some extra information about how call-time arguments corresponding to that variable should be used. Similarly, Out instances can attach information about how output variables should be returned.
The default is typically ‘FAST_RUN’ but this can be changed in theano.config. The mode argument controls the sort of optimizations that will be applied to the graph, and the way the optimized graph will be evaluated.
After each function evaluation, the updates mechanism can replace the value of any SharedVariable [implicit] inputs with new values computed from the expressions in the updates list. An exception will be raised if you give two update expressions for the same SharedVariable input (that doesn’t make sense).
If a SharedVariable is not given an update expression, but has a default_update member containing an expression, this expression will be used as the update expression for this variable. Passing no_default_updates=True to function disables this behavior entirely, passing no_default_updates=[sharedvar1, sharedvar2] disables it for the mentionned variables.
Regarding givens: Be careful to make sure that these substitutions are independent–behaviour when Var1 of one pair appears in the graph leading to Var2 in another expression is undefined. Replacements specified with givens are different from optimizations in that Var2 is not expected to be equivalent to Var1.