8000 feat: add `ndarray/base/find` by headlessNode · Pull Request #7426 · stdlib-js/stdlib · GitHub
[go: up one dir, main page]

Skip to content

feat: add ndarray/base/find #7426

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

Open
wants to merge 35 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b97de57
feat: add ndarray/base/find
headlessNode Jun 20, 2025
dcab5b7
feat: add nd kernels
headlessNode Jun 20, 2025
66764f1
docs: fix return value
headlessNode Jun 20, 2025
12a4b61
fix: lint errors
headlessNode Jun 21, 2025
76a9ba1
fix: lint error
headlessNode Jun 21, 2025
44f5cba
fix: lint error
headlessNode Jun 21, 2025
fa9ef2a
fix: lint errors
headlessNode Jun 21, 2025
d650d02
bench: make consistent & worst case scenario
headlessNode Jun 21, 2025
2ca2802
chore: make consistent
headlessNode Jun 21, 2025
f7fe883
test: add tests upto 2d
headlessNode Jun 21, 2025
a776c3b
refactor: add sentinel cases
headlessNode Jun 25, 2025
c9734b5
test: add 3d tests
headlessNode Jun 25, 2025
79eb09a
refactor: use as sentinel
headlessNode Jun 25, 2025
c62bd4d
docs: apply code review suggestions
headlessNode Jul 2, 2025
5dc4859
bench: apply suggestions from code review
headlessNode Jul 2, 2025
6c4416b
refactor: apply suggestions from code review
headlessNode Jul 2, 2025
4768153
feat: add 4d kernels
headlessNode Jul 2, 2025
f2ee3dc
feat: add 5d kernels
headlessNode Jul 2, 2025
f75fe1b
feat: add 6d kernels
headlessNode Jul 2, 2025
85b845d
feat: add 7d kernels
headlessNode Jul 2, 2025
d7f8d34
feat: add 8d kernels
headlessNode Jul 2, 2025
2abe234
feat: add 9d kernels
headlessNode Jul 2, 2025
eecb8c9
feat: add 10d kernels
headlessNode Jul 2, 2025
a17f0a4
bench: add benchmarks upto 5d
headlessNode Jul 2, 2025
3a31376
bench: add 6d benchmarks
headlessNode Jul 2, 2025
1595c41
bench: add 7d benchmarks
headlessNode Jul 2, 2025
3d2d0cf
bench: add 8d benchmarks
headlessNode Jul 2, 2025
6cd22c0
bench: add 9d benchmarks
headlessNode Jul 2, 2025
48360d7
bench: add 10d benchmarks
headlessNode Jul 2, 2025
b55394c
bench: add 11d benchmarks
headlessNode Jul 2, 2025
239d633
chore: clean-up
kgryte Jul 23, 2025
8b45b53
fix: ensure type parameter can be inferred
kgryte Jul 23, 2025
0c7ec30
Merge branch 'stdlib-js:develop' into ndarray-find
headlessNode Jul 25, 2025
98dd5fd
refactor: complex type test cases
headlessNode Jul 25, 2025
a0ac1ad
test: add 4d tests
headlessNode Jul 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: apply code review suggestions
---
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: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - 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: na
  - task: lint_license_headers
    status: passed
---
  • Loading branch information
headlessNode committed Jul 2, 2025
commit c62bd4d2239fc035cad5d225e525dbad813659d0
58 changes: 29 additions & 29 deletions lib/node_modules/@stdlib/ndarray/base/find/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.

# find

> Return the first element in an ndarray which pass a test implemented by a predicate function.
> Return the first element in an ndarray which passes a test implemented by a predicate function.

<section class="intro">

Expand All @@ -42,14 +42,14 @@ var find = require( '@stdlib/ndarray/base/find' );

#### find( arrays, predicate\[, thisArg] )

Returns the first element in an ndarray which pass a test implemented by a predicate function.
Returns the first element in an ndarray which passes a test implemented by a predicate function.

<!-- eslint-disable max-len -->

```javascript
var Float64Array = require( '@stdlib/array/float64' );

function clbk( value ) {
function isEven( value ) {
return value % 2.0 === 0.0;
}

Expand All @@ -65,16 +65,6 @@ var sx = [ 4, 4, 1 ];
// Define the index offset:
var ox = 0;

// Create the sentinel value ndarray-like object:
var sentinelValue = {
'dtype': 'float64',
'data': new Float64Array( [ NaN ] ),
'shape': [],
'strides': [ 0 ],
'offset': 0,
'order': 'row-major'
};

// Create the input ndarray-like object:
var x = {
'dtype': 'float64',
Expand All @@ -85,14 +75,24 @@ var x = {
'order': 'row-major'
};

// Create the sentinel value ndarray-like object:
var sentinelValue = {
'dtype': 'float64',
'data': new Float64Array( [ NaN ] ),
'shape': [],
'strides': [ 0 ],
'offset': 0,
'order': 'row-major'
};

// Perform reduction:
var out = find( [ x, sentinelValue ], clbk );
var out = find( [ x, sentinelValue ], isEven );
// returns 2.0
```

The function accepts the following arguments:

- **arrays**: array-like object containing an input ndarray and a zero-dimensional sentinel value ndarray.
- **arrays**: array-like object containing an input ndarray and a zero-dimensional ndarray containing a sentinel value which should be returned when no element in an input ndarray passes a test implemented by the predicate function.
- **predicate**: predicate function.
- **thisArg**: predicate function execution context (_optional_).

Expand All @@ -118,7 +118,7 @@ To set the predicate function execution context, provide a `thisArg`.
```javascript
var Float64Array = require( '@stdlib/array/float64' );

function clbk( value ) {
function isEven( value ) {
this.count += 1;
return value % 2.0 === 0.0;
}
Expand All @@ -135,16 +135,6 @@ var sx = [ 4, 4, 1 ];
// Define the index offset:
var ox = 0;

// Create the sentinel value ndarray-like object:
var sentinelValue = {
'dtype': 'float64',
'data': new Float64Array( [ NaN ] ),
'shape': [],
'strides': [ 0 ],
'offset': 0,
'order': 'row-major'
};

// Create the input ndarray-like object:
var x = {
'dtype': 'float64',
Expand All @@ -155,12 +145,22 @@ var x = {
'order': 'row-major'
};

// Create the sentinel value ndarray-like object:
var sentinelValue = {
'dtype': 'float64',
'data': new Float64Array( [ NaN ] ),
'shape': [],
'strides': [ 0 ],
'offset': 0,
'order': 'row-major'
};

var ctx = {
'count': 0
};

// Test elements:
var out = find( [ x, sentinelValue ], clbk, ctx );
var out = find( [ x, sentinelValue ], isEven, ctx );
// returns 2.0

var count = ctx.count;
Expand Down Expand Up @@ -193,7 +193,7 @@ var Float64Array = require( '@stdlib/array/float64' );
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
var find = require( '@stdlib/ndarray/base/find' );

function clbk( value ) {
function isEven( value ) {
return value % 2.0 === 0.0;
}

Expand All @@ -219,7 +219,7 @@ var sv = {
};
console.log( 'Sentinel Value: %d', sv.data[ 0 ] );

var out = find( [ x, sv ], clbk );
var out = find( [ x, sv ], isEven );
console.log( out );
```

Expand Down
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/ndarray/base/find/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@stdlib/ndarray/base/find",
"version": "0.0.0",
"description": "Return the first element in an ndarray which pass a test implemented by a predicate function.",
"description": "Return the first element in an ndarray which passes a test implemented by a predicate function.",
"license": "Apache-2.0",
"author": {
"name": "The Stdlib Authors",
Expand Down
Loading
0