I have an Anano function that is called several times, each time with different shared variables. The way it is currently implemented, the Theano function becomes overridden each time it starts. I suppose this makes the whole program slow, because every time the Theano functions are detected, the graph is restored.
def sumprod_shared(T_shared_array1, T_shared_array2): f = theano.function([], (T_shared_array1 * T_shared_array2).sum(axis=0)) return f() for factor in range(10): m1 = theano.shared(factor * array([[1, 2, 4], [5, 6, 7]])) m2 = theano.shared(factor * array([[1, 2, 4], [5, 6, 7]])) print sumprod_shared(m1, m2)
For non-general (normal) variables, I can define a function once, and then call it with different variables without redefinition.
def sumprod_init(): T_matrix1 = T.lmatrix('T_matrix1') T_matrix2 = T.lmatrix('T_matrix2') return theano.function([T_matrix1, T_matrix2], (T_matrix1 * T_matrix2).sum(axis=0)) sumprod = sumprod_init() for factor in range(10): np_array1 = factor * array([[1, 2, 4], [5, 6, 7]]) np_array2 = factor * array([[1, 2, 4], [5, 6, 7]]) print sumprod(np_array1, np_array2)
Is this also possible for shared variables?