Repository navigation
Conversation
Accumulate products in double so identical vectors with large integer components retain a cosine similarity of one. Individual products still use long arithmetic before being added to the accumulator. Add regression coverage for identical vectors with ordinary, maximum, and minimum integer components. The two large-component cases fail without the accumulator change. Generated-by: OpenAI Codex
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.
Comparing identical vectors containing three
Integer.MAX_VALUEcomponents returns-0.33333333457509673instead of1.0. Each individual product fits in along, but their sum overflows thelongaccumulator inCosineSimilarity.dot().Accumulate the dot product in
double, as the squared norms already do. Keep thelongmultiplication so each integer product is computed without integer overflow before accumulation. Add a parameterized regression test for identical vectors with components1,Integer.MAX_VALUE, andInteger.MIN_VALUE.Validation:
mvn -Dtest=CosineSimilarityTest testran 7 tests and failed the two large-value cases.mvngoal passes, including the full test suite, Apache RAT, japicmp, Checkstyle, PMD, SpotBugs, and Javadoc generation (OpenJDK 21.0.12.1, Maven 3.9.11).Jira: pending an Apache Jira account. This PR remains a draft until the report can be filed and its issue key linked here and in the commit message.
Checklist from the repository template:
mvn).