Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add accessor protocol and refactor stats/base/nanmskmax #6161

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

rahulptl165
Copy link
Contributor


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: na
  • 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 #5662 .

Description

What is the purpose of this pull request?

This pull request:

  • Adds new files accessors.js.
  • Modified existing nanmskmax.js.
  • Modified existing ndarray.js.
  • Modified readme.md, benchmark, docs/types, docs/repl.txt, examples, tests files.

Important

function nanmskmax( N, x, strideX, mask, strideMask ) {
	return ndarray( N, x, strideX, stride2offset( N, strideX ), mask, strideMask, stride2offset( N, strideMask ) );
}

Instead of above code in nanmskmax.js and tests files, I have used below code due to eslint warnings about maximum character allowed in a single line.

function nanmskmax( N, x, strideX, mask, strideMask ) {
	var offsetMask = stride2offset( N, strideMask );
	var offsetX = stride2offset( N, strideX );
	return ndarray( N, x, strideX, offsetX, mask, strideMask, offsetMask );
}

If we should not bother about warnings, request changes in review, i will modify it.

Related Issues

This pull request:

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.


@stdlib-js/reviewers

---
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: na
  - 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
---
@stdlib-bot stdlib-bot added Good First PR A pull request resolving a Good First Issue. Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. and removed Good First PR A pull request resolving a Good First Issue. labels Mar 18, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Mar 18, 2025

Coverage Report

Package Statements Branches Functions Lines
stats/base/nanmskmax $\color{green}329/329$
$\color{green}+100.00\%$
$\color{green}42/42$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}329/329$
$\color{green}+100.00\%$

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

@kgryte kgryte requested a review from aayush0325 April 3, 2025 00:02

The `N` and `stride` parameters determine which elements are accessed at runtime. For example, to compute the maximum value of every other element in `x`,
The `N` and stride parameters determine which elements int the strided arrays are accessed at runtime. For example, to compute the maximum value of every other element in `x`,
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
The `N` and stride parameters determine which elements int the strided arrays are accessed at runtime. For example, to compute the maximum value of every other element in `x`,
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the maximum value of every other element in `x`,


```javascript
var floor = require( '@stdlib/math/base/special/floor' );

var x = [ 1.0, 2.0, -7.0, -2.0, 4.0, 3.0, 5.0, 6.0 ];
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 x = [ 1.0, 2.0, -7.0, -2.0, 4.0, 3.0, 5.0, 6.0 ];
var x = [ 1.0, 2.0, -7.0, -2.0, 4.0, 3.0, 5.0, 6.0, NaN ];


```javascript
var floor = require( '@stdlib/math/base/special/floor' );

var x = [ 1.0, 2.0, -7.0, -2.0, 4.0, 3.0, 5.0, 6.0 ];
var mask = [ 0, 0, 0, 0, 0, 0, 1, 1 ];
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 mask = [ 0, 0, 0, 0, 0, 0, 1, 1 ];
var mask = [ 0, 0, 0, 0, 0, 0, 1, 1, 1 ];


var v = nanmskmax( N, x, 2, mask, 2 );
var v = nanmskmax( 4, x, 2, mask, 2 );
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 v = nanmskmax( 4, x, 2, mask, 2 );
var v = nanmskmax( 5, x, 2, mask, 2 );

We should explicitly traverse over the NaN element to show how it is being ignored by the algorithm

@@ -76,17 +73,14 @@ Note that indexing is relative to the first index. To introduce offsets, use [`t
```javascript
var Float64Array = require( '@stdlib/array/float64' );
var Uint8Array = require( '@stdlib/array/uint8' );
var floor = require( '@stdlib/math/base/special/floor' );

var x0 = new Float64Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, 5.0, 6.0 ] );
Copy link
Member

Choose a reason for hiding this comment

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

same comment regarding NaN values in examples

@@ -104,14 +103,13 @@
// Standard Usage:
> var x = [ 1.0, -2.0, 2.0, 4.0, NaN ];
> var mask = [ 0, 0, 0, 1, 0 ];
> {{alias}}.ndarray( x.length, x, 1, 0, mask, 1, 0 )
> {{alias}}.ndarray( 5, x, 1, 0, mask, 1, 0 )
2.0

// Using offset parameter:
> x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, 4.0 ];
Copy link
Member

Choose a reason for hiding this comment

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

same comment regarding NaN values in exaamples

@@ -26,7 +27,7 @@ import nanmskmax = require( './index' );
const x = new Float64Array( 10 );
const mask = new Uint8Array( 10 );

nanmskmax( x.length, x, 1, mask, 1 ); // $ExpectType number
nanmskmax( x.length, new AccessorArray( x ), 1, mask, 1 ); // $ExpectType number
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
nanmskmax( x.length, new AccessorArray( x ), 1, mask, 1 ); // $ExpectType number
nanmskmax( x.length, x, 1, mask, 1 );
nanmskmax( x.length, new AccessorArray( x ), 1, mask, 1 ); // $ExpectType number

don't remove the old test, add a new one for accessor arrays

Copy link
Member

Choose a reason for hiding this comment

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

same comment for the ndarray API below


x = toAccessorArray( x );

v = nanmskmax( 5, x, 2, 0, toAccessorArray( mask ), 2, 0 );
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
v = nanmskmax( 5, x, 2, 0, toAccessorArray( mask ), 2, 0 );
v = nanmskmax( 6, x, 2, 0, toAccessorArray( mask ), 2, 0 );

follow the commented indices given above

Copy link
Member

Choose a reason for hiding this comment

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

same comment for all other instances

@aayush0325
Copy link
Member

kindly also adhere to the file structure that we're trying to follow, your lib directory should only contain a main.js, ndarray.js, accessors.js and index.js, see #6248 for reference

---
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: na
  - task: lint_repl_help
    status: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - 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: na
  - task: lint_typescript_tests
    status: passed
  - task: lint_license_headers
    status: passed
---
@stdlib-bot stdlib-bot added the Good First PR A pull request resolving a Good First Issue. label Apr 6, 2025
@rahulptl165
Copy link
Contributor Author

Hi @aayush0325, I have addressed requested changes. pls review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First PR A pull request resolving a Good First Issue. 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.

[RFC]: refactor and add protocol support to stats/base/nanmskmax
3 participants