提交 929bb073 authored 作者: Frederic's avatar Frederic

pep8

上级 5f58b6fc
...@@ -185,6 +185,7 @@ def test_inverse_grad(): ...@@ -185,6 +185,7 @@ def test_inverse_grad():
r = rng.randn(4, 4) r = rng.randn(4, 4)
tensor.verify_grad(matrix_inverse, [r], rng=numpy.random) tensor.verify_grad(matrix_inverse, [r], rng=numpy.random)
def test_rop_lop(): def test_rop_lop():
mx = tensor.matrix('mx') mx = tensor.matrix('mx')
mv = tensor.matrix('mv') mv = tensor.matrix('mv')
...@@ -442,6 +443,7 @@ def test_spectral_radius_bound(): ...@@ -442,6 +443,7 @@ def test_spectral_radius_bound():
ok = True ok = True
assert ok assert ok
class test_Solve(utt.InferShapeTester): class test_Solve(utt.InferShapeTester):
def setUp(self): def setUp(self):
super(test_Solve, self).setUp() super(test_Solve, self).setUp()
...@@ -474,10 +476,12 @@ class test_Solve(utt.InferShapeTester): ...@@ -474,10 +476,12 @@ class test_Solve(utt.InferShapeTester):
dtype=config.floatX)], dtype=config.floatX)],
self.op_class) self.op_class)
class test_Eig(utt.InferShapeTester): class test_Eig(utt.InferShapeTester):
op_class = Eig op_class = Eig
op = eig op = eig
dtype = 'float64' dtype = 'float64'
def setUp(self): def setUp(self):
super(test_Eig, self).setUp() super(test_Eig, self).setUp()
self.rng = numpy.random.RandomState(utt.fetch_seed()) self.rng = numpy.random.RandomState(utt.fetch_seed())
...@@ -485,7 +489,7 @@ class test_Eig(utt.InferShapeTester): ...@@ -485,7 +489,7 @@ class test_Eig(utt.InferShapeTester):
X = numpy.asarray(self.rng.rand(5, 5), X = numpy.asarray(self.rng.rand(5, 5),
dtype=self.dtype) dtype=self.dtype)
self.S = X.dot(X.T) self.S = X.dot(X.T)
def test_infer_shape(self): def test_infer_shape(self):
A = self.A A = self.A
S = self.S S = self.S
...@@ -494,26 +498,29 @@ class test_Eig(utt.InferShapeTester): ...@@ -494,26 +498,29 @@ class test_Eig(utt.InferShapeTester):
# S must be square # S must be square
[S], [S],
self.op_class) self.op_class)
def test_eval(self): def test_eval(self):
import math import math
A = theano.tensor.matrix(dtype=self.dtype) A = theano.tensor.matrix(dtype=self.dtype)
self.assertEquals([e.eval({A: [[1]]}) for e in self.op(A)], self.assertEquals([e.eval({A: [[1]]}) for e in self.op(A)],
[[1.0], [[1.0]]]) [[1.0], [[1.0]]])
x = [[0, 1], [1, 0]] x = [[0, 1], [1, 0]]
w, v = [e.eval({A: x}) for e in self.op(A)] w, v = [e.eval({A: x}) for e in self.op(A)]
assert_array_almost_equal(numpy.dot(x,v), w * v) assert_array_almost_equal(numpy.dot(x, v), w * v)
class test_Eigh(test_Eig): class test_Eigh(test_Eig):
op = staticmethod(eigh) op = staticmethod(eigh)
def test_uplo(self): def test_uplo(self):
S = self.S S = self.S
a = theano.tensor.matrix(dtype=self.dtype) a = theano.tensor.matrix(dtype=self.dtype)
wu, vu = [out.eval({a: S}) for out in self.op(a, 'U')] wu, vu = [out.eval({a: S}) for out in self.op(a, 'U')]
wl, vl = [out.eval({a: S}) for out in self.op(a, 'L')] wl, vl = [out.eval({a: S}) for out in self.op(a, 'L')]
assert_array_almost_equal(wu, wl) assert_array_almost_equal(wu, wl)
assert_array_almost_equal(vu*numpy.sign(vu[0,:]), assert_array_almost_equal(vu * numpy.sign(vu[0, :]),
vl*numpy.sign(vl[0,:])) vl * numpy.sign(vl[0, :]))
def test_grad(self): def test_grad(self):
S = self.S S = self.S
utt.verify_grad(lambda x: self.op(x)[0], [S], rng=self.rng) utt.verify_grad(lambda x: self.op(x)[0], [S], rng=self.rng)
...@@ -521,5 +528,6 @@ class test_Eigh(test_Eig): ...@@ -521,5 +528,6 @@ class test_Eigh(test_Eig):
utt.verify_grad(lambda x: self.op(x, 'U')[0], [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) utt.verify_grad(lambda x: self.op(x, 'U')[1], [S], rng=self.rng)
class test_Eigh_float32(test_Eigh): class test_Eigh_float32(test_Eigh):
dtype = 'float32' dtype = 'float32'
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论