summaryrefslogtreecommitdiff
path: root/numpy/linalg/tests
diff options
context:
space:
mode:
authorJeremy Chen <convexset@gmail.com>2018-08-01 01:00:07 +0800
committerEric Wieser <wieser.eric@gmail.com>2018-07-31 10:00:07 -0700
commit8fdc4460b9065f8a6cd7e95e106bfeafdc64d613 (patch)
tree1cfde43473d15181536c60c8467077e2ba65b2ac /numpy/linalg/tests
parent9bb569c4e0e1cf08128179d157bdab10c8706a97 (diff)
downloadnumpy-8fdc4460b9065f8a6cd7e95e106bfeafdc64d613.tar.gz
ENH: handle empty matrices in qr decomposition (#11593)
Ensure LWORK and LDA respect the requirements of the lapack methods (zgeqrf, dgeqrf, zungqr, dorgqr)
Diffstat (limited to 'numpy/linalg/tests')
-rw-r--r--numpy/linalg/tests/test_linalg.py31
1 files changed, 19 insertions, 12 deletions
diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py
index 1c24f1e04..0df673884 100644
--- a/numpy/linalg/tests/test_linalg.py
+++ b/numpy/linalg/tests/test_linalg.py
@@ -1582,9 +1582,25 @@ class TestQR(object):
assert_(isinstance(r2, a_type))
assert_almost_equal(r2, r1)
- def test_qr_empty(self):
- a = np.zeros((0, 2))
- assert_raises(linalg.LinAlgError, linalg.qr, a)
+
+ @pytest.mark.parametrize(["m", "n"], [
+ (3, 0),
+ (0, 3),
+ (0, 0)
+ ])
+ def test_qr_empty(self, m, n):
+ k = min(m, n)
+ a = np.empty((m, n))
+ a_type = type(a)
+ a_dtype = a.dtype
+
+ self.check_qr(a)
+
+ h, tau = np.linalg.qr(a, mode='raw')
+ assert_equal(h.dtype, np.double)
+ assert_equal(tau.dtype, np.double)
+ assert_equal(h.shape, (n, m))
+ assert_equal(tau.shape, (k,))
def test_mode_raw(self):
# The factorization is not unique and varies between libraries,
@@ -1625,15 +1641,6 @@ class TestQR(object):
self.check_qr(m2)
self.check_qr(m2.T)
- def test_0_size(self):
- # There may be good ways to do (some of this) reasonably:
- a = np.zeros((0, 0))
- assert_raises(linalg.LinAlgError, linalg.qr, a)
- a = np.zeros((0, 1))
- assert_raises(linalg.LinAlgError, linalg.qr, a)
- a = np.zeros((1, 0))
- assert_raises(linalg.LinAlgError, linalg.qr, a)
-
class TestCholesky(object):
# TODO: are there no other tests for cholesky?