提交 d047b81a authored 作者: Jeremiah Lowin's avatar Jeremiah Lowin

add test for Jacobian disconnected inputs

上级 1ef58767
......@@ -142,3 +142,25 @@ def test004_hessian():
f = theano.function([x], Hx)
vx = numpy.arange(10).astype(theano.config.floatX)
assert numpy.allclose(f(vx), numpy.eye(10) * 2)
def test_jacobian_disconnected_inputs():
"""
Test that disconnected inputs are properly handled by jacobian.
"""
v1 = tensor.vector()
v2 = tensor.vector()
jacobian_v = theano.gradient.jacobian(1 + v1, v2,
disconnected_inputs='ignore')
func_v = theano.function([v1, v2], jacobian_v)
val = np.arange(4.0).astype(theano.config.floatX)
assert np.allclose(func_v(val, val), np.zeros((4, 4)))
s1 = tensor.scalar()
s2 = tensor.scalar()
jacobian_s = theano.gradient.jacobian(1 + s1, s2,
disconnected_inputs='ignore')
func_s = theano.function([s2], jacobian_s)
val = np.array(1.0).astype(theano.config.floatX)
assert np.allclose(func_s(val), np.zeros(1))
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论