summaryrefslogtreecommitdiff
path: root/numpy/linalg
diff options
context:
space:
mode:
authorAlan McIntyre <alan.mcintyre@local>2008-06-17 00:23:20 +0000
committerAlan McIntyre <alan.mcintyre@local>2008-06-17 00:23:20 +0000
commitc331857d8663ecf54bbe88c834755da749e8ab52 (patch)
treef4cc69ec328a5ff4d3b108f3610acb119a196493 /numpy/linalg
parent22ba7886a84dc6a16ca75871f7cd2f10ef8de1f9 (diff)
downloadnumpy-c331857d8663ecf54bbe88c834755da749e8ab52.tar.gz
Switched to use nose to run tests. Added test and bench functions to all modules.
Diffstat (limited to 'numpy/linalg')
-rw-r--r--numpy/linalg/__init__.py6
-rw-r--r--numpy/linalg/tests/test_linalg.py52
-rw-r--r--numpy/linalg/tests/test_regression.py5
3 files changed, 33 insertions, 30 deletions
diff --git a/numpy/linalg/__init__.py b/numpy/linalg/__init__.py
index 85d81d0a8..842c791d2 100644
--- a/numpy/linalg/__init__.py
+++ b/numpy/linalg/__init__.py
@@ -3,6 +3,6 @@ from info import __doc__
from linalg import *
-def test(level=1, verbosity=1):
- from numpy.testing import NumpyTest
- return NumpyTest().test(level, verbosity)
+from numpy.testing.pkgtester import Tester
+test = Tester().test
+bench = Tester().test
diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py
index d7c3a63ca..58c5cd456 100644
--- a/numpy/linalg/tests/test_linalg.py
+++ b/numpy/linalg/tests/test_linalg.py
@@ -23,28 +23,28 @@ def assert_almost_equal(a, b, **kw):
decimal = 12
old_assert_almost_equal(a, b, decimal=decimal, **kw)
-class LinalgTestCase(NumpyTestCase):
- def check_single(self):
+class LinalgTestCase:
+ def test_single(self):
a = array([[1.,2.], [3.,4.]], dtype=single)
b = array([2., 1.], dtype=single)
self.do(a, b)
- def check_double(self):
+ def test_double(self):
a = array([[1.,2.], [3.,4.]], dtype=double)
b = array([2., 1.], dtype=double)
self.do(a, b)
- def check_csingle(self):
+ def test_csingle(self):
a = array([[1.+2j,2+3j], [3+4j,4+5j]], dtype=csingle)
b = array([2.+1j, 1.+2j], dtype=csingle)
self.do(a, b)
- def check_cdouble(self):
+ def test_cdouble(self):
a = array([[1.+2j,2+3j], [3+4j,4+5j]], dtype=cdouble)
b = array([2.+1j, 1.+2j], dtype=cdouble)
self.do(a, b)
- def check_empty(self):
+ def test_empty(self):
a = atleast_2d(array([], dtype = double))
b = atleast_2d(array([], dtype = double))
try:
@@ -53,79 +53,79 @@ class LinalgTestCase(NumpyTestCase):
except linalg.LinAlgError, e:
pass
- def check_nonarray(self):
+ def test_nonarray(self):
a = [[1,2], [3,4]]
b = [2, 1]
self.do(a,b)
- def check_matrix_b_only(self):
+ def test_matrix_b_only(self):
"""Check that matrix type is preserved."""
a = array([[1.,2.], [3.,4.]])
b = matrix([2., 1.]).T
self.do(a, b)
- def check_matrix_a_and_b(self):
+ def test_matrix_a_and_b(self):
"""Check that matrix type is preserved."""
a = matrix([[1.,2.], [3.,4.]])
b = matrix([2., 1.]).T
self.do(a, b)
-class TestSolve(LinalgTestCase):
+class TestSolve(LinalgTestCase, TestCase):
def do(self, a, b):
x = linalg.solve(a, b)
assert_almost_equal(b, dot(a, x))
assert imply(isinstance(b, matrix), isinstance(x, matrix))
-class TestInv(LinalgTestCase):
+class TestInv(LinalgTestCase, TestCase):
def do(self, a, b):
a_inv = linalg.inv(a)
assert_almost_equal(dot(a, a_inv), identity(asarray(a).shape[0]))
assert imply(isinstance(a, matrix), isinstance(a_inv, matrix))
-class TestEigvals(LinalgTestCase):
+class TestEigvals(LinalgTestCase, TestCase):
def do(self, a, b):
ev = linalg.eigvals(a)
evalues, evectors = linalg.eig(a)
assert_almost_equal(ev, evalues)
-class TestEig(LinalgTestCase):
+class TestEig(LinalgTestCase, TestCase):
def do(self, a, b):
evalues, evectors = linalg.eig(a)
assert_almost_equal(dot(a, evectors), multiply(evectors, evalues))
assert imply(isinstance(a, matrix), isinstance(evectors, matrix))
-class TestSVD(LinalgTestCase):
+class TestSVD(LinalgTestCase, TestCase):
def do(self, a, b):
u, s, vt = linalg.svd(a, 0)
assert_almost_equal(a, dot(multiply(u, s), vt))
assert imply(isinstance(a, matrix), isinstance(u, matrix))
assert imply(isinstance(a, matrix), isinstance(vt, matrix))
-class TestCondSVD(LinalgTestCase):
+class TestCondSVD(LinalgTestCase, TestCase):
def do(self, a, b):
c = asarray(a) # a might be a matrix
s = linalg.svd(c, compute_uv=False)
old_assert_almost_equal(s[0]/s[-1], linalg.cond(a), decimal=5)
-class TestCond2(LinalgTestCase):
+class TestCond2(LinalgTestCase, TestCase):
def do(self, a, b):
c = asarray(a) # a might be a matrix
s = linalg.svd(c, compute_uv=False)
old_assert_almost_equal(s[0]/s[-1], linalg.cond(a,2), decimal=5)
-class TestCondInf(NumpyTestCase):
+class TestCondInf(TestCase):
def test(self):
A = array([[1.,0,0],[0,-2.,0],[0,0,3.]])
assert_almost_equal(linalg.cond(A,inf),3.)
-class TestPinv(LinalgTestCase):
+class TestPinv(LinalgTestCase, TestCase):
def do(self, a, b):
a_ginv = linalg.pinv(a)
assert_almost_equal(dot(a, a_ginv), identity(asarray(a).shape[0]))
assert imply(isinstance(a, matrix), isinstance(a_ginv, matrix))
-class TestDet(LinalgTestCase):
+class TestDet(LinalgTestCase, TestCase):
def do(self, a, b):
d = linalg.det(a)
if asarray(a).dtype.type in (single, double):
@@ -135,7 +135,7 @@ class TestDet(LinalgTestCase):
ev = linalg.eigvals(ad)
assert_almost_equal(d, multiply.reduce(ev))
-class TestLstsq(LinalgTestCase):
+class TestLstsq(LinalgTestCase, TestCase):
def do(self, a, b):
u, s, vt = linalg.svd(a, 0)
x, residuals, rank, sv = linalg.lstsq(a, b)
@@ -145,7 +145,7 @@ class TestLstsq(LinalgTestCase):
assert imply(isinstance(b, matrix), isinstance(x, matrix))
assert imply(isinstance(b, matrix), isinstance(residuals, matrix))
-class TestMatrixPower(ParametricTestCase):
+class TestMatrixPower(TestCase):
R90 = array([[0,1],[-1,0]])
Arb22 = array([[4,-7],[-2,10]])
noninv = array([[1,0],[0,0]])
@@ -158,6 +158,7 @@ class TestMatrixPower(ParametricTestCase):
def test_large_power(self):
assert_equal(matrix_power(self.R90,2L**100+2**10+2**5+1),self.R90)
+
def test_large_power_trailing_zero(self):
assert_equal(matrix_power(self.R90,2L**100+2**10+2**5),identity(2))
@@ -197,10 +198,11 @@ class TestMatrixPower(ParametricTestCase):
self.assertRaises(numpy.linalg.linalg.LinAlgError,
lambda: matrix_power(self.noninv,-1))
-class TestBoolPower(NumpyTestCase):
- def check_square(self):
+class TestBoolPower(TestCase):
+ def test_square(self):
A = array([[True,False],[True,True]])
assert_equal(matrix_power(A,2),A)
-if __name__ == '__main__':
- NumpyTest().run()
+
+if __name__ == "__main__":
+ nose.run(argv=['', __file__])
diff --git a/numpy/linalg/tests/test_regression.py b/numpy/linalg/tests/test_regression.py
index 7a2588000..ec9bc695f 100644
--- a/numpy/linalg/tests/test_regression.py
+++ b/numpy/linalg/tests/test_regression.py
@@ -9,7 +9,7 @@ restore_path()
rlevel = 1
-class TestRegression(NumpyTestCase):
+class TestRegression(TestCase):
def test_eig_build(self, level = rlevel):
"""Ticket #652"""
rva = array([1.03221168e+02 +0.j,
@@ -54,5 +54,6 @@ class TestRegression(NumpyTestCase):
assert_array_almost_equal(b, np.zeros((2, 2)))
+
if __name__ == '__main__':
- NumpyTest().run()
+ nose.run(argv=['', __file__])