Skip to content

Commit

Permalink
Rescale input vector more often to minimize relative error (Reference…
Browse files Browse the repository at this point in the history
…-LAPACK PR 981)
  • Loading branch information
martin-frbg authored Feb 5, 2024
1 parent a4fde2c commit 479e4af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 40 deletions.
30 changes: 10 additions & 20 deletions lapack-netlib/SRC/clarfgp.f
Original file line number Diff line number Diff line change
Expand Up @@ -148,33 +148,23 @@ SUBROUTINE CLARFGP( N, ALPHA, X, INCX, TAU )
ALPHR = REAL( ALPHA )
ALPHI = AIMAG( ALPHA )
*
IF( XNORM.LE.EPS*ABS(ALPHA) ) THEN
IF( XNORM.LE.EPS*ABS(ALPHA) .AND. ALPHI.EQ.ZERO ) THEN
*
* H = [1-alpha/abs(alpha) 0; 0 I], sign chosen so ALPHA >= 0.
*
IF( ALPHI.EQ.ZERO ) THEN
IF( ALPHR.GE.ZERO ) THEN
* When TAU.eq.ZERO, the vector is special-cased to be
* all zeros in the application routines. We do not need
* to clear it.
TAU = ZERO
ELSE
* However, the application routines rely on explicit
* zero checks when TAU.ne.ZERO, and we must clear X.
TAU = TWO
DO J = 1, N-1
X( 1 + (J-1)*INCX ) = ZERO
END DO
ALPHA = -ALPHA
END IF
IF( ALPHR.GE.ZERO ) THEN
* When TAU.eq.ZERO, the vector is special-cased to be
* all zeros in the application routines. We do not need
* to clear it.
TAU = ZERO
ELSE
* Only "reflecting" the diagonal entry to be real and non-negative.
XNORM = SLAPY2( ALPHR, ALPHI )
TAU = CMPLX( ONE - ALPHR / XNORM, -ALPHI / XNORM )
* However, the application routines rely on explicit
* zero checks when TAU.ne.ZERO, and we must clear X.
TAU = TWO
DO J = 1, N-1
X( 1 + (J-1)*INCX ) = ZERO
END DO
ALPHA = XNORM
ALPHA = -ALPHA
END IF
ELSE
*
Expand Down
30 changes: 10 additions & 20 deletions lapack-netlib/SRC/zlarfgp.f
Original file line number Diff line number Diff line change
Expand Up @@ -148,33 +148,23 @@ SUBROUTINE ZLARFGP( N, ALPHA, X, INCX, TAU )
ALPHR = DBLE( ALPHA )
ALPHI = DIMAG( ALPHA )
*
IF( XNORM.LE.EPS*ABS(ALPHA) ) THEN
IF( XNORM.LE.EPS*ABS(ALPHA) .AND. ALPHI.EQ.ZERO ) THEN
*
* H = [1-alpha/abs(alpha) 0; 0 I], sign chosen so ALPHA >= 0.
*
IF( ALPHI.EQ.ZERO ) THEN
IF( ALPHR.GE.ZERO ) THEN
* When TAU.eq.ZERO, the vector is special-cased to be
* all zeros in the application routines. We do not need
* to clear it.
TAU = ZERO
ELSE
* However, the application routines rely on explicit
* zero checks when TAU.ne.ZERO, and we must clear X.
TAU = TWO
DO J = 1, N-1
X( 1 + (J-1)*INCX ) = ZERO
END DO
ALPHA = -ALPHA
END IF
IF( ALPHR.GE.ZERO ) THEN
* When TAU.eq.ZERO, the vector is special-cased to be
* all zeros in the application routines. We do not need
* to clear it.
TAU = ZERO
ELSE
* Only "reflecting" the diagonal entry to be real and non-negative.
XNORM = DLAPY2( ALPHR, ALPHI )
TAU = DCMPLX( ONE - ALPHR / XNORM, -ALPHI / XNORM )
* However, the application routines rely on explicit
* zero checks when TAU.ne.ZERO, and we must clear X.
TAU = TWO
DO J = 1, N-1
X( 1 + (J-1)*INCX ) = ZERO
END DO
ALPHA = XNORM
ALPHA = -ALPHA
END IF
ELSE
*
Expand Down

0 comments on commit 479e4af

Please sign in to comment.