Repository navigation
fix: use offsetOut when the output stride is negative in stats/strided/dmeanstdevpn - #16735
Merged
kgryte merged 1 commit intoNov 21, 2026
Conversation
…ided/dmeanstdevpn` The C ndarray API took the square root of `Out[ 0 ]` whenever `strideOut` was negative, ignoring `offsetOut`. The variance is at `Out[ offsetOut+strideOut ]`, as in the JavaScript implementation.
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
kgryte
approved these changes
Nov 21, 2026
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.
Description
This pull request:
stats/strided/dmeanstdevpnwhen the output stride is negative. It took the square root ofOut[ 0 ]wheneverstrideOut < 0, ignoringoffsetOut.dmeanvarpnwrites the variance toOut[ offsetOut+strideOut ], which is also what the JavaScript implementation reads, so the two disagreed. For example, without = new Float64Array( 4 ),dmeanstdevpn.ndarray( 4, 1, x, 2, 0, out, -1, 3 )left the variance (not the standard deviation) inout[ 2 ]with the native addon.strideOutand anoffsetOutother than-strideOut, to bothtest.ndarray.jsandtest.ndarray.native.js. The existing negative-stride test usesstrideOut = -2andoffsetOut = 2, whereoffsetOut+strideOuthappens to be0, so it passed.The main (non-ndarray) API was not affected, since it passes
offsetOut = -strideOutfor negative strides.Related Issues
No.
Reference Packages
This pull request followed these packages:
stats/strided/dmeanstdevpn(its ownlib/ndarray.js)offsetOut + strideOut, from the JavaScript implementation.Questions
No.
Other
Checked in a container (Node 22) with the addon built via
node-gyp: the new native test fails ondevelop([ 0, 0, 6.25, 1.25 ]instead of[ 0, 0, 2.5, 1.25 ]) and passes with this change; all other tests pass; and the JavaScript and C implementations now give identical results across 1800 combinations ofN,correction, strides and offsets.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
Claude Code found the bug while reading the package, wrote the fix and the test, and ran the tests in a container. I reviewed the change and the test results myself.
@stdlib-js/reviewers