Fix Division-by-Zero in Masked Statistical Functions#1122
Open
JAi-SATHVIK wants to merge 5 commits intofortran-lang:masterfrom
Open
Fix Division-by-Zero in Masked Statistical Functions#1122JAi-SATHVIK wants to merge 5 commits intofortran-lang:masterfrom
JAi-SATHVIK wants to merge 5 commits intofortran-lang:masterfrom
Conversation
…fix-mean-mask-upstream
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1122 +/- ##
==========================================
- Coverage 68.55% 68.53% -0.02%
==========================================
Files 396 396
Lines 12746 12746
Branches 1376 1376
==========================================
- Hits 8738 8736 -2
- Misses 4008 4010 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jalvesz
requested changes
Feb 16, 2026
| #:endif | ||
| mask_) | ||
|
|
||
| if (count(mask_) < 2) then |
Contributor
There was a problem hiding this comment.
Instead of introducing another internal implicit loop (using count) it might be better to store the denominator in its own local variable and check whether the denominator is equal to zero or not to assign NaN. E.g:
denom = dot_product( centeri_, centeri_)*dot_product( centerj_, centerj_)
if (denom<epsilon(0._${k1}$)) then
res(j, i) = ieee_value(1._${k1}$, ieee_quiet_nan)
else
res(j, i) = dot_product( centerj_, centeri_)/sqrt(denom)
end if
same applies elsewhere
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.
Masked statistical functions (mean, variance, correlation, and covariance) currently crash or return
NaNwhen provided with an "all-false" mask. This is caused by a missing guard against zero counts in denominators specifically whencount(mask)is 0 leading to critical division-by-zero errors during runtime.