diff options
author | Matthew Brett <matthew.brett@gmail.com> | 2012-07-14 17:53:10 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2012-07-14 19:34:26 -0600 |
commit | 78b7693d1a3381aabb23b244332e5a568f58909f (patch) | |
tree | 1c0b7c0ff50ced7899b827f3b82c545caf7070f6 /numpy/linalg/tests | |
parent | 6a1ab0382a8a7e7415277231fedc0ee1ef60326c (diff) | |
download | numpy-78b7693d1a3381aabb23b244332e5a568f58909f.tar.gz |
BUG: change default threshold for matrix_rank
The default tolerance threshold for matrix_rank was passing as full rank
some matrices that were numerically rank deficient. This commit changes
the default tolerance to match the algorithm in MATLAB and Numerical
recipes.
Diffstat (limited to 'numpy/linalg/tests')
-rw-r--r-- | numpy/linalg/tests/test_linalg.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py index 2a2ec3da5..623939863 100644 --- a/numpy/linalg/tests/test_linalg.py +++ b/numpy/linalg/tests/test_linalg.py @@ -3,7 +3,9 @@ import sys import numpy as np -from numpy.testing import * +from numpy.testing import (TestCase, assert_, assert_equal, assert_raises, + assert_array_equal, assert_almost_equal, + run_module_suite) from numpy import array, single, double, csingle, cdouble, dot, identity from numpy import multiply, atleast_2d, inf, asarray, matrix from numpy import linalg @@ -451,6 +453,19 @@ class TestMatrixRank(object): yield assert_equal, matrix_rank(1), 1 +def test_reduced_rank(): + # Test matrices with reduced rank + rng = np.random.RandomState(20120714) + for i in range(100): + # Make a rank deficient matrix + X = rng.normal(size=(40, 10)) + X[:, 0] = X[:, 1] + X[:, 2] + # Assert that matrix_rank detected deficiency + assert_equal(matrix_rank(X), 9) + X[:, 3] = X[:, 4] + X[:, 5] + assert_equal(matrix_rank(X), 8) + + class TestQR(TestCase): def test_qr_empty(self): a = np.zeros((0,2)) |