fix: correct xMaxAbsoluteValue sign and guard numeric edge cases#383
Merged
Conversation
- xMaxAbsoluteValue: seed the accumulator with Math.abs so a negative largest-magnitude element (including at index 0) is handled correctly - xSequentialFillFromTo: size 1 returned [NaN], now returns [from] - xSampling: length 1 returned [NaN], now returns the first element - xDotProduct: fuse into a single zero-allocation loop instead of allocating an intermediate array via xMultiply - xApplyFunctionStr: allocate the output instead of copying values that are immediately overwritten
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #383 +/- ##
=======================================
Coverage 97.13% 97.13%
=======================================
Files 207 207
Lines 4147 4147
Branches 1036 1038 +2
=======================================
Hits 4028 4028
Misses 115 115
Partials 4 4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Audit of the
x/helpers surfaced one real bug and several edge cases.Bugs
xMaxAbsoluteValueseeded its accumulator with the raw first element instead ofMath.abs, so a negative largest-magnitude value (incl. at index 0) was wrong — e.g.[-5, -3]returned3.xSequentialFillFromTo({ size: 1 })andxSampling(array, { length: 1 })divided by zero and returned[NaN]; they now return[from]/ the first element.Perf
xDotProductno longer allocates an intermediate array viaxMultiply— single zero-allocation loop.xApplyFunctionStrallocates the output instead of copying values that are immediately overwritten.Regression tests added for each bug.