提交 71262429 authored 作者: Tanjay94's avatar Tanjay94

Removed unimplemented axis inputs in norm test.

上级 548f7f05
...@@ -1215,6 +1215,7 @@ def eigvalsh(a, b, lower=True): ...@@ -1215,6 +1215,7 @@ def eigvalsh(a, b, lower=True):
return Eigvalsh(lower)(a, b) return Eigvalsh(lower)(a, b)
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
def matrix_power(M, n): def matrix_power(M, n):
result = 1 result = 1
...@@ -1245,17 +1246,13 @@ def norm(x,ord): ...@@ -1245,17 +1246,13 @@ def norm(x,ord):
return z return z
elif ndim == 2: elif ndim == 2:
if ord == None or ord == 'fro': if ord == None or ord == 'fro':
z = (tensor.sum(abs(x**2)))**(0.5) return tensor.sum(abs(x**2))**(0.5)
return z
elif ord == 'inf': elif ord == 'inf':
z = tensor.sum(abs(x),1) return tensor.max(tensor.sum(abs(x), 1))
return tensor.max(z)
elif ord == '-inf': elif ord == '-inf':
z = tensor.sum(abs(x),1) return tensor.min(tensor.sum(abs(x), 1))
return tensor.min(z)
elif ord == 1: elif ord == 1:
z = tensor.sum(abs(x),0) return tensor.max(tensor.sum(abs(x), 0))
return tensor.max(z)
elif ord == -1: elif ord == -1:
z = tensor.sum(abs(x),0) z = tensor.sum(abs(x),0)
return tensor.min(z) return tensor.min(z)
......
...@@ -638,21 +638,18 @@ class Matrix_power(): ...@@ -638,21 +638,18 @@ class Matrix_power():
class T_NormTests(unittest.TestCase): class T_NormTests(unittest.TestCase):
def test_wrong_type_of_ord_for_vector(self): def test_wrong_type_of_ord_for_vector(self):
self.assertRaises(ValueError, norm, [2, 1], 'fro', 0) self.assertRaises(ValueError, norm, [2, 1], 'fro')
def test_wrong_type_of_ord_for_matrix(self): def test_wrong_type_of_ord_for_matrix(self):
self.assertRaises(ValueError, norm, [[2, 1], [3, 4]], 0, None) self.assertRaises(ValueError, norm, [[2, 1], [3, 4]], 0)
def test_non_tensorial_input(self): def test_non_tensorial_input(self):
self.assertRaises(ValueError, norm, 3, None, None) self.assertRaises(ValueError, norm, 3, None)
def test_tensor_input(self): def test_tensor_input(self):
self.assertRaises(NotImplementedError, norm, numpy.random.rand(3, 4, 5), None, None) self.assertRaises(NotImplementedError, norm, numpy.random.rand(3, 4, 5), None)
def test_numpy_compare(self): def test_numpy_compare(self):
f = []
t_n = []
n_n = []
rng = numpy.random.RandomState(utt.fetch_seed()) rng = numpy.random.RandomState(utt.fetch_seed())
M = tensor.matrix("A", dtype=theano.config.floatX) M = tensor.matrix("A", dtype=theano.config.floatX)
...@@ -663,21 +660,14 @@ class T_NormTests(unittest.TestCase): ...@@ -663,21 +660,14 @@ class T_NormTests(unittest.TestCase):
A = ( [None, 'fro', 'inf', '-inf', 1, -1, None, 'inf', '-inf', 0, 1, -1, 2, -2], A = ( [None, 'fro', 'inf', '-inf', 1, -1, None, 'inf', '-inf', 0, 1, -1, 2, -2],
[M, M, M, M, M, M, V, V, V, V, V, V, V, V], [M, M, M, M, M, M, V, V, V, V, V, V, V, V],
[None, None, None, None, None, None, None, None, None, None, None, None, None, None],
[a, a, a, a, a, a, b, b, b, b, b, b, b, b], [a, a, a, a, a, a, b, b, b, b, b, b, b, b],
[None, 'fro', inf, -inf, 1, -1, None, inf, -inf, 0, 1, -1, 2, -2]) [None, 'fro', inf, -inf, 1, -1, None, inf, -inf, 0, 1, -1, 2, -2])
try:
numpy.linalg.norm([[2, 1], [3, 4]], None, None)
except TypeError, e:
assert "norm() takes at most 2 arguments (3 given)" in str(e)
raise SkipTest
for i in range(0, 14): for i in range(0, 14):
f.append(function([A[1][i]], [norm(A[1][i], A[0][i], A[2][i])])) f = function([A[1][i]], norm(A[1][i], A[0][i]))
t_n.append(f[i](A[3][i])) t_n = f(A[2][i])
n_n.append(numpy.linalg.norm(A[3][i], A[4][i], A[2][i])) n_n = numpy.linalg.norm(A[2][i], A[3][i])
assert _allclose(n_n[i], t_n[i]) assert _allclose(n_n, t_n)
class T_lstsq(unittest.TestCase): class T_lstsq(unittest.TestCase):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论