提交 5a46c7d8 authored 作者: abalkin's avatar abalkin 提交者: Frederic

Fixed the type of eigenvalues returned by eigh op.

上级 d5b686f6
......@@ -944,7 +944,13 @@ class Eigh(Eig):
def make_node(self, x):
x = as_tensor_variable(x)
w = theano.tensor.vector(dtype='float64')
# Numpy's linalg.eigh may return either double or single
# presision eigenvalues depending on installed version of
# LAPACK. Rather than trying to reproduce the (rather
# involved) logic, we just probe linalg.eigh with a trivial
# input.
w_dtype = self._numop([[numpy.dtype(x.dtype).type()]])[0].dtype.name
w = theano.tensor.vector(dtype=w_dtype)
v = theano.tensor.matrix(dtype=x.dtype)
return Apply(self, [x], [w, v])
......
......@@ -473,12 +473,13 @@ class test_Solve(utt.InferShapeTester):
class test_Eig(utt.InferShapeTester):
op_class = Eig
op = eig
dtype = 'float64'
def setUp(self):
super(test_Eig, self).setUp()
self.rng = numpy.random.RandomState(utt.fetch_seed())
self.A = theano.tensor.matrix()
X = numpy.asarray(self.rng.rand(5, 5),
dtype=config.floatX)
dtype=self.dtype)
self.S = X.dot(X.T)
def test_infer_shape(self):
......@@ -491,7 +492,7 @@ class test_Eig(utt.InferShapeTester):
self.op_class)
def test_eval(self):
import math
A = theano.tensor.matrix()
A = theano.tensor.matrix(dtype=self.dtype)
self.assertEquals([e.eval({A: [[1]]}) for e in self.op(A)],
[[1.0], [[1.0]]])
x = [[0, 1], [1, 0]]
......@@ -515,3 +516,6 @@ class test_Eigh(test_Eig):
utt.verify_grad(lambda x: self.op(x)[1], [S], rng=self.rng)
utt.verify_grad(lambda x: self.op(x, 'U')[0], [S], rng=self.rng)
utt.verify_grad(lambda x: self.op(x, 'U')[1], [S], rng=self.rng)
class test_Eigh_float32(test_Eigh):
dtype = 'float32'
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论