Skip to content

Commit 93a748f

Browse files
committed
Auto-generated commit
1 parent 3cd000c commit 93a748f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+28404
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Features
1212

13+
- [`50b84b5`](https://github.com/stdlib-js/stdlib/commit/50b84b54ffdfc65c9c92498f51120ef3a363a69e) - add `ndarray/base/find` [(#7426)](https://github.com/stdlib-js/stdlib/pull/7426)
1314
- [`b7b141b`](https://github.com/stdlib-js/stdlib/commit/b7b141b93a4d030ce23c6ebe50264bd910e5fdf2) - add `ndarray/base/any-by` [(#7664)](https://github.com/stdlib-js/stdlib/pull/7664)
1415
- [`8e8e3a4`](https://github.com/stdlib-js/stdlib/commit/8e8e3a410a266afa887a1c9f9df7f98833bfa4ea) - add `ndarray/with` [(#7971)](https://github.com/stdlib-js/stdlib/pull/7971)
1516
- [`f043c89`](https://github.com/stdlib-js/stdlib/commit/f043c893ac0fe9392f7b764167899a482d84708e) - add `ndarray/base/nullary-strided1d` [(#7772)](https://github.com/stdlib-js/stdlib/pull/7772)
@@ -500,6 +501,7 @@ A total of 24 issues were closed in this release:
500501

501502
<details>
502503

504+
- [`50b84b5`](https://github.com/stdlib-js/stdlib/commit/50b84b54ffdfc65c9c92498f51120ef3a363a69e) - **feat:** add `ndarray/base/find` [(#7426)](https://github.com/stdlib-js/stdlib/pull/7426) _(by Muhammad Haris, Athan Reines)_
503505
- [`9be4cfa`](https://github.com/stdlib-js/stdlib/commit/9be4cfa08c56d4d736bece90bb713d339db3d9cc) - **docs:** update range to match the one used in example file _(by Philipp Burckhardt)_
504506
- [`b7b141b`](https://github.com/stdlib-js/stdlib/commit/b7b141b93a4d030ce23c6ebe50264bd910e5fdf2) - **feat:** add `ndarray/base/any-by` [(#7664)](https://github.com/stdlib-js/stdlib/pull/7664) _(by Muhammad Haris, Athan Reines)_
505507
- [`8e8e3a4`](https://github.com/stdlib-js/stdlib/commit/8e8e3a410a266afa887a1c9f9df7f98833bfa4ea) - **feat:** add `ndarray/with` [(#7971)](https://github.com/stdlib-js/stdlib/pull/7971) _(by Muhammad Haris, Athan Reines)_

base/find/README.md

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# find
22+
23+
> Return the first element in an ndarray which passes a test implemented by a predicate function.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
<!-- eslint-disable no-redeclare -->
36+
37+
```javascript
38+
var find = require( '@stdlib/ndarray/base/find' );
39+
```
40+
41+
<!-- eslint-enable no-redeclare -->
42+
43+
#### find( arrays, predicate\[, thisArg] )
44+
45+
Returns the first element in an ndarray which passes a test implemented by a predicate function.
46+
47+
<!-- eslint-disable max-len -->
48+
49+
```javascript
50+
var Float64Array = require( '@stdlib/array/float64' );
51+
52+
function isEven( value ) {
53+
return value % 2.0 === 0.0;
54+
}
55+
56+
// Create a data buffer:
57+
var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
58+
59+
// Define the shape of the input array:
60+
var shape = [ 3, 1, 2 ];
61+
62+
// Define the array strides:
63+
var sx = [ 4, 4, 1 ];
64+
65+
// Define the index offset:
66+
var ox = 0;
67+
68+
// Create the input ndarray-like object:
69+
var x = {
70+
'dtype': 'float64',
71+
'data': xbuf,
72+
'shape': shape,
73+
'strides': sx,
74+
'offset': ox,
75+
'order': 'row-major'
76+
};
77+
78+
// Create an ndarray-like object containing a sentinel value:
79+
var sentinelValue = {
80+
'dtype': 'float64',
81+
'data': new Float64Array( [ NaN ] ),
82+
'shape': [],
83+
'strides': [ 0 ],
84+
'offset': 0,
85+
'order': 'row-major'
86+
};
87+
88+
// Perform reduction:
89+
var out = find( [ x, sentinelValue ], isEven );
90+
// returns 2.0
91+
```
92+
93+
The function accepts the following arguments:
94+
95+
- **arrays**: array-like object containing an input ndarray and a zero-dimensional ndarray containing a sentinel value. The sentinel value is returned when no element in an input ndarray passes a test implemented by the predicate function.
96+
- **predicate**: predicate function.
97+
- **thisArg**: predicate function execution context (_optional_).
98+
99+
Each provided ndarray should be an object with the following properties:
100+
101+
- **dtype**: data type.
102+
- **data**: data buffer.
103+
- **shape**: dimensions.
104+
- **strides**: stride lengths.
105+
- **offset**: index offset.
106+
- **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style).
107+
108+
The predicate function is provided the following arguments:
109+
110+
- **value**: current array element.
111+
- **indices**: current array element indices.
112+
- **arr**: the input ndarray.
113+
114+
To set the predicate function execution context, provide a `thisArg`.
115+
116+
<!-- eslint-disable no-invalid-this, max-len -->
117+
118+
```javascript
119+
var Float64Array = require( '@stdlib/array/float64' );
120+
121+
function isEven( value ) {
122+
this.count += 1;
123+
return value % 2.0 === 0.0;
124+
}
125+
126+
// Create a data buffer:
127+
var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
128+
129+
// Define the shape of the input array:
130+
var shape = [ 3, 1, 2 ];
131+
132+
// Define the array strides:
133+
var sx = [ 4, 4, 1 ];
134+
135+
// Define the index offset:
136+
var ox = 0;
137+
138+
// Create the input ndarray-like object:
139+
var x = {
140+
'dtype': 'float64',
141+
'data': xbuf,
142+
'shape': shape,
143+
'strides': sx,
144+
'offset': ox,
145+
'order': 'row-major'
146+
};
147+
148+
// Create an ndarray-like object containing a sentinel value:
149+
var sentinelValue = {
150+
'dtype': 'float64',
151+
'data': new Float64Array( [ NaN ] ),
152+
'shape': [],
153+
'strides': [ 0 ],
154+
'offset': 0,
155+
'order': 'row-major'
156+
};
157+
158+
var ctx = {
159+
'count': 0
160+
};
161+
162+
// Perform reduction:
163+
var out = find( [ x, sentinelValue ], isEven, ctx );
164+
// returns 2.0
165+
166+
var count = ctx.count;
167+
// returns 2
168+
```
169+
170+
</section>
171+
172+
<!-- /.usage -->
173+
174+
<section class="notes">
175+
176+
## Notes
177+
178+
- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before performing the operation in order to achieve better performance.
179+
180+
</section>
181+
182+
<!-- /.notes -->
183+
184+
<section class="examples">
185+
186+
## Examples
187+
188+
<!-- eslint no-undef: "error" -->
189+
190+
```javascript
191+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
192+
var Float64Array = require( '@stdlib/array/float64' );
193+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
194+
var find = require( '@stdlib/ndarray/base/find' );
195+
196+
function isEven( value ) {
197+
return value % 2.0 === 0.0;
198+
}
199+
200+
var x = {
201+
'dtype': 'float64',
202+
'data': discreteUniform( 10, 0.0, 10.0, {
203+
'dtype': 'float64'
204+
}),
205+
'shape': [ 5, 2 ],
206+
'strides': [ 2, 1 ],
207+
'offset': 0,
208+
'order': 'row-major'
209+
};
210+
console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
211+
212+
var sv = {
213+
'dtype': 'float64',
214+
'data': new Float64Array( [ NaN ] ),
215+
'shape': [],
216+
'strides': [ 0 ],
217+
'offset': 0,
218+
'order': x.order
219+
};
220+
console.log( 'Sentinel Value: %d', sv.data[ 0 ] );
221+
222+
var out = find( [ x, sv ], isEven );
223+
console.log( out );
224+
```
225+
226+
</section>
227+
228+
<!-- /.examples -->
229+
230+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
231+
232+
<section class="related">
233+
234+
</section>
235+
236+
<!-- /.related -->
237+
238+
<section class="links">
239+
240+
<!-- <related-links> -->
241+
242+
<!-- </related-links> -->
243+
244+
</section>
245+
246+
<!-- /.links -->

0 commit comments

Comments
 (0)