Skip to content

MATH-1698: Avoid boxing in KendallsCorrelation and document signed zeros - #357

Merged
aherbert merged 1 commit into
apache:masterfrom
insaf021:kendall-signed-zero-ties
Nov 19, 2026
Merged

aherbert merged 1 commit into
apache:masterfrom
insaf021:kendall-signed-zero-ties

Conversation

@insaf021

@insaf021 insaf021 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Reworked after the discussion on MATH-1698. Signed zeros stay distinct; the change is now the boxing refactor plus documentation.

The pairs are stored as double[] and ordered with Double.compare instead of being boxed into Pair<Double, Double>. Double.compare returns 0 exactly when Double.equals is true and orders the same way as Double.compareTo, so the sort, the merge-sort swap count and the tie scans give the same results as before.

The class javadoc now states that values are ordered by Double.compare, so -0.0 sorts below 0.0 and the two are not counted as a tie. testSignedZeros pins that: correlation({0.0, -0.0, 1.0}, {1, 2, 3}) is 1/3 and correlation({0.0, -0.0}, {1, 2}) is -1. It passes against both master and this branch.

mvn clean verify javadoc:javadoc -pl commons-math-legacy is green on JDK 21 (3265 tests, 0 Checkstyle violations).

@aherbert

Copy link
Copy Markdown
Contributor

Discussion issue: https://issues.apache.org/jira/browse/MATH-1698

Store the observation pairs as double[] and order them with
Double.compare instead of boxing into Pair<Double, Double>.
Double.compare matches the previous compareTo/equals semantics, so
results are unchanged.

Document that values are ordered by Double.compare, so -0.0 and 0.0
are distinct and not counted as a tie, and add a test for it.
@insaf021
insaf021 force-pushed the kendall-signed-zero-ties branch from 40e0394 to 4ee598c Compare November 19, 2026 18:53
@insaf021 insaf021 changed the title count signed zeros as ties in KendallsCorrelation MATH-1698: Avoid boxing in KendallsCorrelation and document signed zeros Nov 19, 2026
@insaf021

Copy link
Copy Markdown
Contributor Author

Fair point on underflow. The sign carries real information there, and the class is already consistent with itself, so I've dropped the + 0.0.

Reworked along the lines of your comment on MATH-1698. The pairs are now double[] ordered with Double.compare, which matches the old compareTo/equals semantics, so results don't change. The class javadoc now states that -0.0 and 0.0 are distinct. The test pins -0.0 < 0.0 and passes on master as well as this branch.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.23%. Comparing base (f554608) to head (4ee598c).
⚠️ Report is 421 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #357      +/-   ##
============================================
+ Coverage     86.54%   87.23%   +0.69%     
+ Complexity     9787       91    -9696     
============================================
  Files           532      499      -33     
  Lines         35516    33542    -1974     
  Branches       6194     5856     -338     
============================================
- Hits          30738    29262    -1476     
+ Misses         3518     3160     -358     
+ Partials       1260     1120     -140     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aherbert
aherbert merged commit 700d224 into apache:master Nov 19, 2026
12 checks passed
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.

3 participants