[Scipy-svn] r7089 - trunk/scipy/linalg/tests
scipy-svn at scipy.org
scipy-svn at scipy.org
Wed Jan 26 18:07:11 EST 2011
Author: ptvirtan
Date: 2011-01-26 17:07:09 -0600 (Wed, 26 Jan 2011)
New Revision: 7089
Modified:
trunk/scipy/linalg/tests/test_decomp.py
Log:
TST: linalg: add some new tests for qr and rq, and initialize random seeds
Modified: trunk/scipy/linalg/tests/test_decomp.py
===================================================================
--- trunk/scipy/linalg/tests/test_decomp.py 2011-01-26 23:06:53 UTC (rev 7088)
+++ trunk/scipy/linalg/tests/test_decomp.py 2011-01-26 23:07:09 UTC (rev 7089)
@@ -30,7 +30,7 @@
asarray, matrix, isfinite, all, ndarray, outer, eye, dtype, empty,\
triu, tril
-from numpy.random import rand, normal
+from numpy.random import rand, normal, seed
# digit precision to use in asserts for different types
DIGITS = {'d':11, 'D':11, 'f':4, 'F':4}
@@ -703,6 +703,9 @@
self.cmed = self.vrect.astype(complex64)
class TestLUSolve(TestCase):
+ def setUp(self):
+ seed(1234)
+
def test_lu(self):
a = random((10,10))
b = random((10,))
@@ -715,6 +718,8 @@
assert_array_equal(x1,x2)
class TestSVD(TestCase):
+ def setUp(self):
+ seed(1234)
def test_simple(self):
a = [[1,2,3],[1,20,3],[2,5,6]]
@@ -833,6 +838,9 @@
class TestQR(TestCase):
+ def setUp(self):
+ seed(1234)
+
def test_simple(self):
a = [[8,2,3],[2,9,3],[5,3,6]]
q,r = qr(a)
@@ -861,6 +869,24 @@
assert_equal(q.shape, (3,2))
assert_equal(r.shape, (2,2))
+ def test_simple_fat(self):
+ # full version
+ a = [[8,2,5],[2,9,3]]
+ q,r = qr(a)
+ assert_array_almost_equal(dot(transpose(q),q),identity(2))
+ assert_array_almost_equal(dot(q,r),a)
+ assert_equal(q.shape, (2,2))
+ assert_equal(r.shape, (2,3))
+
+ def test_simple_fat_e(self):
+ # economy version
+ a = [[8,2,3],[2,9,5]]
+ q,r = qr(a, mode='economic')
+ assert_array_almost_equal(dot(transpose(q),q),identity(2))
+ assert_array_almost_equal(dot(q,r),a)
+ assert_equal(q.shape, (2,2))
+ assert_equal(r.shape, (2,3))
+
def test_simple_complex(self):
a = [[3,3+4j,5],[5,2,2+7j],[3,2,7]]
q,r = qr(a)
@@ -916,12 +942,21 @@
class TestRQ(TestCase):
+ def setUp(self):
+ seed(1234)
+
def test_simple(self):
a = [[8,2,3],[2,9,3],[5,3,6]]
r,q = rq(a)
assert_array_almost_equal(dot(q, transpose(q)),identity(3))
assert_array_almost_equal(dot(r,q),a)
+ def test_r(self):
+ a = [[8,2,3],[2,9,3],[5,3,6]]
+ r,q = rq(a)
+ r2 = rq(a, mode='r')
+ assert_array_almost_equal(r, r2)
+
def test_random(self):
n = 20
for k in range(2):
@@ -942,6 +977,12 @@
assert_array_almost_equal(dot(transpose(q),q),identity(2))
assert_array_almost_equal(dot(r,q),a)
+ def test_simple_fat(self):
+ a = [[8,2,5],[2,9,3]]
+ r,q = rq(a)
+ assert_array_almost_equal(dot(transpose(q),q),identity(3))
+ assert_array_almost_equal(dot(r,q),a)
+
def test_simple_complex(self):
a = [[3,3+4j,5],[5,2,2+7j],[3,2,7]]
r,q = rq(a)
@@ -985,6 +1026,17 @@
assert_array_almost_equal(dot(q, conj(transpose(q))),identity(n))
assert_array_almost_equal(dot(r,q),a)
+ def test_random_complex_economic(self):
+ m = 100
+ n = 200
+ for k in range(2):
+ a = random([m,n])+1j*random([m,n])
+ r,q = rq(a, mode='economic')
+ assert_array_almost_equal(dot(q,conj(transpose(q))),identity(m))
+ assert_array_almost_equal(dot(r,q),a)
+ assert_equal(q.shape, (m, n))
+ assert_equal(r.shape, (m, m))
+
transp = transpose
any = sometrue
More information about the Scipy-svn
mailing list