Repository navigation
MATH-1678: Avoid Canberra distance overflow - #336
hutiefang76 wants to merge 3 commits into
Conversation
Large finite coordinates can overflow the denominator and produce NaN or zero instead of the distance contribution. Scale both coordinates by one half only when their finite magnitudes overflow, while preserving ordinary and non-finite input behavior. Add extreme-value, independent BigDecimal reference, and special-value regressions. Generated-by: DeepSeek (deepseek-v4-flash), Codex
|
The three workflows currently show |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #336 +/- ##
============================================
+ Coverage 86.54% 87.19% +0.64%
+ Complexity 9787 91 -9696
============================================
Files 532 499 -33
Lines 35516 33512 -2004
Branches 6194 5846 -348
============================================
- Hits 30738 29221 -1517
+ Misses 3518 3168 -350
+ Partials 1260 1123 -137 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
The Ubuntu/JDK 17 failure is in I ran those same methods on pristine base AI-generated reply. The baseline results were checked against the actual execution log. |
aherbert
left a comment
There was a problem hiding this comment.
If you rebase on master it should collect the changes to the github macOS runner.
| // Rescale large finite coordinates to avoid intermediate overflow. | ||
| sum += JdkMath.abs(a[i] * 0.5 - b[i] * 0.5) / (absA * 0.5 + absB * 0.5); | ||
| } else { | ||
| sum += num == 0.0 && denom == 0.0 ? 0.0 : num / denom; |
There was a problem hiding this comment.
I don't think numerator can ever be non-zero if the denominator is zero. This check could be:
denom == 0.0 ? 0.0 : num / denom;It is then testing for a[i] == b[i] == 0.
There was a problem hiding this comment.
Changed to denom == 0.0 ? 0.0 : num / denom in 7eaa1d03. A zero sum of the absolute values means both coordinates are zero, so the numerator check was redundant. The 8 Canberra tests pass, including signed zero and subnormal cases. mvn clean verify also passes locally on Java 17/macOS arm64 (3798 tests, 33 skips).
The branch already includes current master a9aabf60 through merge dadaf4cd, including the macos-latest and Zulu/Java 8 runner changes (56a8f696 and a9aabf60). Both are ancestors of this commit. Hosted CI still needs to run on the new head.
AI-generated reply; validation figures are from the local execution logs.
CanberraDistance can return NaN for opposite finite extremes and zero for same-sign large values because intermediate arithmetic overflows. This fixes MATH-1678 by halving the coordinates only when their finite magnitudes overflow the denominator. Ordinary values and the existing NaN/infinity behavior are preserved. Regressions cover both signs, vectors, near-equal large values against an independent BigDecimal reference, subnormals and signed zero.
Validation:
mvn -B clean verify: all 14 reactor modules completed successfully; archived Surefire results contain 3,797 tests, with 33 existing skips and no final failures/errors.AI assistance: DeepSeek and Codex helped implement, review and validate this patch. This description was AI-generated.