代码说明:
import theano
import theano.tensor as T
print 'theano.scan_module.until:'
class GRU:
def __init__(self,word_dim):
self.word_dim = word_dim
self.theano = {}
self.__Thea_build__()
def __Thea_build__(self):
def prod_2(pre_value, max_value):
print "what-what"
return pre_value*2, theano.scan_module.until(pre_value*2 > max_value)
max_value = T.iscalar('max_value')
result, update = theano.scan(prod_2, outputs_info=T.constant(1.),
non_sequences=[max_value], n_steps=100)
self.prod_fn = theano.function([max_value], result, updates=update)
mode = GRU(3)
print "-----------------------------"
for i in range(100,500,100):
print mode.prod_fn(i)
执行前需要先编译一下
输出:[@104_27 theano_test]$ python theano_function.py
Using gpu device 0
theano.scan_module.until:
what-what
-----------------------------
[ 2. 4. 8. 16. 32. 64. 128.]
[ 2. 4. 8. 16. 32. 64. 128. 256.]
[ 2. 4. 8. 16. 32. 64. 128. 256. 512.]
[ 2. 4. 8. 16. 32. 64. 128. 256. 512.]