Skip to content
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

BUG: linalg: fix eigh(1x1 array, driver='evd') f2py check #20516

Merged
merged 2 commits into from
Apr 18, 2024

Conversation

ev-br
Copy link
Member

@ev-br ev-br commented Apr 18, 2024

f2py check was just too strict;
LAPACK docs indicate that for N=1, lwork>=1 is acceptable:

*  LWORK   (input) INTEGER
*          The dimension of the array WORK.
*          If N <= 1,               LWORK must be at least 1.
*          If JOBZ = 'N' and N > 1, LWORK must be at least 2*N+1.
*          If JOBZ = 'V' and N > 1, LWORK must be at least
*                                                1 + 6*N + 2*N**2.

https://www.netlib.org/lapack/explore-3.1.1-html/ssyevd.f.html

closes gh-20512

The issue is not new, observed with scipy 1.9.1 at least.

f2py check was just too strict;
LAPACK docs indicate that for N=1, lwork>=1 is acceptable:

*  LWORK   (input) INTEGER
*          The dimension of the array WORK.
*          If N <= 1,               LWORK must be at least 1.
*          If JOBZ = 'N' and N > 1, LWORK must be at least 2*N+1.
*          If JOBZ = 'V' and N > 1, LWORK must be at least
*                                                1 + 6*N + 2*N**2.

https://www.netlib.org/lapack/explore-3.1.1-html/ssyevd.f.html

closes scipygh-20512
@ev-br ev-br added defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.linalg labels Apr 18, 2024
Copy link
Member

@lucascolley lucascolley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@lucascolley lucascolley added the backport-candidate This fix should be ported by a maintainer to previous SciPy versions. label Apr 18, 2024
@lucascolley lucascolley added this to the 1.13.1 milestone Apr 18, 2024
@ogauthe
Copy link
Contributor

ogauthe commented Apr 18, 2024

Thank you for the quick fix. I found that lwork computation also crashes for size-0 arrays for syevr and syevx. Thanks to #20372 it is no more called in such a case and eigh returns early, so I don't know if it is worth fixing lwork.

@ogauthe
Copy link
Contributor

ogauthe commented Apr 18, 2024

Also, the same issue affects heevd. So I think the same fix should be applied at line 183

@ev-br
Copy link
Member Author

ev-br commented Apr 18, 2024

size-0 arrays are probably not worth it. The invariant is that lapack should never see arrays with .size == 0, they all should be filtered out at the python level.

@ev-br
Copy link
Member Author

ev-br commented Apr 18, 2024

Also, the same issue affects heevd. So I think the same fix should be applied at line 183

Indeed. PR updated.

Copy link
Contributor

@tylerjereddy tylerjereddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified that reverting either of the checks individually is sufficient to trigger regression test failure, so that seems pretty robust.

@tylerjereddy tylerjereddy merged commit 789105f into scipy:main Apr 18, 2024
30 checks passed
@tylerjereddy
Copy link
Contributor

Squash-merged for backporting, thanks.

tylerjereddy pushed a commit to tylerjereddy/scipy that referenced this pull request May 2, 2024
f2py check was just too strict;
LAPACK docs indicate that for N=1, lwork>=1 is acceptable:

*  LWORK   (input) INTEGER
*          The dimension of the array WORK.
*          If N <= 1,               LWORK must be at least 1.
*          If JOBZ = 'N' and N > 1, LWORK must be at least 2*N+1.
*          If JOBZ = 'V' and N > 1, LWORK must be at least
*                                                1 + 6*N + 2*N**2.

https://www.netlib.org/lapack/explore-3.1.1-html/ssyevd.f.html

closes scipygh-20512
@tylerjereddy tylerjereddy mentioned this pull request May 2, 2024
10 tasks
@tylerjereddy tylerjereddy removed the backport-candidate This fix should be ported by a maintainer to previous SciPy versions. label May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.linalg
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: eigh fails for size 1 array with driver=evd
4 participants