Permalink
Browse files

BUG: linalg/flapackf: fix lwork size in gerqf/orgrq/ungrq

Thanks to Mike Wimmer for the patch.
  • Loading branch information...
1 parent 6052f3c commit ed29437a98d1ddd66230247ec01a666d12188633 @pv committed May 20, 2012
Showing with 26 additions and 4 deletions.
  1. +3 −3 scipy/linalg/flapack.pyf.src
  2. +23 −1 scipy/linalg/tests/test_lapack.py
View
6 scipy/linalg/flapack.pyf.src
@@ -650,7 +650,7 @@ interface
<ftype> dimension(m,n),intent(in,out,copy,out=qr,aligned8) :: a
<ftype> dimension(MIN(m,n)),intent(out) :: tau
- integer optional,intent(in),depend(n),check(lwork>=n||lwork==-1) :: lwork=3*n
+ integer optional,intent(in),depend(n),check(lwork>=m||lwork==-1) :: lwork=3*m
<ftype> dimension(MAX(lwork,1)),intent(out),depend(lwork) :: work
integer intent(out) :: info
end subroutine <prefix>gerqf
@@ -769,7 +769,7 @@ interface
<ftype2> dimension(m,n),intent(in,out,copy,out=q) :: a
<ftype2> dimension(k),intent(in) :: tau
- integer optional,intent(in),depend(n),check(lwork>=n||lwork==-1) :: lwork=3*n
+ integer optional,intent(in),depend(n),check(lwork>=m||lwork==-1) :: lwork=3*m
<ftype2> dimension(MAX(lwork,1)),intent(out),depend(lwork) :: work
integer intent(out) :: info
end subroutine <prefix2>orgrq
@@ -791,7 +791,7 @@ interface
<ftype2c> dimension(m,n),intent(in,out,copy,out=q) :: a
<ftype2c> dimension(k),intent(in) :: tau
- integer optional,intent(in),depend(n),check(lwork>=n||lwork==-1) :: lwork=3*n
+ integer optional,intent(in),depend(n),check(lwork>=m||lwork==-1) :: lwork=3*m
<ftype2c> dimension(MAX(lwork,1)),intent(out),depend(lwork) :: work
integer intent(out) :: info
end subroutine <prefix2c>ungrq
View
24 scipy/linalg/tests/test_lapack.py
@@ -4,13 +4,16 @@
#
from numpy.testing import TestCase, run_module_suite, assert_equal, \
- assert_array_almost_equal, assert_
+ assert_array_almost_equal, assert_, assert_raises
import numpy as np
from scipy.linalg import flapack, clapack
from scipy.linalg.lapack import get_lapack_funcs
+REAL_DTYPES = [np.float32, np.float64]
+COMPLEX_DTYPES = [np.complex64, np.complex128]
+DTYPES = REAL_DTYPES + COMPLEX_DTYPES
class TestFlapackSimple(TestCase):
@@ -81,6 +84,25 @@ def test_clapack(self):
#clapack module is empty
pass
+class TestRegression(TestCase):
+
+ def test_ticket_1645(self):
+ # Check that RQ routines have correct lwork
+ for dtype in DTYPES:
+ a = np.zeros((300, 2), dtype=dtype)
+
+ gerqf, = get_lapack_funcs(['gerqf'], [a])
+ assert_raises(Exception, gerqf, a, lwork=2)
+ rq, tau, work, info = gerqf(a)
+
+ if dtype in REAL_DTYPES:
+ orgrq, = get_lapack_funcs(['orgrq'], [a])
+ assert_raises(Exception, orgrq, rq[-2:], tau, lwork=1)
+ orgrq(rq[-2:], tau, lwork=2)
+ elif dtype in COMPLEX_DTYPES:
+ ungrq, = get_lapack_funcs(['ungrq'], [a])
+ assert_raises(Exception, ungrq, rq[-2:], tau, lwork=1)
+ ungrq(rq[-2:], tau, lwork=2)
if __name__ == "__main__":
run_module_suite()

0 comments on commit ed29437

Please sign in to comment.