Skip to content
This repository

Incorrect lwork assertion in f2py wrapper for LAPACK xGERQF #222

Merged
merged 1 commit into from almost 2 years ago

2 participants

Pauli Virtanen Ralf Gommers
Pauli Virtanen
Owner
pv commented May 20, 2012

From ticket http://projects.scipy.org/scipy/ticket/1645

Seems straightforward to me, re-verified the sizes from the lapack manpages.

Ralf Gommers rgommers merged commit 63bb175 into from May 20, 2012
Ralf Gommers rgommers closed this May 20, 2012
jnothman jnothman referenced this pull request from a commit May 08, 2013
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

May 20, 2012
Pauli Virtanen BUG: linalg/flapackf: fix lwork size in gerqf/orgrq/ungrq
Thanks to Mike Wimmer for the patch.
ed29437
This page is out of date. Refresh to see the latest.
6  scipy/linalg/flapack.pyf.src
@@ -650,7 +650,7 @@ interface
650 650
      <ftype> dimension(m,n),intent(in,out,copy,out=qr,aligned8) :: a
651 651
      <ftype> dimension(MIN(m,n)),intent(out) :: tau
652 652
 
653  
-     integer optional,intent(in),depend(n),check(lwork>=n||lwork==-1) :: lwork=3*n
  653
+     integer optional,intent(in),depend(n),check(lwork>=m||lwork==-1) :: lwork=3*m
654 654
      <ftype> dimension(MAX(lwork,1)),intent(out),depend(lwork) :: work
655 655
      integer intent(out) :: info
656 656
    end subroutine <prefix>gerqf
@@ -769,7 +769,7 @@ interface
769 769
      <ftype2> dimension(m,n),intent(in,out,copy,out=q) :: a
770 770
      <ftype2> dimension(k),intent(in) :: tau
771 771
 
772  
-     integer optional,intent(in),depend(n),check(lwork>=n||lwork==-1) :: lwork=3*n
  772
+     integer optional,intent(in),depend(n),check(lwork>=m||lwork==-1) :: lwork=3*m
773 773
      <ftype2> dimension(MAX(lwork,1)),intent(out),depend(lwork) :: work
774 774
      integer intent(out) :: info
775 775
    end subroutine <prefix2>orgrq
@@ -791,7 +791,7 @@ interface
791 791
      <ftype2c> dimension(m,n),intent(in,out,copy,out=q) :: a
792 792
      <ftype2c> dimension(k),intent(in) :: tau
793 793
 
794  
-     integer optional,intent(in),depend(n),check(lwork>=n||lwork==-1) :: lwork=3*n
  794
+     integer optional,intent(in),depend(n),check(lwork>=m||lwork==-1) :: lwork=3*m
795 795
      <ftype2c> dimension(MAX(lwork,1)),intent(out),depend(lwork) :: work
796 796
      integer intent(out) :: info
797 797
    end subroutine <prefix2c>ungrq
24  scipy/linalg/tests/test_lapack.py
@@ -4,13 +4,16 @@
4 4
 #
5 5
 
6 6
 from numpy.testing import TestCase, run_module_suite, assert_equal, \
7  
-    assert_array_almost_equal, assert_
  7
+    assert_array_almost_equal, assert_, assert_raises
8 8
 
9 9
 import numpy as np
10 10
 
11 11
 from scipy.linalg import flapack, clapack
12 12
 from scipy.linalg.lapack import get_lapack_funcs
13 13
 
  14
+REAL_DTYPES = [np.float32, np.float64]
  15
+COMPLEX_DTYPES = [np.complex64, np.complex128]
  16
+DTYPES = REAL_DTYPES + COMPLEX_DTYPES
14 17
 
15 18
 class TestFlapackSimple(TestCase):
16 19
 
@@ -81,6 +84,25 @@ def test_clapack(self):
81 84
             #clapack module is empty
82 85
             pass
83 86
 
  87
+class TestRegression(TestCase):
  88
+
  89
+    def test_ticket_1645(self):
  90
+        # Check that RQ routines have correct lwork
  91
+        for dtype in DTYPES:
  92
+            a = np.zeros((300, 2), dtype=dtype)
  93
+
  94
+            gerqf, = get_lapack_funcs(['gerqf'], [a])
  95
+            assert_raises(Exception, gerqf, a, lwork=2)
  96
+            rq, tau, work, info = gerqf(a)
  97
+
  98
+            if dtype in REAL_DTYPES:
  99
+                orgrq, = get_lapack_funcs(['orgrq'], [a])
  100
+                assert_raises(Exception, orgrq, rq[-2:], tau, lwork=1)
  101
+                orgrq(rq[-2:], tau, lwork=2)
  102
+            elif dtype in COMPLEX_DTYPES:
  103
+                ungrq, = get_lapack_funcs(['ungrq'], [a])
  104
+                assert_raises(Exception, ungrq, rq[-2:], tau, lwork=1)
  105
+                ungrq(rq[-2:], tau, lwork=2)
84 106
 
85 107
 if __name__ == "__main__":
86 108
     run_module_suite()
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.