-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ENH: handle empty matrices in qr decomposition #11593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
36fcb0c
3fa693a
6dabc39
448b409
1624a80
e6fa7df
7f22736
68d608e
5809e9a
16d79e9
c4c6426
ff9063c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1583,45 +1583,39 @@ def check_qr(self, a): | |
assert_almost_equal(r2, r1) | ||
|
||
def test_qr_empty(self): | ||
for m, n in [(3, 0), (0, 3)]: | ||
for m, n in [(0, 0), (3, 0), (0, 3)]: | ||
k = min(m, n) | ||
a = np.empty((m, n)) | ||
a_type = type(a) | ||
a_dtype = a.dtype | ||
# | ||
|
||
q, r = np.linalg.qr(a, mode='reduced') | ||
assert_(q.dtype == a_dtype) | ||
assert_(r.dtype == a_dtype) | ||
assert_equal(q.dtype, a_dtype) | ||
assert_equal(r.dtype, a_dtype) | ||
assert_(isinstance(q, a_type)) | ||
assert_(isinstance(r, a_type)) | ||
assert_(q.shape == (m, k)) | ||
assert_(r.shape == (k, n)) | ||
assert_almost_equal(np.dot(q, r), a) | ||
assert_almost_equal(np.dot(q.T.conj(), q), np.eye(k)) | ||
assert_almost_equal(np.triu(r), r) | ||
# | ||
assert_equal(q.shape, (m, k)) | ||
assert_equal(r.shape, (k, n)) | ||
|
||
r = np.linalg.qr(a, mode='r') | ||
assert_(r.dtype == a_dtype) | ||
assert_equal(r.dtype, a_dtype) | ||
assert_(isinstance(r, a_type)) | ||
assert_(r.shape == (k, n)) | ||
assert_almost_equal(np.triu(r), r) | ||
# | ||
assert_equal(r.shape, (k, n)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shape test should probably be in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's there implicitly. # mode == 'reduced'
q1, r1 = linalg.qr(a, mode='reduced')
# ...
assert_(r1.shape == (k, n))
# ...
# mode == 'r'
r2 = linalg.qr(a, mode='r')
# ...
assert_almost_equal(r2, r1) So I took that bit out. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. I think the explicit shape check you had here was a little clearer, but it's not super important. |
||
|
||
q, r = np.linalg.qr(a, mode='complete') | ||
assert_(q.dtype == a_dtype) | ||
assert_(r.dtype == a_dtype) | ||
assert_equal(q.dtype, a_dtype) | ||
assert_equal(r.dtype, a_dtype) | ||
assert_(isinstance(q, a_type)) | ||
assert_(isinstance(r, a_type)) | ||
assert_(q.shape == (m, m)) | ||
assert_(r.shape == (m, n)) | ||
assert_equal(q.shape, (m, m)) | ||
assert_equal(r.shape, (m, n)) | ||
assert_almost_equal(q, np.eye(m)) | ||
assert_almost_equal(np.dot(q, r), a) | ||
assert_almost_equal(np.triu(r), r) | ||
# | ||
|
||
h, tau = np.linalg.qr(a, mode='raw') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test can stay - for whatever reason, it seems |
||
assert_(h.dtype == np.double) | ||
assert_(tau.dtype == np.double) | ||
assert_(h.shape == (n, m)) | ||
assert_(tau.shape == (k,)) | ||
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, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this already covered by
check_qr
?