Skip to content

*tgex2: loosen swap acceptance threshold to fix false rejections - #1299

Open
jschueller wants to merge 2 commits into
Reference-LAPACK:masterfrom
jschueller:issue1201
Open

*tgex2: loosen swap acceptance threshold to fix false rejections#1299
jschueller wants to merge 2 commits into
Reference-LAPACK:masterfrom
jschueller:issue1201

Conversation

@jschueller

Copy link
Copy Markdown
Collaborator

The weak stability test in TGEX2 rejects a block swap when the off-diagonal block norm BQRA21 exceeds THRESHA = TWENTYEPSSA. For certain matrices (reported by MathWorks from MATLAB's ORDQZ), this threshold is too tight -- BQRA21 can be ~5x larger than TWENTYEPS*SA due to round-off in the preceding QZ steps, even though the swap is mathematically valid (verified via Sylvester equation-based proof).

Increase the safety factor from TWENTY (20) to HUNDRED (100), which fixes all known failing cases (3x3 and 4x4 pencils) while remaining well below the BRQA21 bound that guards against truly invalid swaps.

Closes #1201

@thijssteel

Copy link
Copy Markdown
Collaborator

I don't fully understand "even though the swap is mathematically valid (verified via Sylvester equation-based proof)" Do you mean that the swap was accurate in the provided matlab script?

Also in "BQRA21 can be ~5x larger than TWENTYEPS*SA due to round-off in the preceding QZ steps", I don't really understand what the preceding QZ steps have to do with this.

Increasing the threshold does indeed fix the failures indicated by mathworks, but it misses the underlying issue. LAPACK and the matlab script use slightly different methods.

LAPACK does

  1. calculate Q and Z from sylvester equation
  2. Anew = Q* A Z, Bnew = Q* B Z
  3. Make Bnew upper triangular with either QR or RQ
  4. Apply the same transformation to A
  5. Check residual in A, keep either QR or RQ based reduction depending on which is best

The script does:

  1. calculate Q and Z from sylvester equation
  2. Anew = Q* A Z, Bnew = Q* B Z
  3. Check residual in both A and B

You could certainly argue that since it appears to result in much less failures, we should switch to the method of the script. However, if my assumption is correct and you meant that the swap is accurate because the matlab script indicates good accuracy, then I think that is a step too far. Just because method2 is accurate, does not mean that method1 remains accurate with an increased tolerance.

I think the best solution is a combination of method2 and Daan Camps' work, as I have implemented in LAPACK: tlapack/tlapack#608

@jschueller

jschueller commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator Author

fair enough, instead lets just change the acceptance criterion to check the off-diagonal of both A and B for now, that seems to fix the reported issue, I'll leave it for you to implement the robust change involving the algorithmic rewrite,
what do you think ?

Comment thread SRC/dtgex2.f Outdated
Comment thread SRC/dtgex2.f Outdated
Comment thread SRC/stgex2.f Outdated
The weak stability test in *TGEX2 rejects a block swap when the
off-diagonal block of A (BQRA21 or BRQA21) exceeds THRESHA after the
RQ/QR cleanup that triangularizes B. For certain matrices this cleanup
can perturb the A off-diagonal beyond THRESHA even though the
underlying Sylvester swap is mathematically valid, causing false
rejections (reported by MathWorks from MATLAB's ORDQZ).

Fix by checking the off-diagonal of both A and B from the raw Sylvester
result *before* the RQ/QR cleanup. When both raw off-diagonals are
below their thresholds, accept unconditionally -- the cleanup cannot
trigger a false rejection. The safety factor is kept at TWENTY.

Closes Reference-LAPACK#1201
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.

Issue in ?TGEX2

3 participants