提交 04b75c28 authored 作者: Frederic's avatar Frederic

Fix buildbot failure in debugmode. Theano don't accept None for Tensor.

上级 99014933
...@@ -1119,11 +1119,22 @@ class Eigvalsh(Op): ...@@ -1119,11 +1119,22 @@ class Eigvalsh(Op):
def make_node(self, a, b): def make_node(self, a, b):
assert imported_scipy, ( assert imported_scipy, (
"Scipy not available. Scipy is needed for the Eigvalsh op") "Scipy not available. Scipy is needed for the Eigvalsh op")
a, b = map(as_tensor_variable, (a, b)) a = as_tensor_variable(a)
assert a.ndim == 2 assert a.ndim == 2
assert b.ndim == 2 if not isinstance(b, (theano.Variable)):
if b is None:
b = theano.tensor.NoneConst
out_dtype = a.dtype
else:
b = as_tensor_variable(b)
out_dtype = theano.scalar.upcast(a.dtype, b.dtype)
elif not isinstance(b.type, theano.tensor.NoneTypeT):
b = as_tensor_variable(b)
out_dtype = theano.scalar.upcast(a.dtype, b.dtype)
assert b.ndim == 2
else:
out_dtype = a.dtype
out_dtype = theano.scalar.upcast(a.dtype, b.dtype)
w = theano.tensor.vector(dtype=out_dtype) w = theano.tensor.vector(dtype=out_dtype)
return Apply(self, [a, b], [w]) return Apply(self, [a, b], [w])
......
...@@ -587,11 +587,20 @@ def test_eigvalsh(): ...@@ -587,11 +587,20 @@ def test_eigvalsh():
rng = numpy.random.RandomState(utt.fetch_seed()) rng = numpy.random.RandomState(utt.fetch_seed())
a = rng.randn(5, 5) a = rng.randn(5, 5)
a = a + a.T a = a + a.T
for b in [10 * numpy.eye(5, 5) + rng.randn(5, 5), None]: for b in [10 * numpy.eye(5, 5) + rng.randn(5, 5)]:
w = f(a, b) w = f(a, b)
refw = scipy.linalg.eigvalsh(a, b) refw = scipy.linalg.eigvalsh(a, b)
numpy.testing.assert_array_almost_equal(w, refw) numpy.testing.assert_array_almost_equal(w, refw)
# We need to test None separatly, as otherwise DebugMode will
# complain, as this isn't a valid ndarray.
b = None
B = theano.tensor.NoneConst
f = function([A], eigvalsh(A, B))
w = f(a)
refw = scipy.linalg.eigvalsh(a, b)
numpy.testing.assert_array_almost_equal(w, refw)
def test_eigvalsh_grad(): def test_eigvalsh_grad():
rng = numpy.random.RandomState(utt.fetch_seed()) rng = numpy.random.RandomState(utt.fetch_seed())
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论