Conversation
isamax and idamax skipped NaNs entirely, so the index they returned depended on where the NaN sat; icamax and izamax have returned the first one since they were rewritten for arXiv:2207.09281. Give the real pair the same rule, document the contract on all four, and test it. Inf and NaN are built the way ?B1NRM2 in the same testers already builds them, from HUGE, since a constant expression would be folded and rejected at compile time. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1416 +/- ##
==========================================
+ Coverage 69.36% 69.38% +0.02%
==========================================
Files 6122 6122
Lines 486711 486847 +136
Branches 23268 23268
==========================================
+ Hits 337584 337790 +206
+ Misses 148689 148629 -60
+ Partials 438 428 -10
Continue to review full report in Codecov by Harness.
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
icamaxandizamaxwere rewritten for Demmel et al., Proposed Consistent Exception Handling for the BLAS and LAPACK in #1116, and since then return the index of the first NaN, or failing that the first Inf.isamaxandidamaxwere left on the oldIF (ABS(SX(I)) .GT. SMAX)comparison, which is false whenever either side is a NaN, so a NaN is skipped rather than selected. The four routines therefore disagree, and the real pair's answer depends on where in the vector the NaN happens to sit:isamaxbeforeicamaxisamaxafter[0, NaN, 2][NaN, 0, 2][1, Inf, NaN]This PR applies the rule to
isamaxandidamax, states the contract in the Purpose block of all four (it was previously only in inline comments, even on the complex pair), and adds tests.The change
.NOT.(a .LE. b)is true whenais a NaN and whena > b, so a NaN is taken and then returned. For finite data the result is unchanged, including the tie rule: equal elements still leave the earliest index in place.Coverage
Measured locally with gfortran 13.3.0:
BLAS/SRCbuilt-O0 -g --coverage -fno-inline, the four?blat1drivers linked against it and run, thengcov -b -n. Percentages are lines executed and branches taken at least once; the denominators are gcov's, and they grow for the real pair because the change adds code.isamax.f,idamax.ficamax.f90,izamax.f90Benchmark
There is no measurable cost. On gfortran 13.3.0
-O2, x86-64, n = 100000, the newisamaxruns at 0.59x to 0.68x of the old across random, ascending and descending data. The oldIF (ABS(x) .GT. SMAX)lets gfortran emit an unconditionalmaxss, which serialises the loop on a loop-carried latency chain; the new form has nomaxssand a well-predicted branch instead. Only gfortran on x86-64 was timed.