Repository navigation
Zero at most N columns of Z in xBDSVDX for RANGE = 'V' - #1488
Merged
Merged
Conversation
For RANGE = 'V', xBDSVDX counts the eigenvalues of the 2N-by-2N Golub-Kahan (TGK) matrix in (-VU,-VL] and zeros that many columns of Z before computing the singular vectors. With VL = 0 every zero singular value contributes two eigenvalues to that count (the pair +0 and -0 of the TGK matrix), so the count, and the number of columns zeroed, can reach 2*N, although xBDSVDX returns at most N singular values and documents that Z needs NS+1 columns. A bidiagonal with zero diagonal entries made it write N+5 to N+8 columns of Z in some tests, and a zero bidiagonal 2*N. xGESVDX passes Z inside WORK, sized for N columns of 2*N entries plus N, so the extra columns overran WORK: DGESVDX for the 30-by-30 zero matrix with JOBU = JOBVT = 'V', RANGE = 'V' and VL = 0 wrote WORK up to entry 3720, while its workspace query returned 2910 (and its minimum LWORK is 2370). CGESVDX and ZGESVDX keep Z in RWORK in the same way. The singular values and vectors were not affected, because xBDSVDX forms the TGK matrix again after zeroing Z. xBDSVDX now zeros MIN(NS,N) columns. The final NS is at most both the count and N, and the columns it fills are zeroed above each block as the computation goes, as before. With this change xBDSVDX writes NS+1 columns of Z in the cases above, and DGESVDX on the zero matrix uses about as much workspace for RANGE = 'V' as for RANGE = 'A' (2130 and 2136 entries). Found by running the test suite with every workspace sized exactly by the routine's own workspace query, followed by a guard. Test: xDRVBD now gives its RANGE = 'V' call of xGESVDX exactly the LWORK that a workspace query returns; the rest of WORK is a guard that must stay unchanged, and an overwritten guard makes test 33 fail. On the parent commit 20 to 32 of the 14820 DBD and SBD driver tests fail per run, all for the zero matrix (JTYPE = 1) with M, N >= 10; with this change they pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 9, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1488 +/- ##
=======================================
Coverage 70.10% 70.10%
=======================================
Files 6213 6213
Lines 498005 498027 +22
Branches 23446 23446
=======================================
+ Hits 349106 349129 +23
Misses 148462 148462
+ Partials 437 436 -1
... and 3 files with indirect coverage changes Continue to review full report in Codecov by Harness.
|
langou
approved these changes
Nov 16, 2026
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AI disclosure: This PR was prepared with Claude Code.
Summary
With RANGE = 'V' and VL = 0,
xBDSVDXwrites up to2*Ncolumns of Z for a bidiagonal matrix with zero singular values, although it returns at most N singular values and documents that Z needs NS+1 columns. ThroughxGESVDX, which keeps Z in WORK (in RWORK for the complex routines), this writes past the end of a workspace of the queried size.DGESVDXon the 30-by-30 zero matrix with JOBU = JOBVT = 'V', RANGE = 'V' and VL = 0 writes WORK up to entry 3720, although its workspace query returns 2910 and its minimum LWORK is 2370.Description
For RANGE = 'V',
xBDSVDXfirst counts the eigenvalues of the 2N-by-2N Golub-Kahan (TGK) matrix in (-VU,-VL] and zeros that many columns of Z. With VL = 0, every zero singular value contributes two eigenvalues to that count, the pair +0 and -0 of the TGK matrix, so the count, and with it the number of columns zeroed, can reach2*N. In tests, a bidiagonal with zero diagonal entries made it write N+5 to N+8 columns, and a zero bidiagonal2*N.The computed singular values and vectors are not affected.
xBDSVDXforms the TGK matrix again after zeroing Z, and the extra columns are never used.Fix
Zero MIN(NS,N) columns. The final NS is at most both the count and N, and the loop already zeroes the columns it fills above each block. With this change
xBDSVDXwrites NS+1 columns of Z in the cases above.DGESVDXon the zero matrix then uses about as much workspace for RANGE = 'V' as for RANGE = 'A': 2130 and 2136 entries.Regression test
xDRVBDnow gives its RANGE = 'V' call ofxGESVDXexactly the LWORK that a workspace query returns. The rest of WORK is a guard that must stay unchanged, and an overwritten guard fails test 33. On master, 20 to 32 of the 14820 DBD and SBD driver tests fail per run, all for the zero matrix (JTYPE = 1) with M, N >= 10. With this change they pass.The bug was found with the tooling described in #1485, which runs the test suite with every workspace sized exactly by the routine's own query.
Test suite
The full test suite passes, configured as in CI (
CBLAS=ON,LAPACKE=ON,LAPACKE_WITH_TMG=ON) with the_64API. All 313 CTest entries pass, with 5739011 LAPACK tests, 11973112 LAPACKE tests, 13539 BLAS tests and 645492 CBLAS tests for each API, and 0 numerical errors and 0 other errors. The builds used GNU Fortran and GCC 15.2.0 withCMAKE_BUILD_TYPE=Release, and the tests ran on x86-64 Linux build workers.Not changed here
xBDSVDXwith RANGE = 'V' and VU below the largest singular values returns INFO =2*N+1, a zero vector norm in its normalization, where RANGE = 'A' succeeds. One example is N = 30 with D(I) = 0 for MOD(I-1,4) = 0 and E(I) = 0 for MOD(I-1,3) = 1, with VL = 0 and VU = 1. This is a separate problem, not changed by this PR.xGESVDXsizes its Z for N columns of2*Nentries plus N, half a column less than the documented NS+1 <= N+1. The lower half of column N+1, whichxBDSVDXuses as scratch when a diagonal entry is zero, overlaps the start of the WORK it passes toxBDSVDX. I could not produce wrong results from this: residuals and orthogonality stay at roundoff for upper bidiagonal matrices with interior zero diagonal entries.Checklist
xBDSVDXnow does what it documents.)