提交 c71ac8ac authored 作者: --global's avatar --global

Add tests case for modification

上级 0c0dadac
...@@ -3029,6 +3029,43 @@ class T_Scan(unittest.TestCase): ...@@ -3029,6 +3029,43 @@ class T_Scan(unittest.TestCase):
sol[:, :] = v_out sol[:, :] = v_out
utt.assert_allclose(sol, f(v_h, v_W1, v_W2)) utt.assert_allclose(sol, f(v_h, v_W1, v_W2))
def test_pushout_while(self):
# Ensure that the optimizations for Scan that push computation out of
# the Scan don't alter the result for 'as_while' scans.
W1 = tensor.matrix('W1')
W2 = tensor.matrix('W2')
step_indices = tensor.vector('step_indices')
def lambda_fn(step_idx, W1, W2):
until_condition = theano.scan_module.until(step_idx > 2)
return tensor.dot(W1, W2), until_condition
# Compile a function with the optimization
o, _ = theano.scan(lambda_fn,
sequences=[step_indices, W1],
non_sequences=[W2],
n_steps=5)
f = theano.function([W1, W2, step_indices], o, mode=mode_with_opt)
# Compule an theano function without the optimization
o, _ = theano.scan(lambda_fn,
sequences=[step_indices, W1],
non_sequences=[W2],
n_steps=5, mode='FAST_COMPILE')
f_ref = theano.function([W1, W2, step_indices], o, mode='FAST_COMPILE')
# Compare the results of the two implementations
input_values = [numpy.random.random((5, 5)),
numpy.random.random((5, 5)),
numpy.arange(5)]
out = f(*input_values)
out_ref = f_ref(*input_values)
utt.assert_allclose(out, out_ref)
def test_pushout(self): def test_pushout(self):
W1 = tensor.matrix('W1') W1 = tensor.matrix('W1')
W2 = tensor.matrix('W2') W2 = tensor.matrix('W2')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论