Skip to content

Comments

feat: add stats/mskmax#8855

Closed
iampratik13 wants to merge 16 commits intostdlib-js:developfrom
iampratik13:stats/mskmax
Closed

feat: add stats/mskmax#8855
iampratik13 wants to merge 16 commits intostdlib-js:developfrom
iampratik13:stats/mskmax

Conversation

@iampratik13
Copy link
Member

type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:

task: lint_filenames status: passed
task: lint_editorconfig status: passed
task: lint_markdown status: passed
task: lint_package_json status: passed
task: lint_repl_help status: passed
task: lint_javascript_src status: passed
task: lint_javascript_cli status: na
task: lint_javascript_examples status: passed
task: lint_javascript_tests status: passed
task: lint_javascript_benchmarks status: passed
task: lint_python status: na
task: lint_r status: na
task: lint_c_src status: na
task: lint_c_examples status: na
task: lint_c_benchmarks status: na
task: lint_c_tests_fixtures status: na
task: lint_shell status: na
task: lint_typescript_declarations status: passed
task: lint_typescript_tests status: passed
task: lint_license_headers status: passed
Resolves None.

Description
What is the purpose of this pull request?

This pull request:

feat: add stats/mskmax

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

None

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 Dec 6, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Dec 6, 2025

Coverage Report

Package Statements Branches Functions Lines
stats/meanpw $\color{green}164/164$
$\color{green}+100.00%$
$\color{green}2/2$
$\color{green}+100.00%$
$\color{green}0/0$
$\color{green}+100.00%$
$\color{green}164/164$
$\color{green}+100.00%$
stats/mskmax $\color{red}331/333$
$\color{red}-0.60%$
$\color{red}18/19$
$\color{red}-5.26%$
$\color{green}2/2$
$\color{green}+0.00%$
$\color{red}331/333$
$\color{red}-0.60%$

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

@iampratik13 iampratik13 closed this Dec 8, 2025
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Dec 8, 2025
@iampratik13 iampratik13 reopened this Dec 8, 2025
@kgryte kgryte added the Feature Issue or pull request for adding a new feature. label Dec 9, 2025
Signed-off-by: Athan <kgryte@gmail.com>
// VARIABLES //

var idtypes = dtypes( 'real_and_generic' );
var mdtypes = dtypes( 'integer' );
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var mdtypes = dtypes( 'integer' );
var mdtypes = dtypes( 'mask_index_and_generic' );

Copy link
Member

Choose a reason for hiding this comment

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

We can be more strict here. Users should be more explicit when working with mask arrays.

var mdtypes = dtypes( 'integer' );
var odtypes = dtypes( 'real_and_generic' );
var policies = {
'output': 'promoted',
Copy link
Member

Choose a reason for hiding this comment

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

This is not correct. We should not be promoting here. A mask array should have no affect on the output dtype.

The function has the following parameters:

- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or "generic" [data type][@stdlib/ndarray/dtypes].
- **mask**: mask [ndarray][@stdlib/ndarray/ctor]. Must have the same shape as `x`. If a mask element is `0`, the corresponding element in `x` is considered valid. If a mask element is non-zero, the corresponding element in `x` is ignored.
Copy link
Member

Choose a reason for hiding this comment

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

This isn't correct. Namely, x and mask should broadcast together. E.g., I should be able to provide a lower-dimensional mask and apply that to each sub-matrix in x. And similarly, I should be able to provide a lower-dimensional x and apply each mask sub-matrix to that same x.

/**
* Computes the maximum value along one or more ndarray dimensions according to a mask.
*
* @name max
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @name max
* @name mskmax

* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
*
* // Create a mask buffer:
* var mbuf = new Uint8Array( [ 0, 0, 0, 1, 0, 1 ] ); // eslint-disable-line id-length
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* var mbuf = new Uint8Array( [ 0, 0, 0, 1, 0, 1 ] ); // eslint-disable-line id-length
* var mbuf = new Uint8Array( [ 0, 0, 0, 1, 0, 1 ] );

Don't disable lint rules within JSDoc examples like this.

Copy link
Member

Choose a reason for hiding this comment

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

Also, this lint rule is not even applicable here.

* var v = out.get();
* // returns 5.0
*/
var mskmax = factory( table, [ idtypes, mdtypes ], odtypes, policies );
Copy link
Member

Choose a reason for hiding this comment

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

Because of broadcast semantics, it isn't enough to simply call factory here. We need a wrapper which handles broadcast semantics.

The package https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/ext/index-of is NOT an apples-to-apples comparison, but it has the same general idea of a "wrapper" around a "base" implementation.

In short, main.js needs to take the input arrays x and mask, call ndarray/base/maybe-broadcast-arrays on them in order to get arrays which are the same shape, and then pass off to the "base" implementation found in base.js.

Same for assign.js, which needs to take the input arrays x and mask and broadcast them together such that they are the same shape.

Copy link
Member

Choose a reason for hiding this comment

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

Something like

function mskmax( x, mask ) {
    if ( !isndarrayLike( x ) {...}
    if ( !isndarrayLike( mask ) {....}
    arrs = maybeBroadcastArrays( [ x, mask ] );
    if ( arguments.length > 2 ) {
        return base( arrs[ 0 ], arrs[ 1 ], arguments[ 2 ] );
    }
    return base( arrs[ 0 ], arrs[ 1 ] );
}

Copy link
Member

Choose a reason for hiding this comment

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

Your current main.js implementation can serve as base.js.

Copy link
Member

Choose a reason for hiding this comment

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

Obviously this is the first mask package we are doing, so there is a bit more of a learning curve here.

Copy link
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 some initial comments.

@kgryte kgryte added the Needs Changes Pull request which needs changes before being merged. label Dec 9, 2025
iampratik13 and others added 5 commits December 9, 2025 11:49
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
@kgryte
Copy link
Member

kgryte commented Dec 9, 2025

@iampratik13 You've included changes for meanpw in this PR, which is not correct. You need to fix your Git history before this PR can move forward.

@kgryte
Copy link
Member

kgryte commented Dec 9, 2025

Our development guide includes instructions for how to properly sync branches and remotes.

@iampratik13 iampratik13 closed this Dec 9, 2025
@iampratik13 iampratik13 deleted the stats/mskmax branch December 9, 2025 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Issue or pull request for adding a new feature. Needs Changes Pull request which needs changes before being merged. Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants