提交 742b27bb authored 作者: Ian Goodfellow's avatar Ian Goodfellow

added unit test to make sure connection pattern of shape and alloc work

right
上级 2c2ce0d2
......@@ -293,6 +293,28 @@ def test_grad_grad_cubic():
theano.tests.unittest_tools.verify_grad(output,[vx,vA])
def test_grad_disconnected():
#tests corner cases of gradient for shape and alloc
x = theano.tensor.vector(name = 'x')
total = x.sum()
total.name = 'total'
num_elements = x.shape[0]
num_elements.name = 'num_elements'
silly_vector = theano.tensor.alloc( total / num_elements, num_elements)
silly_vector.name = 'silly_vector'
cost = silly_vector.sum()
cost.name = 'cost'
#note that cost simplifies to be the same as "total"
g = gradient.grad(cost, x, add_names = False)
#we still need to pass in x because it determines the shape of the output
f = theano.function([x],g)
rng = np.random.RandomState([2012,9,5])
x = np.cast[x.dtype](rng.randn(3))
g = f(x)
assert np.allclose(g,np.ones(x.shape,dtype=x.dtype))
if __name__ == '__main__':
unittest.main()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论