Skip to content

fix: use offsetOut when the output stride is negative in stats/strided/dmeanstdevpn - #16735

Merged
kgryte merged 1 commit into
stdlib-js:developfrom
devxsubh:fix/stats-strided-dmeanstdevpn-negative-stride-out
Nov 21, 2026
Merged

kgryte merged 1 commit into
stdlib-js:developfrom
devxsubh:fix/stats-strided-dmeanstdevpn-negative-stride-out

Conversation

@devxsubh

Copy link
Copy Markdown
Contributor

Description

What is the purpose of this pull request?

This pull request:

  • fixes the C ndarray API of stats/strided/dmeanstdevpn when the output stride is negative. It took the square root of Out[ 0 ] whenever strideOut < 0, ignoring offsetOut. dmeanvarpn writes the variance to Out[ offsetOut+strideOut ], which is also what the JavaScript implementation reads, so the two disagreed. For example, with out = new Float64Array( 4 ), dmeanstdevpn.ndarray( 4, 1, x, 2, 0, out, -1, 3 ) left the variance (not the standard deviation) in out[ 2 ] with the native addon.
  • adds a test with a negative strideOut and an offsetOut other than -strideOut, to both test.ndarray.js and test.ndarray.native.js. The existing negative-stride test uses strideOut = -2 and offsetOut = 2, where offsetOut+strideOut happens to be 0, so it passed.

The main (non-ndarray) API was not affected, since it passes offsetOut = -strideOut for negative strides.

Related Issues

Does this pull request have any related issues?

No.

Reference Packages

Did the content of this pull request follow one or more existing packages? Answering is optional.

This pull request followed these packages:

  • stats/strided/dmeanstdevpn (its own lib/ndarray.js)

What carried over from the reference(s)?

  • The output index offsetOut + strideOut, from the JavaScript implementation.

What differed, or what did you have to work out yourself?

  • Nothing.

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

Checked in a container (Node 22) with the addon built via node-gyp: the new native test fails on develop ([ 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 of N, correction, strides and offsets.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

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

…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.
@devxsubh
devxsubh requested a review from a team November 20, 2026 19:20
@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. labels Nov 20, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/strided/dmeanstdevpn $\\color{green}374/374$
$\\color{green}+100.00\\%$
$\\color{green}15/15$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}374/374$
$\\color{green}+100.00\\%$

The above coverage report was generated for the changes in this PR.

@kgryte kgryte added difficulty: 1 Low degree of difficulty. Should be straightforward to implement and/or resolve. review: 5 and removed Needs Review A pull request which needs code review. labels Nov 21, 2026
@kgryte
kgryte merged commit b09c612 into stdlib-js:develop Nov 21, 2026
81 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

difficulty: 1 Low degree of difficulty. Should be straightforward to implement and/or resolve. review: 5 Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants