Skip to content

BUG: ?GESVDX and ?GESVDMR3 return INFO = 0 after a failed bidiagonal SVD when singular vectors are requested #1482

Open

Description

@rmlarsen

Disclaimer: This issue was prepared using Claude Code.

Description

If the bidiagonal SVD fails (?BDSVDX or ?BDSVDMR3 returns a positive INFO), ?GESVDX and ?GESVDMR3 return INFO = 0 whenever JOBU = 'V' or JOBVT = 'V', in three of their four paths. After the bidiagonal SVD, the calls that apply the orthogonal transformations to the singular vectors take INFO as their own output argument, and they reset it to zero:

path calls after ?BDSVDX / ?BDSVDMR3 output argument
1 (M much larger than N) ?ORMBR, ?ORMQR, ?ORMBR INFO
2 (M at least N, not much larger) ?ORMBR, ?ORMBR IERR
1t (N much larger than M) ?ORMBR, ?ORMBR, ?ORMLQ INFO
2t (N greater than M, not much larger) ?ORMBR, ?ORMBR INFO

Only path 2 writes IERR, so only path 2 keeps the error. The final undo-scaling calls ?LASCL( 'G', 0, 0, ..., S, MINMN, INFO ) also write INFO. They run only when NS > 0 (IF( ISCL.EQ.1 .AND. NS.GT.0 )), so they matter only if a failure comes back with NS > 0 and A was scaled.

Lines in master (c9967aa):

  • dgesvdx.f: path 1 at 577, 584, 601; path 2 (IERR) at 648, 665; path 1t at 729, 748, 755; path 2t at 800, 819; DLASCL at 830, 833.
  • dgesvdmr3.f: path 1 at 586, 593, 610; path 2 (IERR) at 658, 675; path 1t at 740, 759, 766; path 2t at 812, 831; DLASCL at 842, 845.

The S, C and Z versions have the same structure (with ?UNMBR, ?UNMQR and ?UNMLQ in the complex ones). ?GESVDMR3 was modelled on ?GESVDX and inherited the pattern.

Reproducer

The bidiagonal solvers rarely fail on real input. The example therefore links a stand-in for DBDSVDX ahead of the library, which reports a failure (NS = 0, INFO = 1), and calls DGESVDX once for each path:

subroutine dbdsvdx(uplo, jobz, range, n, d, e, vl, vu, il, iu, ns, s, z, &
                   ldz, work, iwork, info)
  character :: uplo, jobz, range
  integer :: n, il, iu, ns, ldz, info, iwork(*)
  double precision :: d(*), e(*), vl, vu, s(*), z(ldz, *), work(*)
  ns = 0
  info = 1
end subroutine

program demo
  implicit none
  double precision :: a(8, 8), s(8), u(8, 8), vt(8, 8), work(20000)
  integer :: iwork(400), info, ns, k, i, j, q
  character :: ju(3) = ['N', 'V', 'N'], jv(3) = ['N', 'N', 'V']
  integer :: shp(2, 4) = reshape([8, 2, 8, 6, 2, 8, 6, 8], [2, 4])
  do i = 1, 4
    do k = 1, 3
      do j = 1, 8
        a(:, j) = [(1 + mod(3*j + 5*q + 7*j*q, 11) / 11d0, q = 1, 8)]
      end do
      call dgesvdx(ju(k), jv(k), 'A', shp(1, i), shp(2, i), a, 8, 0d0, 0d0, &
                   0, 0, ns, s, u, 8, vt, 8, work, 20000, iwork, info)
      print '(i0,"x",i0," JOBU=",a," JOBVT=",a,": INFO = ",i0)', &
        shp(1, i), shp(2, i), ju(k), jv(k), info
    end do
  end do
end program
M x N (path) JOBU='N', JOBVT='N' JOBU='V' JOBVT='V'
8 x 2 (1) 1 0 0
8 x 6 (2) 1 1 1
2 x 8 (1t) 1 0 0
6 x 8 (2t) 1 0 0

The same program against DGESVDMR3, with a stand-in DBDSVDMR3 that returns INFO = MIN(M,N)+2 and NS = 0 (the value for a non-finite fallback result), gives the same pattern: 4, 8, 4, 8 with JOBU = JOBVT = 'N', and 0 with vectors in paths 1, 1t and 2t.

Suggested fix

Write IERR instead of INFO in the calls that follow the bidiagonal SVD, as path 2 already does, and as ?GESDD does after ?BDSDC.

Checklist

  • I've included a minimal example to reproduce the issue
  • I'd be willing to make a PR to solve this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions