From efdff9634f0f43cad2865e2ad113d32a5d7fb160 Mon Sep 17 00:00:00 2001 From: NAKATA Maho Date: Tue, 14 Apr 2026 13:31:24 +0900 Subject: [PATCH] SRC: detect all-zero Y columns in GEDMD scaling Add the missing all-zero column check to the JOBS='Y' scaling path in the GEDMD routines. The existing JOBS='S'/'C' path detects when all columns of X are zero and returns INFO=-8, but the corresponding JOBS='Y' path did not count zero columns of Y or return early when all Y columns are zero. Return INFO=-10 for the all-zero Y case, matching Y as the 10th argument and the existing SCCOLY error handling. Update the routine documentation to describe this condition. --- SRC/cgedmd.f90 | 15 ++++++++++++++- SRC/dgedmd.f90 | 15 ++++++++++++++- SRC/sgedmd.f90 | 15 ++++++++++++++- SRC/zgedmd.f90 | 15 ++++++++++++++- 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/SRC/cgedmd.f90 b/SRC/cgedmd.f90 index 9cc23e81e0..67de2db1c1 100644 --- a/SRC/cgedmd.f90 +++ b/SRC/cgedmd.f90 @@ -117,6 +117,8 @@ !> 'Y' :: The data snapshots matrices X and Y are multiplied !> by a diagonal matrix D so that Y*D has unit !> nonzero columns (in the Euclidean 2-norm) +!> If all columns of Y are zero, the procedure returns +!> with INFO = -10. !> 'N' :: No data scaling. !> \endverbatim !..... @@ -467,7 +469,8 @@ !> \verbatim !> INFO (output) INTEGER !> -i < 0 :: On entry, the i-th argument had an -!> illegal value +!> illegal value. If JOBS == 'Y' and all columns +!> of Y are zero, INFO = -10. !> = 0 :: Successful return. !> = 1 :: Void input. Quick exit (M=0 or N=0). !> = 2 :: The SVD computation of X did not converge. @@ -833,6 +836,7 @@ SUBROUTINE CGEDMD( JOBS, JOBZ, JOBR, JOBF, WHTSVD, & ! The columns of Y will be normalized. ! To prevent overflows, the column norms of Y are ! carefully computed using CLASSQ. + K = 0 DO i = 1, N !RWORK(i) = SCNRM2( M, Y(1,i), 1 ) SSUM = ONE @@ -868,8 +872,17 @@ SUBROUTINE CGEDMD( JOBS, JOBZ, JOBR, JOBF, WHTSVD, & END IF ELSE RWORK(i) = ZERO + K = K + 1 END IF END DO + IF ( K == N ) THEN + ! All columns of Y are zero. Return error code -10. + ! (the 10th input variable had an illegal value) + K = 0 + INFO = -10 + CALL XERBLA('CGEDMD',-INFO) + RETURN + END IF DO i = 1, N ! Now, apply the same scaling to the columns of X. IF ( RWORK(i) > ZERO ) THEN diff --git a/SRC/dgedmd.f90 b/SRC/dgedmd.f90 index 642e2d61b3..e356ffa326 100644 --- a/SRC/dgedmd.f90 +++ b/SRC/dgedmd.f90 @@ -115,6 +115,8 @@ !> 'Y' :: The data snapshots matrices X and Y are multiplied !> by a diagonal matrix D so that Y*D has unit !> nonzero columns (in the Euclidean 2-norm) +!> If all columns of Y are zero, the procedure returns +!> with INFO = -10. !> 'N' :: No data scaling. !> \endverbatim !..... @@ -501,7 +503,8 @@ !> \verbatim !> INFO (output) INTEGER !> -i < 0 :: On entry, the i-th argument had an -!> illegal value +!> illegal value. If JOBS == 'Y' and all columns +!> of Y are zero, INFO = -10. !> = 0 :: Successful return. !> = 1 :: Void input. Quick exit (M=0 or N=0). !> = 2 :: The SVD computation of X did not converge. @@ -854,6 +857,7 @@ SUBROUTINE DGEDMD( JOBS, JOBZ, JOBR, JOBF, WHTSVD, & ! The columns of Y will be normalized. ! To prevent overflows, the column norms of Y are ! carefully computed using DLASSQ. + K = 0 DO i = 1, N !WORK(i) = DNRM2( M, Y(1,i), 1 ) SSUM = ONE @@ -889,8 +893,17 @@ SUBROUTINE DGEDMD( JOBS, JOBZ, JOBR, JOBF, WHTSVD, & END IF ELSE WORK(i) = ZERO + K = K + 1 END IF END DO + IF ( K == N ) THEN + ! All columns of Y are zero. Return error code -10. + ! (the 10th input variable had an illegal value) + K = 0 + INFO = -10 + CALL XERBLA('DGEDMD',-INFO) + RETURN + END IF DO i = 1, N ! Now, apply the same scaling to the columns of X. IF ( WORK(i) > ZERO ) THEN diff --git a/SRC/sgedmd.f90 b/SRC/sgedmd.f90 index 68e85d8210..60b177dc5b 100644 --- a/SRC/sgedmd.f90 +++ b/SRC/sgedmd.f90 @@ -116,6 +116,8 @@ !> 'Y' :: The data snapshots matrices X and Y are multiplied !> by a diagonal matrix D so that Y*D has unit !> nonzero columns (in the Euclidean 2-norm) +!> If all columns of Y are zero, the procedure returns +!> with INFO = -10. !> 'N' :: No data scaling. !> \endverbatim !..... @@ -501,7 +503,8 @@ !> \verbatim !> INFO (output) INTEGER !> -i < 0 :: On entry, the i-th argument had an -!> illegal value +!> illegal value. If JOBS == 'Y' and all columns +!> of Y are zero, INFO = -10. !> = 0 :: Successful return. !> = 1 :: Void input. Quick exit (M=0 or N=0). !> = 2 :: The SVD computation of X did not converge. @@ -854,6 +857,7 @@ SUBROUTINE SGEDMD( JOBS, JOBZ, JOBR, JOBF, WHTSVD, & ! The columns of Y will be normalized. ! To prevent overflows, the column norms of Y are ! carefully computed using SLASSQ. + K = 0 DO i = 1, N !WORK(i) = DNRM2( M, Y(1,i), 1 ) SSUM = ONE @@ -889,8 +893,17 @@ SUBROUTINE SGEDMD( JOBS, JOBZ, JOBR, JOBF, WHTSVD, & END IF ELSE WORK(i) = ZERO + K = K + 1 END IF END DO + IF ( K == N ) THEN + ! All columns of Y are zero. Return error code -10. + ! (the 10th input variable had an illegal value) + K = 0 + INFO = -10 + CALL XERBLA('SGEDMD',-INFO) + RETURN + END IF DO i = 1, N ! Now, apply the same scaling to the columns of X. IF ( WORK(i) > ZERO ) THEN diff --git a/SRC/zgedmd.f90 b/SRC/zgedmd.f90 index 7e40a3f1b6..2b84942e5e 100644 --- a/SRC/zgedmd.f90 +++ b/SRC/zgedmd.f90 @@ -117,6 +117,8 @@ !> 'Y' :: The data snapshots matrices X and Y are multiplied !> by a diagonal matrix D so that Y*D has unit !> nonzero columns (in the Euclidean 2-norm) +!> If all columns of Y are zero, the procedure returns +!> with INFO = -10. !> 'N' :: No data scaling. !> \endverbatim !..... @@ -467,7 +469,8 @@ !> \verbatim !> INFO (output) INTEGER !> -i < 0 :: On entry, the i-th argument had an -!> illegal value +!> illegal value. If JOBS == 'Y' and all columns +!> of Y are zero, INFO = -10. !> = 0 :: Successful return. !> = 1 :: Void input. Quick exit (M=0 or N=0). !> = 2 :: The SVD computation of X did not converge. @@ -833,6 +836,7 @@ SUBROUTINE ZGEDMD( JOBS, JOBZ, JOBR, JOBF, WHTSVD, & ! The columns of Y will be normalized. ! To prevent overflows, the column norms of Y are ! carefully computed using ZLASSQ. + K = 0 DO i = 1, N !RWORK(i) = DZNRM2( M, Y(1,i), 1 ) SSUM = ONE @@ -868,8 +872,17 @@ SUBROUTINE ZGEDMD( JOBS, JOBZ, JOBR, JOBF, WHTSVD, & END IF ELSE RWORK(i) = ZERO + K = K + 1 END IF END DO + IF ( K == N ) THEN + ! All columns of Y are zero. Return error code -10. + ! (the 10th input variable had an illegal value) + K = 0 + INFO = -10 + CALL XERBLA('ZGEDMD',-INFO) + RETURN + END IF DO i = 1, N ! Now, apply the same scaling to the columns of X. IF ( RWORK(i) > ZERO ) THEN