summaryrefslogtreecommitdiff
path: root/numpy/linalg/tests
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2017-08-19 15:48:34 +0200
committerSebastian Berg <sebastian@sipsolutions.net>2017-08-19 16:35:08 +0200
commitbd3a2c580e2d5f0a7a958b3e7d942c230648f2e3 (patch)
treed8d6f04c7b1e845437b84b3799596dac0c0c5a3c /numpy/linalg/tests
parent3c887aa5242857ef92870d2988de7c899c6415be (diff)
downloadnumpy-bd3a2c580e2d5f0a7a958b3e7d942c230648f2e3.tar.gz
ENH: Warn to change lstsq default for rcond
The default parameter used by LAPACK (which was our default) is not very good, so implement a FutureWarning to change to a better default.
Diffstat (limited to 'numpy/linalg/tests')
-rw-r--r--numpy/linalg/tests/test_linalg.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py
index 97b2e328a..ab81fc485 100644
--- a/numpy/linalg/tests/test_linalg.py
+++ b/numpy/linalg/tests/test_linalg.py
@@ -793,7 +793,7 @@ class TestLstsq(LinalgSquareTestCase, LinalgNonsquareTestCase):
arr = np.asarray(a)
m, n = arr.shape
u, s, vt = linalg.svd(a, 0)
- x, residuals, rank, sv = linalg.lstsq(a, b)
+ x, residuals, rank, sv = linalg.lstsq(a, b, rcond=-1)
if m <= n:
assert_almost_equal(b, dot(a, x))
assert_equal(rank, m)
@@ -814,6 +814,23 @@ class TestLstsq(LinalgSquareTestCase, LinalgNonsquareTestCase):
assert_(imply(isinstance(b, matrix), isinstance(x, matrix)))
assert_(imply(isinstance(b, matrix), isinstance(residuals, matrix)))
+ def test_future_rcond(self):
+ a = np.array([[0., 1., 0., 1., 2., 0.],
+ [0., 2., 0., 0., 1., 0.],
+ [1., 0., 1., 0., 0., 4.],
+ [0., 0., 0., 2., 3., 0.]]).T
+
+ b = np.array([1, 0, 0, 0, 0, 0])
+ with suppress_warnings() as sup:
+ w = sup.record(FutureWarning, "`rcond` parameter will change")
+ x, residuals, rank, s = linalg.lstsq(a, b)
+ assert_(rank == 4)
+ x, residuals, rank, s = linalg.lstsq(a, b, rcond=-1)
+ assert_(rank == 4)
+ x, residuals, rank, s = linalg.lstsq(a, b, rcond=None)
+ assert_(rank == 3)
+ # Warning should be raised exactly once (first command)
+ assert_(len(w) == 1)
class TestMatrixPower(object):
R90 = array([[0, 1], [-1, 0]])