Skip to content

feat: add stats/strided/nancumax#11307

Open
parthodas23 wants to merge 2 commits intostdlib-js:developfrom
parthodas23:rfc/stats-strided-nancumax
Open

feat: add stats/strided/nancumax#11307
parthodas23 wants to merge 2 commits intostdlib-js:developfrom
parthodas23:rfc/stats-strided-nancumax

Conversation

@parthodas23
Copy link
Copy Markdown
Contributor

Resolves #305 .

Description

What is the purpose of this pull request?

This pull request:

  • feat: add stats/strided/nancumax

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

@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. labels Apr 5, 2026
@github-actions github-actions bot mentioned this pull request Apr 5, 2026
@parthodas23 parthodas23 force-pushed the rfc/stats-strided-nancumax branch from b26bdd4 to b303abc Compare April 5, 2026 14:30
@stdlib-bot
Copy link
Copy Markdown
Contributor

stdlib-bot commented Apr 5, 2026

Coverage Report

Package Statements Branches Functions Lines
stats/strided/nancumax $\color{red}297/299$
$\color{green}+0.00%$
$\color{red}22/24$
$\color{green}+0.00%$
$\color{green}3/3$
$\color{green}+0.00%$
$\color{red}297/299$
$\color{green}+0.00%$

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

@kgryte kgryte added Feature Issue or pull request for adding a new feature. difficulty: 3 Likely to be challenging but manageable. review: 5 and removed Needs Review A pull request which needs code review. labels Apr 17, 2026
for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( pkg+':len='+len, f );
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.

@parthodas23 Mind updating this to use string interpolation instead of concatenation? Cheers!

Comment thread lib/node_modules/@stdlib/stats/strided/nancumax/benchmark/benchmark.js Outdated
Comment thread lib/node_modules/@stdlib/stats/strided/nancumax/benchmark/benchmark.js Outdated
Comment thread lib/node_modules/@stdlib/stats/strided/nancumax/benchmark/benchmark.ndarray.js Outdated
Comment thread lib/node_modules/@stdlib/stats/strided/nancumax/benchmark/benchmark.ndarray.js Outdated
for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( pkg+':ndarray:len='+len, f );
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.

Same comment here.

Comment thread lib/node_modules/@stdlib/stats/strided/nancumax/docs/types/index.d.ts Outdated
Comment thread lib/node_modules/@stdlib/stats/strided/nancumax/docs/types/index.d.ts Outdated
Comment thread lib/node_modules/@stdlib/stats/strided/nancumax/docs/types/test.ts Outdated
Comment thread lib/node_modules/@stdlib/stats/strided/nancumax/docs/types/test.ts Outdated
Comment thread lib/node_modules/@stdlib/stats/strided/nancumax/docs/repl.txt Outdated
Comment thread lib/node_modules/@stdlib/stats/strided/nancumax/docs/repl.txt Outdated
* var y = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
*
* var v = nancumax( 6, arraylike2object( x ), 1, 0, arraylike2object( y ), 1, 0 );
* // returns <Object>
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.

This isn't a good use of doctesting, as it doesn't actually validate the implementation.

Comment on lines +50 to +54
* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, NaN, 4.0 ] );
* var y = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
*
* var v = nancumax( 6, arraylike2object( x ), 1, 0, arraylike2object( y ), 1, 0 );
* // returns <Object>
Copy link
Copy Markdown
Member

@kgryte kgryte Apr 17, 2026

Choose a reason for hiding this comment

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

Suggested change
* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, NaN, 4.0 ] );
* var y = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
*
* var v = nancumax( 6, arraylike2object( x ), 1, 0, arraylike2object( y ), 1, 0 );
* // returns <Object>
* var x = [ 2.0, 1.0, 2.0, -2.0, NaN, 4.0 ];
* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
*
* nancumax( 6, arraylike2object( toAccessorArray( x ) ), 1, 0, arraylike2object( toAccessorArray( y ) ), 1, 0 );
* // x => [ 2.0, 2.0, 2.0, 2.0, 2.0, 4.0 ]

Comment on lines +75 to +77
if ( N <= 0 ) {
return y;
}
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.

This check shouldn't be here, as it is unreachable via the main export.

}
ix = offsetX;
iy = offsetY;
max = -Infinity;
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.

Why are you using -Infinity? I thought we discussed this elsewhere. Namely, have a loop which searches for the first non-NaN value. Until that time, fill the output array with NaNs. Once you find the first non-NaN, set max equal to that value and then proceed as you have done below.

Comment thread lib/node_modules/@stdlib/stats/strided/nancumax/lib/main.js Outdated
}
ix = offsetX;
iy = offsetY;
max = -Infinity;
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.

All the same comments.

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.

If you start with -Infinity, how is a user supposed to distinguish between when x contains -Infinities and when it contains NaNs? The answer is they can't. That is why you need to fill with NaNs until the first non-NaN value.

t.end();
});

tape( 'the function computes the cumulative maximum of a strided array', function test( t ) {
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.

You need to add test examples for when the input array starts with NaN values to demonstrate expected behavior.

t.end();
});

tape( 'the function computes the cumulative maximum of a strided array', function test( t ) {
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.

Same comment.

Comment thread lib/node_modules/@stdlib/stats/strided/nancumax/README.md Outdated
Comment thread lib/node_modules/@stdlib/stats/strided/nancumax/README.md Outdated
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
@kgryte kgryte requested a review from a team April 17, 2026 07:18
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Apr 17, 2026
Copy link
Copy Markdown
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

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

Left initial comments.

@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. review: 3 review: 2 and removed Needs Review A pull request which needs code review. review: 5 review: 3 labels Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

difficulty: 3 Likely to be challenging but manageable. Feature Issue or pull request for adding a new feature. Needs Changes Pull request which needs changes before being merged. review: 2 Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFC: add stats/strided/nancumax

3 participants