Reputation: 3459
If I had something like:
import theano.tensor as T
from theano import function
a = T.dscalar('a')
b = T.dscalar('b')
first_func = a * b
second_func = a - b
first = function([a, b], first_func)
second = function([a, b], second_func)
and I wanted to create a third function that was first_func(1,2) + second_func(3,4)
, is there a way to do this and create a function that is passed these two smaller functions as input?
I want to do something like:
third_func = first(a, b) + second(a,b)
third = function([a, b], third_func)
but this does not work. What is the correct way to break my functions into smaller functions?
Upvotes: 0
Views: 31
Reputation: 1201
I guess the only way to decompose function is in-terms of tensor variables, rather than function calls. This should work:
import theano.tensor as T
from theano import function
a = T.dscalar('a')
b = T.dscalar('b')
first_func = a * b
second_func = a - b
first = function([a, b], first_func)
second = function([a, b], second_func)
third_func = first_func + second_func
third = function([a, b], third_func)
third_func = first(a, b) + second(a,b)
does not work because function call need real values whereas a
and b
are tensor/symbolic variables. Basically one should define mathematical operations with tensors and then use function to evaluate values of these tensors.
Upvotes: 1