Skip to content

feat: add C implementation for stats/base/ndarray/sztest - #15048

Open
aryan7071 wants to merge 3 commits into
stdlib-js:developfrom
aryan7071:add-c-implementation-stats-base-ndarray-sztest
Open

aryan7071 wants to merge 3 commits into
stdlib-js:developfrom
aryan7071:add-c-implementation-stats-base-ndarray-sztest

Conversation

@aryan7071

Copy link
Copy Markdown
Contributor

Resolves a part of #14034

Description

What is the purpose of this pull request?

This pull request:

  • feat: add C implementation for stats/base/ndarray/sztest

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

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.

No.

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.".

{{TODO: add disclosure if applicable}}


@stdlib-js/reviewers

@aryan7071
aryan7071 requested a review from a team September 6, 2026 19:41
@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. and removed Needs Review A pull request which needs code review. labels Sep 6, 2026
@aryan7071
aryan7071 marked this pull request as draft September 6, 2026 19:42
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Sep 6, 2026
@stdlib-bot

stdlib-bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/ndarray/sztest $\\color{green}267/267$
$\\color{green}+100.00\\%$
$\\color{green}7/7$
$\\color{green}+100.00\\%$
$\\color{green}2/2$
$\\color{green}+100.00\\%$
$\\color{green}267/267$
$\\color{green}+100.00\\%$

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

@aryan7071
aryan7071 marked this pull request as ready for review September 12, 2026 20:02
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Sep 12, 2026

@0PrashantYadav0 0PrashantYadav0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking issue #14034 marks the ztest family as blocked on custom-dtype support (the note was added after this PR was opened), and this PR works around that with y.get().toDataView(), as stats/strided/sztest does, so a maintainer needs to confirm the approach. The AI disclosure in the description is still {{TODO: add disclosure if applicable}}.

var x = arrays[ 0 ];
var y = arrays[ 1 ];

addon( getData( x ), serialize( x ), getData( alt ), serialize( alt ), getData( alpha ), serialize( alpha ), getData( mu ), serialize( mu ), getData( sigma ), serialize( sigma ), y.get().toDataView() ); // eslint-disable-line max-len

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the output ndarray has a non-zero offset, the native path writes to the wrong struct. With buf = new ResultsArray( 3 ) and out = new ndarray( Float32Results, buf, [], [ 0 ], 1, 'row-major' ), main.js fills buf.get( 1 ) but native.js fills buf.get( 2 ). With offset 2, it writes past the end of the buffer.

The cause is upstream. At napi/argv-dataview/src/main.c:69, the code adds byte_offset to a pointer that napi_get_dataview_info has already offset. stats/strided/sztest native has the same bug with buf.get( 1 ). Should this wait for that fix, and then add an output-offset case to test/test.native.js?

Comment on lines +93 to +94
static double rand_double( void ) {
return (double)rand() / ( (double)RAND_MAX + 1.0 );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static double rand_double( void ) {
return (double)rand() / ( (double)RAND_MAX + 1.0 );
static float rand_float( void ) {
int r = rand();
return (float)r / ( (float)RAND_MAX + 1.0f );

Also update line 133 to data[ i ] = ( rand_float()*10.0f ) - 5.0f;. Same as #15170 (comment).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review A pull request which needs code review. Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants