Ah, great, thanks guys. I get what you mean by the ifelse now.
Here is a full example with the solution:
import numpy as np
import theano.tensor as T
import theano
from theano.ifelse import ifelse
floatX = theano.config.floatX
def temp_diff(x):
last = theano.shared(np.zeros((0, )*x.ndim, dtype=floatX))
updates = [(last, x)]
return ifelse(last.size>0, x-last, x), updates
x = T.matrix()
out, updates = temp_diff(x)
f = theano.function([x], out, updates=updates)
print f(np.ones((3,4), dtype=floatX)*5) # returns a 3x4 matrix of 5's
print f(np.ones((3,4), dtype=floatX)*3) # returns a 3x4 matrix of -2's
print f(np.ones((3,4), dtype=floatX)*6) # returns a 3x4 matrix of 3's
--
---
You received this message because you are subscribed to the Google Groups
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.