Skip to content

LASYF / LAHEF: zero-pivot column is not copied back from W to A, so blocked SYTRF / HETRF return wrong factors when INFO > 0 #1432

Closed

Description

@Bruun97

When the blocked Bunch-Kaufman panel routine DLASYF meets a column that is exactly zero after the update (MAX(ABSAKK, COLMAX) == ZERO), it sets INFO = K and KP = K, but never copies the updated column from the work matrix W back into A. Column K of A therefore keeps its original, non-updated values. In particular A(K,K) keeps the original diagonal entry instead of the computed pivot D(K,K) = 0.

The result is that DSYTRF returns INFO = K > 0 together with factors where D(K,K) is not zero and L*D*L**T (or U*D*U**T) does not reproduce A. This contradicts the documented meaning of the return code:

> 0: if INFO = i, D(i,i) is exactly zero. The factorization has been completed, but the block diagonal matrix D is exactly singular, and division by zero will occur if it is used to solve a system of equations.

The unblocked routine DSYTF2 is correct, because it works in place. The result of DSYTRF therefore depends on LWORK and N (blocked vs. unblocked path).

Where

SRC/dlasyf.f at master (74d4d63), upper branch around line 270 and lower branch around line 552:

         IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
*
*           Column K is zero or underflow: set INFO and continue
*
            IF( INFO.EQ.0 )
     $         INFO = K
            KP = K
         ELSE

The sibling routines already contain the missing copy. SRC/dlasyf_rook.f (lines 290 and 602) and SRC/dlasyf_rk.f (lines 372 and 681):

            IF( INFO.EQ.0 )
     $         INFO = K
            KP = K
            CALL DCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 )          ! upper
            ...
            CALL DCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 )       ! lower

SRC/zlahef.f has the same problem (lines 288 and 639): A( K, K ) = DBLE( A( K, K ) ) reads the stale value in A instead of the updated one in W.

Minimal example

A is 102-by-102 and diagonal with 0.04, except for a rank-1 leading 2-by-2 block with all entries 0.0625. After eliminating column 1, the updated column 2 is exactly zero, so the correct factorization has D(2,2) = 0 and INFO = 2. No interchanges occur and all pivots are 1-by-1.

Reproduced through SciPy's low-level LAPACK wrappers (SciPy 1.17.1, OpenBLAS 0.3.30, Windows x86_64):

import numpy as np
from scipy.linalg import lapack

n = 102
A = np.diag(np.full(n, 0.04))
A[:2, :2] = 0.0625

lwork_opt = int(lapack.dsytrf_lwork(n, lower=1)[0])

for label, lwork in [("unblocked", n), ("blocked", lwork_opt)]:
    ldu, piv, info = lapack.dsytrf(A.copy(), lower=1, lwork=lwork)
    L = np.tril(ldu, -1) + np.eye(n)          # valid: no interchanges, 1x1 pivots
    R = L @ np.diag(np.diag(ldu)) @ L.T
    print(f"{label:9s} info={info} D(2,2)={ldu[1, 1]:.4f} "
          f"max|L*D*L^T - A|={np.abs(R - A).max():.4f}")

Output:

unblocked info=2 D(2,2)=0.0000 max|L*D*L^T - A|=0.0000
blocked   info=2 D(2,2)=0.0625 max|L*D*L^T - A|=0.0625

The same happens with UPLO = 'U' when the rank-1 block is placed in the trailing 2-by-2 corner (INFO = 101, D(101,101) = 0.0625 instead of 0).

Affected routines

With the same matrix I observe the identical wrong result on the blocked path, and the correct result on the unblocked path, for SSYTRF, DSYTRF, CSYTRF, ZSYTRF, CHETRF and ZHETRF. So SLASYF, DLASYF, CLASYF, ZLASYF, CLAHEF and ZLAHEF all appear to be affected. I have only read the source of dlasyf.f and zlahef.f.

Caveat: my test runs against the LAPACK bundled with OpenBLAS 0.3.30, not a build of Reference-LAPACK master. The source on master shows the same code, but I have not compiled master myself.

Suggested fix

Add the copy that ?LASYF_ROOK and ?LASYF_RK already have to the zero-column branch:

*     upper
            CALL DCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 )
*     lower
            CALL DCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 )

and in ?LAHEF copy the column first and then force the diagonal real, as ?LAHEF_ROOK does.

Impact

Callers that follow the documentation and treat INFO > 0 as "factorization completed, D singular" get silently wrong factors for singular (e.g. positive semidefinite, rank-deficient) input once N is large enough for the blocked path. We hit this through scipy.linalg.ldl, which is used by CVXPY's quad_form for dense PSD matrices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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