Skip to content

Commit 26db02c

Browse files
committed
Auto-generated commit
1 parent a4212a2 commit 26db02c

File tree

5 files changed

+21
-40
lines changed

5 files changed

+21
-40
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ A total of 40 issues were closed in this release:
695695

696696
<details>
697697

698+
- [`90021da`](https://github.com/stdlib-js/stdlib/commit/90021dae5b5a3b4fbeb5e2366c71b5ddf2095555) - **chore:** clean-up _(by Athan Reines)_
698699
- [`fd99657`](https://github.com/stdlib-js/stdlib/commit/fd99657f0da9706d3c1d7b03c5f9caf97069d3df) - **feat:** add `ndarray/prepend-singleton-dimensions` [(#9478)](https://github.com/stdlib-js/stdlib/pull/9478) _(by Muhammad Haris, Athan Reines)_
699700
- [`f475c84`](https://github.com/stdlib-js/stdlib/commit/f475c843a4b1579eef6533e464e4c16766d7ecdd) - **feat:** add writable parameter to `ndarray/base/expand-dimensions` [(#9476)](https://github.com/stdlib-js/stdlib/pull/9476) _(by Muhammad Haris, Athan Reines)_
700701
- [`da6ecc9`](https://github.com/stdlib-js/stdlib/commit/da6ecc96d7f503e03007eef616703fc7a71587b8) - **chore:** fix JavaScript lint errors [(#9572)](https://github.com/stdlib-js/stdlib/pull/9572) _(by Shreelaxmi Hegde, Athan Reines)_

find/README.md

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ var x = array( [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ], [ 7.0, 8.0 ] ]
5959

6060
// Perform reduction:
6161
var out = find( x, isEven );
62-
// returns <ndarray>
63-
64-
var v = out.get();
65-
// returns 2.0
62+
// returns <ndarray>[ 2.0 ]
6663
```
6764

6865
The function accepts the following arguments:
@@ -82,7 +79,6 @@ By default, the function performs reduction over all all elements in a provided
8279

8380
```javascript
8481
var array = require( '@stdlib/ndarray/array' );
85-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
8682

8783
function isEven( value ) {
8884
return value % 2.0 === 0.0;
@@ -98,17 +94,13 @@ var opts = {
9894

9995
// Perform reduction:
10096
var out = find( x, opts, isEven );
101-
// returns <ndarray>
102-
103-
var v = ndarray2array( out );
104-
// returns [ [ NaN, 2.0 ], [ NaN, 4.0 ] ]
97+
// returns <ndarray>[ [ NaN, 2.0 ], [ NaN, 6.0 ] ]
10598
```
10699

107100
By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having a shape matching only the non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor] (i.e., the reduced dimensions are dropped). To include the reduced dimensions as singleton dimensions in the output [ndarray][@stdlib/ndarray/ctor], set the `keepdims` option to `true`.
108101

109102
```javascript
110103
var array = require( '@stdlib/ndarray/array' );
111-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
112104

113105
function isEven( value ) {
114106
return value % 2.0 === 0.0;
@@ -125,17 +117,13 @@ var opts = {
125117

126118
// Perform reduction:
127119
var out = find( x, opts, isEven );
128-
// returns <ndarray>
129-
130-
var v = ndarray2array( out );
131-
// returns [ [ [ NaN, 2 ], [ NaN, 4 ] ] ]
120+
// returns <ndarray>[ [ [ NaN, 2.0 ] ], [ [ NaN, 6.0 ] ] ]
132121
```
133122

134123
To specify a custom sentinel value to return when no element passes the test, set the `sentinel` option.
135124

136125
```javascript
137126
var array = require( '@stdlib/ndarray/array' );
138-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
139127

140128
function isEven( value ) {
141129
return value % 2.0 === 0.0;
@@ -151,10 +139,7 @@ var opts = {
151139

152140
// Perform reduction:
153141
var out = find( x, opts, isEven );
154-
// returns <ndarray>
155-
156-
var v = out.get();
157-
// returns -999
142+
// returns <ndarray>[ -999 ]
158143
```
159144

160145
To set the `predicate` function execution context, provide a `thisArg`.
@@ -163,7 +148,6 @@ To set the `predicate` function execution context, provide a `thisArg`.
163148

164149
```javascript
165150
var array = require( '@stdlib/ndarray/array' );
166-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
167151

168152
function isEven( value ) {
169153
this.count += 1;
@@ -180,10 +164,7 @@ var ctx = {
180164

181165
// Perform reduction:
182166
var out = find( x, isEven, ctx );
183-
// returns <ndarray>
184-
185-
var v = out.get();
186-
// returns 2.0
167+
// returns <ndarray>[ 2.0 ]
187168

188169
var count = ctx.count;
189170
// returns 2
@@ -196,6 +177,7 @@ Finds the first elements which pass a test implemented by a predicate function a
196177
```javascript
197178
var array = require( '@stdlib/ndarray/array' );
198179
var empty = require( '@stdlib/ndarray/empty' );
180+
var getDType = require( '@stdlib/ndarray/dtype' );
199181

200182
function isEven( value ) {
201183
return value % 2.0 === 0.0;
@@ -207,18 +189,15 @@ var x = array( [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ], [ 7.0, 8.0 ] ]
207189

208190
// Create an output ndarray:
209191
var y = empty( [], {
210-
'dtype': x.dtype
192+
'dtype': getDType( x )
211193
});
212194

213195
// Perform reduction:
214196
var out = find.assign( x, y, isEven );
215-
// returns <ndarray>
197+
// returns <ndarray>[ 2.0 ]
216198

217199
var bool = ( out === y );
218200
// returns true
219-
220-
var v = y.get();
221-
// returns 2.0
222201
```
223202

224203
The function accepts the following arguments:
@@ -237,7 +216,7 @@ The function accepts the following options:
237216
```javascript
238217
var array = require( '@stdlib/ndarray/array' );
239218
var empty = require( '@stdlib/ndarray/empty' );
240-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
219+
var getDType = require( '@stdlib/ndarray/dtype' );
241220

242221
function isEven( value ) {
243222
return value % 2.0 === 0.0;
@@ -249,7 +228,7 @@ var x = array( [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ], [ 7.0, 8.0 ] ]
249228

250229
// Create an output ndarray:
251230
var y = empty( [ 2, 2 ], {
252-
'dtype': x.dtype
231+
'dtype': getDType( x )
253232
});
254233

255234
var opts = {
@@ -258,12 +237,10 @@ var opts = {
258237

259238
// Perform reduction:
260239
var out = find.assign( x, y, opts, isEven );
240+
// returns <ndarray>[ [ NaN, 2.0 ], [ NaN, 6.0 ] ]
261241

262242
var bool = ( out === y );
263243
// returns true
264-
265-
var v = ndarray2array( y );
266-
// returns [ [ NaN, 2.0 ], [ NaN, 4.0 ] ]
267244
```
268245

269246
</section>

find/docs/repl.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
{{alias}}( x[, options], predicate[, thisArg] )
3-
Return a new ndarray containing the first elements which pass a test
3+
Returns a new ndarray containing the first elements which pass a test
44
implemented by a predicate function along one or more ndarray dimensions.
55

66
Parameters
@@ -54,7 +54,7 @@
5454

5555
{{alias}}.assign( x, out[, options], predicate[, thisArg] )
5656
Finds the first elements which pass a test implemented by a predicate
57-
function along one or more ndarray dimensions and assign results to a
57+
function along one or more ndarray dimensions and assigns results to a
5858
provided output ndarray.
5959

6060
Parameters

find/lib/assign.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,24 @@ var getSentinel = require( './sentinel.js' );
5555
* @throws {TypeError} second argument must be an ndarray-like object
5656
* @throws {TypeError} options argument must be an object
5757
* @throws {TypeError} predicate argument must be a function
58+
* @throws {RangeError} dimension indices must not exceed input ndarray bounds
59+
* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions
5860
* @throws {Error} must provide valid options
5961
* @returns {ndarray} output ndarray
6062
*
6163
* @example
6264
* var isEven = require( '@stdlib/assert/is-even' ).isPrimitive;
6365
* var array = require( '@stdlib/ndarray/array' );
6466
* var empty = require( '@stdlib/ndarray/empty' );
67+
* var getDType = require( '@stdlib/ndarray/dtype' );
6568
*
6669
* // Create an input ndarray:
6770
* var x = array( [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ], [ [ 0.0, 6.0 ], [ 7.0, 8.0 ] ] ] );
6871
* // returns <ndarray>
6972
*
7073
* // Create an output ndarray:
7174
* var y = empty( [], {
72-
* 'dtype': x.dtype
75+
* 'dtype': getDType( x )
7376
* });
7477
*
7578
* // Perform reduction:

find/lib/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ function find( x, options, predicate, thisArg ) { // eslint-disable-line stdlib/
101101
}
102102
// Case: find( x, predicate )
103103
if ( nargs < 3 ) {
104-
if ( !isFunction( options ) ) {
105-
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', options ) );
106-
}
107104
cb = options;
105+
if ( !isFunction( cb ) ) {
106+
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', cb ) );
107+
}
108108
}
109109
// Case: find( x, options, predicate, thisArg )
110110
else if ( nargs > 3 ) {

0 commit comments

Comments
 (0)