Skip to content

Commit 7ab876a

Browse files
committed
fix: apply suggestions from code review
--- 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: 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: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent f19d145 commit 7ab876a

8 files changed

Lines changed: 237 additions & 240 deletions

File tree

lib/node_modules/@stdlib/ndarray/some-by/README.md

Lines changed: 29 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# someBy
2222

23-
> Test whether at least `n` elements in an [`ndarray`][@stdlib/ndarray/ctor] pass a test implemented by a predicate function along one or more dimensions.
23+
> Test whether at least `n` elements along one or more [`ndarray`][@stdlib/ndarray/ctor] dimensions pass a test implemented by a predicate function.
2424
2525
<section class="intro">
2626

@@ -38,32 +38,20 @@ var someBy = require( '@stdlib/ndarray/some-by' );
3838

3939
#### someBy( x, n\[, options], predicate\[, thisArg] )
4040

41-
Tests whether at least `n` elements in an [`ndarray`][@stdlib/ndarray/ctor] pass a test implemented by a predicate function along one or more dimensions.
41+
Tests whether at least `n` elements along one or more [`ndarray`][@stdlib/ndarray/ctor] dimensions pass a test implemented by a predicate function.
4242

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

4545
```javascript
46-
var Float64Array = require( '@stdlib/array/float64' );
47-
var ndarray = require( '@stdlib/ndarray/ctor' );
46+
var array = require( '@stdlib/ndarray/array' );
4847

4948
function predicate( value ) {
5049
return value > 0.0;
5150
}
5251

53-
// Create a data buffer:
54-
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 ] );
55-
56-
// Define the shape of the input array:
57-
var sh = [ 3, 1, 2 ];
58-
59-
// Define the array strides:
60-
var sx = [ 4, 4, 1 ];
61-
62-
// Define the index offset:
63-
var ox = 1;
64-
6552
// Create an input ndarray:
66-
var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' );
53+
var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 0.0, 6.0 ] ] ] );
54+
// returns <ndarray>
6755

6856
// Perform reduction:
6957
var out = someBy( x, 2, predicate );
@@ -76,7 +64,7 @@ console.log( out.get() );
7664
The function accepts the following arguments:
7765

7866
- **x**: input [`ndarray`][@stdlib/ndarray/ctor].
79-
- **n**: number of elements which must pass the test implemented by a predicate function. May be either a scalar or an [`ndarray`][@stdlib/ndarray/ctor].
67+
- **n**: number of elements which must pass the test implemented by a predicate function. May be either a scalar or an [`ndarray`][@stdlib/ndarray/ctor]. Must be [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the non-reduced dimensions of input [`ndarray`][@stdlib/ndarray/ctor]. Must have an integer [data type][@stdlib/ndarray/dtypes].
8068
- **options**: function options (_optional_).
8169
- **predicate**: predicate function.
8270
- **thisArg**: predicate execution context (_optional_).
@@ -88,31 +76,17 @@ The function accepts the following `options`:
8876

8977
By default, the function performs a reduction over all elements in a provided [`ndarray`][@stdlib/ndarray/ctor]. To reduce specific dimensions, set the `dims` option.
9078

91-
<!-- eslint-disable max-len -->
92-
9379
```javascript
94-
var Float64Array = require( '@stdlib/array/float64' );
95-
var ndarray = require( '@stdlib/ndarray/ctor' );
80+
var array = require( '@stdlib/ndarray/array' );
9681
var ndarray2array = require( '@stdlib/ndarray/to-array' );
9782

9883
function predicate( value ) {
9984
return value > 0.0;
10085
}
10186

102-
// Create a data buffer:
103-
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 ] );
104-
105-
// Define the shape of the input array:
106-
var sh = [ 3, 1, 2 ];
107-
108-
// Define the array strides:
109-
var sx = [ 4, 4, 1 ];
110-
111-
// Define the index offset:
112-
var ox = 1;
113-
11487
// Create an input ndarray:
115-
var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' );
88+
var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 0.0, 6.0 ] ] ] );
89+
// returns <ndarray>
11690

11791
var opts = {
11892
'dims': [ 0, 1 ]
@@ -128,31 +102,17 @@ var v = ndarray2array( out );
128102

129103
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`.
130104

131-
<!-- eslint-disable max-len -->
132-
133105
```javascript
134-
var Float64Array = require( '@stdlib/array/float64' );
135-
var ndarray = require( '@stdlib/ndarray/ctor' );
106+
var array = require( '@stdlib/ndarray/array' );
136107
var ndarray2array = require( '@stdlib/ndarray/to-array' );
137108

138109
function predicate( value ) {
139110
return value > 0.0;
140111
}
141112

142-
// Create a data buffer:
143-
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 ] );
144-
145-
// Define the shape of the input array:
146-
var sh = [ 3, 1, 2 ];
147-
148-
// Define the array strides:
149-
var sx = [ 4, 4, 1 ];
150-
151-
// Define the index offset:
152-
var ox = 1;
153-
154113
// Create an input ndarray:
155-
var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' );
114+
var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 0.0, 6.0 ] ] ] );
115+
// returns <ndarray>
156116

157117
var opts = {
158118
'dims': [ 0, 1 ],
@@ -164,36 +124,24 @@ var out = someBy( x, 2, opts, predicate );
164124
// returns <ndarray>
165125

166126
var v = ndarray2array( out );
167-
// returns [[[ true, true ]]]
127+
// returns [ [ [ true, true ] ] ]
168128
```
169129

170130
To set the predicate function execution context, provide a `thisArg`.
171131

172-
<!-- eslint-disable no-invalid-this, max-len -->
132+
<!-- eslint-disable no-invalid-this -->
173133

174134
```javascript
175-
var Float64Array = require( '@stdlib/array/float64' );
176-
var ndarray = require( '@stdlib/ndarray/ctor' );
135+
var array = require( '@stdlib/ndarray/array' );
177136

178137
function predicate( value ) {
179138
this.count += 1;
180139
return value > 0.0;
181140
}
182141

183-
// Create a data buffer:
184-
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 ] );
185-
186-
// Define the shape of the input array:
187-
var sh = [ 3, 1, 2 ];
188-
189-
// Define the array strides:
190-
var sx = [ 4, 4, 1 ];
191-
192-
// Define the index offset:
193-
var ox = 1;
194-
195142
// Create an input ndarray:
196-
var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' );
143+
var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 0.0, 6.0 ] ] ] );
144+
// returns <ndarray>
197145

198146
// Create a context object:
199147
var ctx = {
@@ -213,33 +161,21 @@ var count = ctx.count;
213161

214162
#### someBy.assign( x, n, out\[, options], predicate\[, thisArg] )
215163

216-
Test whether at least `n` elements in an [`ndarray`][@stdlib/ndarray/ctor] pass a test implemented by a predicate function along one or more dimensions and assigns results to a provided output [`ndarray`][@stdlib/ndarray/ctor].
164+
Tests whether at least `n` elements along one or more [`ndarray`][@stdlib/ndarray/ctor] dimensions pass a test implemented by a predicate function and assigns results to a provided output [`ndarray`][@stdlib/ndarray/ctor].
217165

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

220168
```javascript
221-
var Float64Array = require( '@stdlib/array/float64' );
222-
var ndarray = require( '@stdlib/ndarray/ctor' );
169+
var array = require( '@stdlib/ndarray/array' );
223170
var empty = require( '@stdlib/ndarray/empty' );
224171

225172
function predicate( value ) {
226173
return value > 0.0;
227174
}
228175

229-
// Create a data buffer:
230-
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 ] );
231-
232-
// Define the shape of the input array:
233-
var sh = [ 3, 1, 2 ];
234-
235-
// Define the array strides:
236-
var sx = [ 4, 4, 1 ];
237-
238-
// Define the index offset:
239-
var ox = 1;
240-
241176
// Create an input ndarray:
242-
var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' );
177+
var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 0.0, 6.0 ] ] ] );
178+
// returns <ndarray>
243179

244180
// Create an output ndarray:
245181
var y = empty( [], {
@@ -260,7 +196,7 @@ var v = y.get();
260196
The function accepts the following arguments:
261197

262198
- **x**: input [`ndarray`][@stdlib/ndarray/ctor].
263-
- **n**: number of elements which must pass the test implemented by a predicate function. May be either a scalar or an [`ndarray`][@stdlib/ndarray/ctor].
199+
- **n**: number of elements which must pass the test implemented by a predicate function. May be either a scalar or an [`ndarray`][@stdlib/ndarray/ctor]. Must be [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the non-reduced dimensions of input [`ndarray`][@stdlib/ndarray/ctor]. Must have an integer [data type][@stdlib/ndarray/dtypes].
264200
- **out**: output [`ndarray`][@stdlib/ndarray/ctor]. The output [`ndarray`][@stdlib/ndarray/ctor] must have a shape matching the non-reduced dimensions of the input [`ndarray`][@stdlib/ndarray/ctor].
265201
- **options**: function options (_optional_).
266202
- **predicate**: predicate function.
@@ -272,32 +208,18 @@ The function accepts the following `options`:
272208

273209
By default, the function performs a reduction over all elements in a provided [`ndarray`][@stdlib/ndarray/ctor]. To reduce specific dimensions, set the `dims` option.
274210

275-
<!-- eslint-disable max-len -->
276-
277211
```javascript
278-
var Float64Array = require( '@stdlib/array/float64' );
279-
var ndarray = require( '@stdlib/ndarray/ctor' );
212+
var array = require( '@stdlib/ndarray/array' );
280213
var empty = require( '@stdlib/ndarray/empty' );
281214
var ndarray2array = require( '@stdlib/ndarray/to-array' );
282215

283216
function predicate( value ) {
284217
return value > 0.0;
285218
}
286219

287-
// Create a data buffer:
288-
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 ] );
289-
290-
// Define the shape of the input array:
291-
var sh = [ 3, 1, 2 ];
292-
293-
// Define the array strides:
294-
var sx = [ 4, 4, 1 ];
295-
296-
// Define the index offset:
297-
var ox = 1;
298-
299220
// Create an input ndarray:
300-
var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' );
221+
var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 0.0, 6.0 ] ] ] );
222+
// returns <ndarray>
301223

302224
// Create an output ndarray:
303225
var y = empty( [ 2 ], {
@@ -380,6 +302,10 @@ console.log( y.get() );
380302

381303
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor
382304

305+
[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes
306+
307+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes
308+
383309
<!-- <related-links> -->
384310

385311
<!-- </related-links> -->

lib/node_modules/@stdlib/ndarray/some-by/docs/repl.txt

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11

22
{{alias}}( x, n[, options], predicate[, thisArg] )
3-
Tests whether at least `n` elements in an ndarray pass a test implemented by
4-
a predicate function along one or more dimensions.
3+
Tests whether at least `n` elements along one or more ndarray dimensions
4+
pass a test implemented by a predicate function.
55

66
Parameters
77
----------
88
x: ndarray
99
Input ndarray.
1010

11-
n: ndarray|any
11+
n: ndarray|integer
1212
Number of elements which must pass the test implemented by a predicate
13-
function.
13+
function. Must be brodcast compatible with the non-reduced dimensions of
14+
input ndarray.
1415

1516
options: Object (optional)
1617
Function options.
@@ -38,14 +39,9 @@
3839

3940
Examples
4041
--------
41-
> var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] );
42-
> var dt = 'float64';
43-
> var sh = [ 2, 2 ];
44-
> var sx = [ 2, 1 ];
45-
> var ox = 0;
46-
> var ord = 'row-major';
47-
> var x = {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord );
42+
4843
> function f ( v ) { return v > 0.0; };
44+
> var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2], [ 3, 4 ] ] );
4945
> var y = {{alias}}( x, 3, f )
5046
<ndarray>
5147
> y.get()
@@ -59,17 +55,18 @@
5955

6056

6157
{{alias}}.assign( x, n, y[, options], predicate[, thisArg] )
62-
Tests whether at least `n` elements in an ndarray pass a test implemented by
63-
a predicate function along one or more dimensions.
58+
Tests whether at least `n` elements along one or more ndarray dimensions
59+
pass a test implemented by a predicate function.
6460

6561
Parameters
6662
----------
6763
x: ndarray
6864
Input ndarray.
6965

70-
n: ndarray|any
66+
n: ndarray|integer
7167
Number of elements which must pass the test implemented by a predicate
72-
function.
68+
function. Must be brodcast compatible with the non-reduced dimensions of
69+
input ndarray.
7370

7471
y: ndarray
7572
Output ndarray. The output shape must match the shape of the non-reduced
@@ -100,15 +97,10 @@
10097

10198
Examples
10299
--------
103-
> var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] );
104-
> var dt = 'float64';
105-
> var sh = [ 2, 2 ];
106-
> var sx = [ 2, 1 ];
107-
> var ox = 0;
108-
> var ord = 'row-major';
109-
> var x = {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord );
110-
> var y = {{alias:@stdlib/ndarray/from-scalar}}( false );
100+
111101
> function f ( v ) { return v > 0.0 };
102+
> var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2], [ 3, 4 ] ] );
103+
> var y = {{alias:@stdlib/ndarray/from-scalar}}( false );
112104
> var out = {{alias}}.assign( x, 3, y, f )
113105
<ndarray>
114106
> var bool = ( out === y )

0 commit comments

Comments
 (0)