Repository navigation
Conversation
The optimized sparse L-inf distance took abs(this[i] - v[i]) for the keys stored in this, but for keys stored only in v it compared and assigned the raw value v[i] without the absolute value, even though this[i] is the default 0 there. A negative value therefore never raised the maximum: two vectors that differ only by a negative entry of v reported an L-inf distance of 0, and the sparse overload disagreed with the generic RealVector#getLInfDistance(RealVector) on identical inputs (5 vs 0). getDistance squares the values and getL1Distance takes their absolute value, so only the L-inf variant was affected. Take the absolute value of the entries found only in v before comparing. Regression test added to RealVectorAbstractTest so all three fixtures (Array, generic RealVector, sparse) run it; it fails on the unfixed sparse implementation with expected 5.0 but was 0.0. Assisted-By: DeepSeek-V4.1 (deepseek-ai) via DeepSeek Harness Assisted-By: DeepSeek-V4.1 (deepseek-ai) via DeepSeek Harness Signed-off-by: simpleqt <2015900818@qq.com>
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.
OpenMapRealVector.getLInfDistance(OpenMapRealVector)takesabs(this[i] - v[i])for the keys stored inthis, but for keys stored only invit compares the rawv[i]— althoughthis[i]is the default 0 there. A negative value can never raise the maximum, so two vectors that differ only by a negative entry ofvreport an L-inf distance of 0:The same input against an
ArrayRealVectorreturns 5.0 (the genericRealVector#getLInfDistance(RealVector)path), so the sparse overload also disagrees with the generic one depending on the argument type.getDistancesquares the v-only entries andgetL1Distancetakes their absolute value; only the L-inf variant misses it.Fix: take the absolute value of the entries found only in
vbefore comparing. Regression test added toRealVectorAbstractTest(runs for the Array / generic / sparse fixtures; fails on the unfixed sparse implementation withexpected:<5.0> but was:<0.0>).Local checks:
mvn -pl commons-math-legacy test— 3268 tests, 0 failures (30 skipped, 3 flaky rerun-passes in SimplexOptimizer [POWELL], pre-existing);checkstyle:check— 0 violations. SpotBugs/pmd not run locally.