提交 0c737bad authored 作者: Tanjay94's avatar Tanjay94

Fixed tests and added numpy compare test to norm function.

上级 a747573c
...@@ -3,6 +3,7 @@ import unittest ...@@ -3,6 +3,7 @@ import unittest
import numpy import numpy
import numpy.linalg import numpy.linalg
from numpy.testing import assert_array_almost_equal from numpy.testing import assert_array_almost_equal
from numpy.testing import dec, assert_array_equal, assert_allclose
import theano import theano
from theano import tensor, function from theano import tensor, function
...@@ -613,7 +614,6 @@ def test_eigvalsh_grad(): ...@@ -613,7 +614,6 @@ def test_eigvalsh_grad():
[a, b], rng=numpy.random) [a, b], rng=numpy.random)
<<<<<<< HEAD
class Matrix_power(): class Matrix_power():
def test_numpy_compare(self): def test_numpy_compare(self):
...@@ -650,10 +650,16 @@ class T_NormTests(unittest.TestCase): ...@@ -650,10 +650,16 @@ class T_NormTests(unittest.TestCase):
self.assertRaises(ValueError, norm, 3, None, None) self.assertRaises(ValueError, norm, 3, None, None)
def test_no_enough_dimensions(self): def test_no_enough_dimensions(self):
self.assertRaises(ValueError, norm, [[2,1],[3,4]], None, 3) self.assertRaises(ValueError, norm, [[2,1],[3,4]], None, 3)
def test_numpy_compare(self):
rng = numpy.random.RandomState(utt.fetch_seed())
A = tensor.matrix("A", dtype=theano.config.floatX)
Q = norm(A, None, None)
fn = function([A], [Q])
a = rng.rand(4, 4).astype(theano.config.floatX)
def test(): n_n = numpy.linalg.norm(a, None, None)
x = theano.tensor.matrix() t_n = fn(a)
x.swapaxes(0,1) assert _allclose(n_n, t_n)
class T_lstsq(unittest.TestCase): class T_lstsq(unittest.TestCase):
def test_correct_solution(self): def test_correct_solution(self):
......
...@@ -32,7 +32,7 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as, ...@@ -32,7 +32,7 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as,
alloc, as_tensor_variable, tensor_from_scalar, ARange, autocast_float, alloc, as_tensor_variable, tensor_from_scalar, ARange, autocast_float,
clip, constant, default, dot, clip, constant, default, dot,
dmatrix, dscalar, dvector, eq, eye, fill, flatten, inverse_permutation, dmatrix, dscalar, dvector, eq, eye, fill, flatten, inverse_permutation,
tensor4, permute_row_elements, Flatten, fmatrix, fscalars, grad, tensor4permute_row_elements, Flatten, fmatrix, fscalars, grad,
inplace, iscalar, matrix, minimum, matrices, maximum, mul, neq, inplace, iscalar, matrix, minimum, matrices, maximum, mul, neq,
Reshape, row, scalar, scalars, second, smallest, stack, sub, Tensor, Reshape, row, scalar, scalars, second, smallest, stack, sub, Tensor,
tensor_copy, tensordot, TensorType, Tri, tri, tril, triu, unbroadcast, tensor_copy, tensordot, TensorType, Tri, tri, tril, triu, unbroadcast,
...@@ -6918,6 +6918,11 @@ class T_swapaxes(unittest.TestCase): ...@@ -6918,6 +6918,11 @@ class T_swapaxes(unittest.TestCase):
testMatrix = [[2, 1], [3, 4]] testMatrix = [[2, 1], [3, 4]]
self.assertTrue(numpy.array_equal(testMatrix, f(f(testMatrix)))) self.assertTrue(numpy.array_equal(testMatrix, f(f(testMatrix))))
def test_infeshape(self):
x = theano.tensor.matrix()
x.swapaxes(0,1)
class T_Power(): class T_Power():
def test_numpy_compare(self): def test_numpy_compare(self):
rng = numpy.random.RandomState(utt.fetch_seed()) rng = numpy.random.RandomState(utt.fetch_seed())
...@@ -6944,6 +6949,18 @@ class T_Power(): ...@@ -6944,6 +6949,18 @@ class T_Power():
f = function([x], z) f = function([x], z)
self.assertRaise(ValueError, f, [1, 2, 3, 4]) self.assertRaise(ValueError, f, [1, 2, 3, 4])
def test_numpy_compare(self):
rng = numpy.random.RandomState(utt.fetch_seed())
A = tensor.matrix("A", dtype=theano.config.floatX)
Q = swapaxes(A, 0, 1)
fn = function([A], [Q])
a = rng.rand(4, 4).astype(theano.config.floatX)
n_s = numpy.swapaxes(a, 0, 1)
t_s = fn(a)
assert numpy.allclose(n_s, t_s)
""" """
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论