提交 f7b98a6e authored 作者: abergeron's avatar abergeron

Merge pull request #1867 from nouiz/fix_test

Fix test
......@@ -401,10 +401,17 @@ class SingletonType(Type):
It saves having to implement __eq__ and __hash__
"""
__instance = None
def __new__(cls):
if cls.__instance is None:
# If sub-subclass of SingletonType don't redeclare __instance
# when we look for it, we will find it in the subclass. We
# don't want that, so we check the class. When we add one, we
# add one only to the current class, so all is working
# correctly.
if cls.__instance is None or not isinstance(cls.__instance, cls):
cls.__instance = Type.__new__(cls)
return cls.__instance
def __str__(self):
return self.__class__.__name__
......
......@@ -1119,11 +1119,22 @@ class Eigvalsh(Op):
def make_node(self, a, b):
assert imported_scipy, (
"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 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)
return Apply(self, [a, b], [w])
......
......@@ -587,11 +587,20 @@ def test_eigvalsh():
rng = numpy.random.RandomState(utt.fetch_seed())
a = rng.randn(5, 5)
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)
refw = scipy.linalg.eigvalsh(a, b)
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():
rng = numpy.random.RandomState(utt.fetch_seed())
......
......@@ -72,10 +72,9 @@ class NoneTypeT(Generic):
else:
raise TypeError('Expected None!')
def __str__(self):
return "None"
none_type_t = NoneTypeT()
# This is a variable instance. It can be used only once per fgraph.
# So use NoneConst.clone() before using it in a Theano graph.
# Use NoneConst.equal(x) to check if two variable are NoneConst.
NoneConst = Constant(NoneTypeT(), None, name='None')
NoneConst = Constant(NoneTypeT(), None, name='NoneConst')
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论