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

Fixed tests and added numpy compare test to norm function.

上级 a747573c
......@@ -3,6 +3,7 @@ import unittest
import numpy
import numpy.linalg
from numpy.testing import assert_array_almost_equal
from numpy.testing import dec, assert_array_equal, assert_allclose
import theano
from theano import tensor, function
......@@ -613,7 +614,6 @@ def test_eigvalsh_grad():
[a, b], rng=numpy.random)
<<<<<<< HEAD
class Matrix_power():
def test_numpy_compare(self):
......@@ -636,24 +636,30 @@ class Matrix_power():
self.assertRaises(ValueError, f, a)
class T_NormTests(unittest.TestCase):
def test_wrong_type_of_ord_for_vector(self):
self.assertRaises(ValueError, norm, [2,1],'fro',0)
def test_wrong_type_of_ord_for_vector_in_matrix(self):
self.assertRaises(ValueError, norm, [[2,1],[3,4]],'fro',0)
def test_wrong_type_of_ord_for_vector_in_tensor(self):
self.assertRaises(ValueError, norm, [[[2,1],[3,4]],[[6,5],[7,8]]],'fro',0)
def test_wrong_type_of_ord_for_matrix(self):
self.assertRaises(ValueError, norm, [[2,1],[3,4]],0,None)
def test_wrong_type_of_ord_for_matrix_in_tensor(self):
self.assertRaises(ValueError, norm, [[[2,1],[3,4]],[[6,5],[7,8]]],0,None)
def test_non_tensorial_input(self):
self.assertRaises(ValueError, norm, 3, None, None)
def test_no_enough_dimensions(self):
self.assertRaises(ValueError, norm, [[2,1],[3,4]], None, 3)
def test():
x = theano.tensor.matrix()
x.swapaxes(0,1)
def test_wrong_type_of_ord_for_vector(self):
self.assertRaises(ValueError, norm, [2,1],'fro',0)
def test_wrong_type_of_ord_for_vector_in_matrix(self):
self.assertRaises(ValueError, norm, [[2,1],[3,4]],'fro',0)
def test_wrong_type_of_ord_for_vector_in_tensor(self):
self.assertRaises(ValueError, norm, [[[2,1],[3,4]],[[6,5],[7,8]]],'fro',0)
def test_wrong_type_of_ord_for_matrix(self):
self.assertRaises(ValueError, norm, [[2,1],[3,4]],0,None)
def test_wrong_type_of_ord_for_matrix_in_tensor(self):
self.assertRaises(ValueError, norm, [[[2,1],[3,4]],[[6,5],[7,8]]],0,None)
def test_non_tensorial_input(self):
self.assertRaises(ValueError, norm, 3, None, None)
def test_no_enough_dimensions(self):
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)
n_n = numpy.linalg.norm(a, None, None)
t_n = fn(a)
assert _allclose(n_n, t_n)
class T_lstsq(unittest.TestCase):
def test_correct_solution(self):
......
......@@ -32,7 +32,7 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as,
alloc, as_tensor_variable, tensor_from_scalar, ARange, autocast_float,
clip, constant, default, dot,
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,
Reshape, row, scalar, scalars, second, smallest, stack, sub, Tensor,
tensor_copy, tensordot, TensorType, Tri, tri, tril, triu, unbroadcast,
......@@ -6918,6 +6918,11 @@ class T_swapaxes(unittest.TestCase):
testMatrix = [[2, 1], [3, 4]]
self.assertTrue(numpy.array_equal(testMatrix, f(f(testMatrix))))
def test_infeshape(self):
x = theano.tensor.matrix()
x.swapaxes(0,1)
class T_Power():
def test_numpy_compare(self):
rng = numpy.random.RandomState(utt.fetch_seed())
......@@ -6944,6 +6949,18 @@ class T_Power():
f = function([x], z)
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__':
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论