提交 19233856 authored 作者: Razvan Pascanu's avatar Razvan Pascanu

New interface for scan

Is suppose to give a lot more control to the user, making it possible to avoid some graphs that are hard to optimize, or which do not get optimized properly. It is also suppose to generate much cleaner and small graphs.
上级 927ac9a4
差异被折叠。
import theano
import numpy
import scan
def test_001():
x0 = theano.tensor.fvector('x0')
state = theano.tensor.unbroadcast(
theano.tensor.shape_padleft(x0), 0)
out, _ = scan.scan(lambda x:x+numpy.float32(1),
states = state,
n_steps = 5)
fn = theano.function([x0], out[0])
val_x0 = numpy.float32([1,2,3])
assert numpy.all(fn(val_x0) == val_x0 +5)
def test_002():
x0 = theano.tensor.fvector('x0')
state = theano.tensor.alloc(
theano.tensor.constant(numpy.float32(0)),
6,
x0.shape[0])
state = theano.tensor.set_subtensor(state[0], x0)
out, _ = scan.scan(lambda x:x+numpy.float32(1),
states = state,
n_steps = 5)
fn = theano.function([x0], out)
val_x0 = numpy.float32([1,2,3])
assert numpy.all(fn(val_x0)[-1] == val_x0 +5)
assert numpy.all(fn(val_x0)[0] == val_x0)
if __name__=='__main__':
test_001()
test_002()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论