Skip to content

Commit efcde85

Browse files
docs: improve doctests for ndarray instances in
--- 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: 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 908b8bb commit efcde85

7 files changed

Lines changed: 29 additions & 85 deletions

File tree

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

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 0.0, 6.0 ] ] ] );
5353

5454
// Perform reduction:
5555
var out = someBy( x, 2, predicate );
56-
// returns <ndarray>
57-
58-
var v = out.get();
59-
// returns true
56+
// returns <ndarray>[ true ]
6057
```
6158

6259
The function accepts the following arguments:
@@ -76,7 +73,6 @@ By default, the function performs a reduction over all elements in a provided [`
7673

7774
```javascript
7875
var array = require( '@stdlib/ndarray/array' );
79-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
8076

8177
function predicate( value ) {
8278
return value > 0.0;
@@ -92,17 +88,13 @@ var opts = {
9288

9389
// Perform reduction:
9490
var out = someBy( x, 2, opts, predicate );
95-
// returns <ndarray>
96-
97-
var v = ndarray2array( out );
98-
// returns [ true, true ]
91+
// returns <ndarray>[ true, true ]
9992
```
10093

10194
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`.
10295

10396
```javascript
10497
var array = require( '@stdlib/ndarray/array' );
105-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
10698

10799
function predicate( value ) {
108100
return value > 0.0;
@@ -119,10 +111,7 @@ var opts = {
119111

120112
// Perform reduction:
121113
var out = someBy( x, 2, opts, predicate );
122-
// returns <ndarray>
123-
124-
var v = ndarray2array( out );
125-
// returns [ [ [ true, true ] ] ]
114+
// returns <ndarray>[ [ [ true, true ] ] ]
126115
```
127116

128117
To set the predicate function execution context, provide a `thisArg`.
@@ -148,10 +137,7 @@ var ctx = {
148137

149138
// Perform reduction:
150139
var out = someBy( x, 2, predicate, ctx );
151-
// returns <ndarray>
152-
153-
var v = out.get();
154-
// returns true
140+
// returns <ndarray>[ true ]
155141

156142
var count = ctx.count;
157143
// returns 2
@@ -184,9 +170,6 @@ var out = someBy.assign( x, 2, y, predicate );
184170

185171
var bool = ( out === y );
186172
// returns true
187-
188-
var v = y.get();
189-
// returns true
190173
```
191174

192175
The function accepts the following arguments:
@@ -207,7 +190,6 @@ By default, the function performs a reduction over all elements in a provided [`
207190
```javascript
208191
var array = require( '@stdlib/ndarray/array' );
209192
var empty = require( '@stdlib/ndarray/empty' );
210-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
211193

212194
function predicate( value ) {
213195
return value > 0.0;
@@ -231,9 +213,6 @@ var out = someBy.assign( x, 2, y, opts, predicate );
231213

232214
var bool = ( out === y );
233215
// returns true
234-
235-
var v = ndarray2array( y );
236-
// returns [ true, true ]
237216
```
238217

239218
</section>
@@ -263,7 +242,6 @@ var v = ndarray2array( y );
263242
```javascript
264243
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
265244
var isEven = require( '@stdlib/assert/is-even' ).isPrimitive;
266-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
267245
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
268246
var fillBy = require( '@stdlib/ndarray/fill-by' );
269247
var zeros = require( '@stdlib/ndarray/zeros' );
@@ -273,13 +251,13 @@ var x = zeros( [ 2, 4, 5 ], {
273251
'dtype': 'float64'
274252
});
275253
x = fillBy( x, discreteUniform( 0, 10 ) );
276-
console.log( ndarray2array( x ) );
254+
console.log( x );
277255

278256
var n = scalar2ndarray( 4, {
279257
'dtype': 'int8'
280258
});
281259
var y = someBy( x, n, isEven );
282-
console.log( y.get() );
260+
console.log( y );
283261
```
284262

285263
</section>

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,9 @@
4242
> function f ( v ) { return v > 0.0; };
4343
> var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2], [ 3, 4 ] ] );
4444
> var y = {{alias}}( x, 3, f )
45-
<ndarray>
46-
> y.get()
47-
true
45+
<ndarray>[ true ]
4846
> y = {{alias}}( x, 3, { 'keepdims': true }, f )
49-
<ndarray>
50-
> {{alias:@stdlib/ndarray/to-array}}( y )
51-
[ [ true ] ]
52-
> y.get( 0, 0 )
53-
true
47+
<ndarray>[ [ true ] ]
5448

5549

5650
{{alias}}.assign( x, n, y[, options], predicate[, thisArg] )
@@ -97,11 +91,7 @@
9791
> var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2], [ 3, 4 ] ] );
9892
> var y = {{alias:@stdlib/ndarray/from-scalar}}( false );
9993
> var out = {{alias}}.assign( x, 3, y, f )
100-
<ndarray>
101-
> var bool = ( out === y )
102-
true
103-
> y.get()
104-
true
94+
<ndarray>[ true ]
10595

10696
See Also
10797
--------

lib/node_modules/@stdlib/ndarray/some-by/docs/types/index.d.ts

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,7 @@ interface SomeBy {
127127
*
128128
* // Perform reduction:
129129
* var out = someBy( x, 3, isEven );
130-
* // returns <ndarray>
131-
*
132-
* var v = out.get();
133-
* // returns true
130+
* // returns <ndarray>[ true ]
134131
*/
135132
<T = unknown, U extends InputArray<T> = InputArray<T>, ThisArg = unknown>( x: U, n: integerndarray | number, predicate: Predicate<T, U, ThisArg>, thisArg?: ThisParameterType<Predicate<T, U, ThisArg>> ): boolndarray;
136133

@@ -168,10 +165,7 @@ interface SomeBy {
168165
*
169166
* // Perform reduction:
170167
* var out = someBy( x, 3, {}, isEven );
171-
* // returns <ndarray>
172-
*
173-
* var v = out.get();
174-
* // returns true
168+
* // returns <ndarray>[ true ]
175169
*/
176170
<T = unknown, U extends InputArray<T> = InputArray<T>, ThisArg = unknown>( x: U, n: integerndarray | number, options: Options, predicate: Predicate<T, U, ThisArg>, thisArg?: ThisParameterType<Predicate<T, U, ThisArg>> ): boolndarray;
177171

@@ -213,10 +207,7 @@ interface SomeBy {
213207
*
214208
* // Perform reduction:
215209
* var out = someBy.assign( x, 3, y, isEven );
216-
* // returns <ndarray>
217-
*
218-
* var v = out.get();
219-
* // returns true
210+
* // returns <ndarray>[ true ]
220211
*/
221212
assign<T = unknown, U extends InputArray<T> = InputArray<T>, V extends ndarray = ndarray, ThisArg = unknown>( x: ndarray, n: integerndarray | number, y: V, predicate: Predicate<T, U, ThisArg>, thisArg?: ThisParameterType<Predicate<T, U, ThisArg>> ): V;
222213

@@ -260,10 +251,7 @@ interface SomeBy {
260251
*
261252
* // Perform reduction:
262253
* var out = someBy.assign( x, 3, y, {}, isEven );
263-
* // returns <ndarray>
264-
*
265-
* var v = out.get();
266-
* // returns true
254+
* // returns <ndarray>[ true ]
267255
*/
268256
assign<T = unknown, U extends InputArray<T> = InputArray<T>, V extends ndarray = ndarray, ThisArg = unknown>( x: ndarray, n: integerndarray | number, y: V, options: BaseOptions, predicate: Predicate<T, U, ThisArg>, thisArg?: ThisParameterType<Predicate<T, U, ThisArg>> ): V;
269257
}
@@ -302,10 +290,7 @@ interface SomeBy {
302290
*
303291
* // Perform reduction:
304292
* var out = someBy( x, 3, isEven );
305-
* // returns <ndarray>
306-
*
307-
* var v = out.get();
308-
* // returns true
293+
* // returns <ndarray>[ true ]
309294
*
310295
* @example
311296
* var Float64Array = require( '@stdlib/array/float64' );
@@ -335,10 +320,7 @@ interface SomeBy {
335320
*
336321
* // Perform reduction:
337322
* var out = someBy.assign( x, 3, y, isEven );
338-
* // returns <ndarray>
339-
*
340-
* var v = out.get();
341-
* // returns true
323+
* // returns <ndarray>[ true ]
342324
*/
343325
declare var someBy: SomeBy;
344326

lib/node_modules/@stdlib/ndarray/some-by/examples/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
2222
var isEven = require( '@stdlib/assert/is-even' ).isPrimitive;
23-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
2423
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
2524
var fillBy = require( '@stdlib/ndarray/fill-by' );
2625
var zeros = require( '@stdlib/ndarray/zeros' );
@@ -30,10 +29,10 @@ var x = zeros( [ 2, 4, 5 ], {
3029
'dtype': 'float64'
3130
});
3231
x = fillBy( x, discreteUniform( 0, 10 ) );
33-
console.log( ndarray2array( x ) );
32+
console.log( x );
3433

3534
var n = scalar2ndarray( 4, {
3635
'dtype': 'int8'
3736
});
3837
var y = someBy( x, n, isEven );
39-
console.log( y.get() );
38+
console.log( y );

lib/node_modules/@stdlib/ndarray/some-by/lib/assign.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' );
9393
*
9494
* // Perform reduction:
9595
* var out = assign( x, 3, y, isEven );
96-
* // returns <ndarray>
97-
*
98-
* var v = out.get();
99-
* // returns true
96+
* // returns <ndarray>[ true ]
10097
*/
10198
function assign( x, n, y, options, predicate, thisArg ) {
10299
var nargs;

lib/node_modules/@stdlib/ndarray/some-by/lib/index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@
4343
* // Create an input ndarray:
4444
* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' );
4545
*
46+
*function predicate( v ) {
47+
* return v > 0.0;
48+
*}
4649
* // Perform reduction:
47-
* var out = someBy( x, 6 );
48-
* // returns <ndarray>
49-
*
50-
* var v = out.get();
51-
* // returns true
50+
* var out = someBy( x, 6 , predicate );
51+
* // returns <ndarray>[ true ]
5252
*
5353
* @example
5454
* var Float64Array = require( '@stdlib/array/float64' );
@@ -76,12 +76,13 @@
7676
* 'dtype': 'bool'
7777
* });
7878
*
79+
*function predicate( v ) {
80+
* return v > 0.0;
81+
*}
7982
* // Perform reduction:
80-
* var out = someBy.assign( x, 6.0, y );
81-
* // returns <ndarray>
8283
*
83-
* var v = out.get();
84-
* // returns true
84+
* var out = someBy.assign( x, 6.0, y , predicate );
85+
* // returns <ndarray>[ true ]
8586
*/
8687

8788
// MODULES //

lib/node_modules/@stdlib/ndarray/some-by/lib/main.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' );
9696
*
9797
* // Perform reduction:
9898
* var out = someBy( x, 3, isEven );
99-
* // returns <ndarray>
100-
*
101-
* var v = out.get();
102-
* // returns true
99+
* // returns <ndarray>[ true ]
103100
*/
104101
function someBy( x, n, options, predicate, thisArg ) {
105102
var nargs;

0 commit comments

Comments
 (0)