-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
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 all commits
36fcb0c
3fa693a
6dabc39
448b409
1624a80
e6fa7df
7f22736
68d608e
5809e9a
16d79e9
c4c6426
ff9063c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -858,13 +858,13 @@ def qr(a, mode='reduced'): | |
|
|
||
| a, wrap = _makearray(a) | ||
| _assertRank2(a) | ||
| _assertNoEmpty2d(a) | ||
| m, n = a.shape | ||
| t, result_t = _commonType(a) | ||
| a = _fastCopyAndTranspose(t, a) | ||
| a = _to_native_byte_order(a) | ||
| mn = min(m, n) | ||
| tau = zeros((mn,), t) | ||
|
|
||
| if isComplexType(t): | ||
| lapack_routine = lapack_lite.zgeqrf | ||
| routine_name = 'zgeqrf' | ||
|
|
@@ -875,14 +875,14 @@ def qr(a, mode='reduced'): | |
| # calculate optimal size of work data 'work' | ||
| lwork = 1 | ||
| work = zeros((lwork,), t) | ||
| results = lapack_routine(m, n, a, m, tau, work, -1, 0) | ||
| results = lapack_routine(m, n, a, max(1, m), tau, work, -1, 0) | ||
| if results['info'] != 0: | ||
| raise LinAlgError('%s returns %d' % (routine_name, results['info'])) | ||
|
|
||
| # do qr decomposition | ||
| lwork = int(abs(work[0])) | ||
| lwork = max(1, n, int(abs(work[0]))) | ||
| work = zeros((lwork,), t) | ||
| results = lapack_routine(m, n, a, m, tau, work, lwork, 0) | ||
| results = lapack_routine(m, n, a, max(1, m), tau, work, lwork, 0) | ||
| if results['info'] != 0: | ||
| raise LinAlgError('%s returns %d' % (routine_name, results['info'])) | ||
|
|
||
|
|
@@ -918,14 +918,14 @@ def qr(a, mode='reduced'): | |
| # determine optimal lwork | ||
| lwork = 1 | ||
| work = zeros((lwork,), t) | ||
| results = lapack_routine(m, mc, mn, q, m, tau, work, -1, 0) | ||
| results = lapack_routine(m, mc, mn, q, max(1, m), tau, work, -1, 0) | ||
| if results['info'] != 0: | ||
| raise LinAlgError('%s returns %d' % (routine_name, results['info'])) | ||
|
|
||
| # compute q | ||
| lwork = int(abs(work[0])) | ||
| lwork = max(1, n, int(abs(work[0]))) | ||
|
Member
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. So, looking at the source code - Either way, what you have here is definitely correct, and it doesn't really do any harm to be extra safe. |
||
| work = zeros((lwork,), t) | ||
| results = lapack_routine(m, mc, mn, q, m, tau, work, lwork, 0) | ||
| results = lapack_routine(m, mc, mn, q, max(1, m), tau, work, lwork, 0) | ||
| if results['info'] != 0: | ||
| raise LinAlgError('%s returns %d' % (routine_name, results['info'])) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
This is exactly the fix I was expecting :)
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.
... yes... and (the late) Gene Golub is not going to tell me to give back my e-mail account. (I got my gmail invite from him.)