Skip to content

Zero at most N columns of Z in xBDSVDX for RANGE = 'V' - #1488

Merged
langou merged 1 commit into
Reference-LAPACK:masterfrom
rmlarsen:bdsvdx-z-columns
Nov 16, 2026
Merged

langou merged 1 commit into
Reference-LAPACK:masterfrom
rmlarsen:bdsvdx-z-columns

Conversation

@rmlarsen

@rmlarsen rmlarsen commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

AI disclosure: This PR was prepared with Claude Code.

Summary

With RANGE = 'V' and VL = 0, xBDSVDX writes up to 2*N columns 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. Through xGESVDX, which keeps Z in WORK (in RWORK for the complex routines), this writes past the end of a workspace of the queried size. DGESVDX on 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', xBDSVDX first 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 reach 2*N. In tests, a bidiagonal with zero diagonal entries made it write N+5 to N+8 columns, and a zero bidiagonal 2*N.

The computed singular values and vectors are not affected. xBDSVDX forms 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 xBDSVDX writes NS+1 columns of Z in the cases above. DGESVDX on the zero matrix then uses about as much workspace for RANGE = 'V' as for RANGE = 'A': 2130 and 2136 entries.

Regression 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 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 _64 API. 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 with CMAKE_BUILD_TYPE=Release, and the tests ran on x86-64 Linux build workers.

Not changed here

  • For some bidiagonals with zero diagonal entries, xBDSVDX with 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.
  • xGESVDX sizes its Z for N columns of 2*N entries plus N, half a column less than the documented NS+1 <= N+1. The lower half of column N+1, which xBDSVDX uses as scratch when a diagonal entry is zero, overlaps the start of the WORK it passes to xBDSVDX. I could not produce wrong results from this: residuals and orthogonality stay at roundoff for upper bidiagonal matrices with interior zero diagonal entries.

Checklist

  • The documentation has been updated. (Not needed: xBDSVDX now does what it documents.)
  • If the PR solves a specific issue, it is set to be closed on merge. (No tracking issue.)

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>
@codecov

codecov Bot commented Nov 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.61538% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.10%. Comparing base (c9967aa) to head (16d9c16).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
TESTING/EIG/ddrvbd.f 81.81% 2 Missing ⚠️
TESTING/EIG/sdrvbd.f 81.81% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           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     
Components Coverage Δ
BLAS 99.73% <ø> (+0.02%) ⬆️
CBLAS 97.10% <ø> (ø)
LAPACK 83.50% <100.00%> (+<0.01%) ⬆️
LAPACKE 2.17% <ø> (ø)
TMGLIB 55.69% <ø> (ø)
BLAS testing 88.77% <ø> (ø)
CBLAS testing 89.65% <ø> (ø)
LAPACK testing 82.33% <81.81%> (-0.01%) ⬇️
LAPACKE testing ∅ <ø> (∅)
Files with missing lines Coverage Δ
SRC/dbdsvdx.f 88.97% <100.00%> (ø)
SRC/sbdsvdx.f 88.97% <100.00%> (ø)
TESTING/EIG/ddrvbd.f 82.03% <81.81%> (-0.01%) ⬇️
TESTING/EIG/sdrvbd.f 82.03% <81.81%> (-0.01%) ⬇️

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c9967aa...16d9c16. Read the comment docs.

@langou
langou merged commit 902162d into Reference-LAPACK:master Nov 16, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants