Skip to content

Commit f046230

Browse files
committed
docs: improve doctests for ndarray instances in ndarray/count-if
--- 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: 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 d876e80 commit f046230

6 files changed

Lines changed: 18 additions & 75 deletions

File tree

lib/node_modules/@stdlib/ndarray/count-if/README.md

Lines changed: 6 additions & 27 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 = countIf( x, clbk );
56-
// returns <ndarray>
57-
58-
var v = out.get();
59-
// returns 5
56+
// returns <ndarray>[ 5 ]
6057
```
6158

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

7673
```javascript
7774
var array = require( '@stdlib/ndarray/array' );
78-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
7975

8076
function clbk( value ) {
8177
return value > 0.0;
@@ -90,17 +86,13 @@ var opts = {
9086
'dims': [ 1, 2 ]
9187
};
9288
var out = countIf( x, opts, clbk );
93-
// returns <ndarray>
94-
95-
var v = ndarray2array( out );
96-
// returns [ 2, 2, 1 ]
89+
// returns <ndarray>[ 2, 2, 1 ]
9790
```
9891

9992
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`.
10093

10194
```javascript
10295
var array = require( '@stdlib/ndarray/array' );
103-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
10496

10597
function clbk( value ) {
10698
return value > 0.0;
@@ -116,10 +108,7 @@ var opts = {
116108
'keepdims': true
117109
};
118110
var out = countIf( x, opts, clbk );
119-
// returns <ndarray>
120-
121-
var v = ndarray2array( out );
122-
// returns [ [ [ 2 ] ], [ [ 2 ] ], [ [ 1 ] ] ]
111+
// returns <ndarray>[ [ [ 2 ] ], [ [ 2 ] ], [ [ 1 ] ] ]
123112
```
124113

125114
To set the predicate function execution context, provide a `thisArg`.
@@ -128,7 +117,6 @@ To set the predicate function execution context, provide a `thisArg`.
128117

129118
```javascript
130119
var array = require( '@stdlib/ndarray/array' );
131-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
132120

133121
function clbk( value ) {
134122
this.count += 1;
@@ -146,10 +134,7 @@ var ctx = {
146134

147135
// Perform reduction:
148136
var out = countIf( x, clbk, ctx );
149-
// returns <ndarray>
150-
151-
var v = out.get();
152-
// returns 5
137+
// returns <ndarray>[ 5 ]
153138

154139
var count = ctx.count;
155140
// returns 6
@@ -178,13 +163,10 @@ var y = empty( [], {
178163

179164
// Perform reduction:
180165
var out = countIf.assign( x, y, clbk );
181-
// returns <ndarray>
166+
// returns <ndarray>[ 5 ]
182167

183168
var bool = ( out === y );
184169
// returns true
185-
186-
var v = y.get();
187-
// returns 5
188170
```
189171

190172
The function accepts the following arguments:
@@ -204,7 +186,6 @@ By default, the function performs a reduction over all elements in a provided [`
204186
```javascript
205187
var array = require( '@stdlib/ndarray/array' );
206188
var empty = require( '@stdlib/ndarray/empty' );
207-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
208189

209190
function clbk( value ) {
210191
return value > 0.0;
@@ -224,12 +205,10 @@ var opts = {
224205
'dims': [ 1, 2 ]
225206
};
226207
var out = countIf.assign( x, y, opts, clbk );
208+
// returns <ndarray>[ 2, 2, 1 ]
227209

228210
var bool = ( out === y );
229211
// returns true
230-
231-
var v = ndarray2array( y );
232-
// returns [ 2, 2, 1 ]
233212
```
234213

235214
</section>

lib/node_modules/@stdlib/ndarray/count-if/docs/repl.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@
4747
> y.get()
4848
3
4949
> y = {{alias}}( x, { 'keepdims': true }, clbk )
50-
<ndarray>
51-
> {{alias:@stdlib/ndarray/to-array}}( y )
52-
[ [ 3 ] ]
53-
> y.get( 0, 0 )
54-
3
50+
<ndarray>[ [ 3 ] ]
5551

5652

5753
{{alias}}.assign( x, y[, options], predicate[, thisArg] )
@@ -93,11 +89,9 @@
9389
> var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 1.0 ], [ 0.0, 1.0 ] ] );
9490
> var y = {{alias:@stdlib/ndarray/from-scalar}}( 0, { 'dtype': 'int32' } );
9591
> var out = {{alias}}.assign( x, y, clbk )
96-
<ndarray>
92+
<ndarray>[ 3 ]
9793
> var bool = ( out === y )
9894
true
99-
> y.get()
100-
3
10195

10296
See Also
10397
--------

lib/node_modules/@stdlib/ndarray/count-if/docs/types/index.d.ts

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,7 @@ interface CountIf {
124124
*
125125
* // Perform reduction:
126126
* var out = countIf( x, predicate );
127-
* // returns <ndarray>
128-
*
129-
* var v = out.get();
130-
* // returns 5
127+
* // returns <ndarray>[ 5 ]
131128
*/
132129
<T = unknown, U = unknown>( x: typedndarray<T>, predicate: Predicate<T, U>, thisArg?: ThisParameterType<Predicate<T, U>> ): int32ndarray; // FIXME: update once `int64` dtype support
133130

@@ -167,10 +164,7 @@ interface CountIf {
167164
*
168165
* // Perform reduction:
169166
* var out = countIf( x, {}, predicate );
170-
* // returns <ndarray>
171-
*
172-
* var v = out.get();
173-
* // returns 5
167+
* // returns <ndarray>[ 5 ]
174168
*/
175169
<T = unknown, U = unknown>( x: typedndarray<T>, options: Options, predicate: Predicate<T, U>, thisArg?: ThisParameterType<Predicate<T, U>> ): int32ndarray; // FIXME: update once `int64` dtype support; may require adding support for an output `dtype` option
176170

@@ -216,10 +210,7 @@ interface CountIf {
216210
*
217211
* // Perform reduction:
218212
* var out = countIf.assign( x, y, predicate );
219-
* // returns <ndarray>
220-
*
221-
* var v = out.get();
222-
* // returns 5
213+
* // returns <ndarray>[ 5 ]
223214
*/
224215
assign<T = unknown, U extends typedndarray<unknown> = typedndarray<unknown>, V = unknown>( x: typedndarray<T>, y: U, predicate: Predicate<T, V>, thisArg?: ThisParameterType<Predicate<T, V>> ): U;
225216

@@ -265,10 +256,7 @@ interface CountIf {
265256
*
266257
* // Perform reduction:
267258
* var out = countIf.assign( x, y, {}, predicate );
268-
* // returns <ndarray>
269-
*
270-
* var v = out.get();
271-
* // returns 5
259+
* // returns <ndarray>[ 5 ]
272260
*/
273261
assign<T = unknown, U extends typedndarray<unknown> = typedndarray<unknown>, V = unknown>( x: typedndarray<T>, y: U, options: BaseOptions, predicate: Predicate<T, V>, thisArg?: ThisParameterType<Predicate<T, V>> ): U;
274262
}
@@ -309,10 +297,7 @@ interface CountIf {
309297
*
310298
* // Perform reduction:
311299
* var out = countIf( x, predicate );
312-
* // returns <ndarray>
313-
*
314-
* var v = out.get();
315-
* // returns 5
300+
* // returns <ndarray>[ 5 ]
316301
*
317302
* @example
318303
* var Float64Array = require( '@stdlib/array/float64' );
@@ -345,10 +330,7 @@ interface CountIf {
345330
*
346331
* // Perform reduction:
347332
* var out = countIf.assign( x, y, predicate );
348-
* // returns <ndarray>
349-
*
350-
* var v = out.get();
351-
* // returns 5
333+
* // returns <ndarray>[ 5 ]
352334
*/
353335
declare var countIf: CountIf;
354336

lib/node_modules/@stdlib/ndarray/count-if/lib/assign.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@ var validate = require( './validate.js' );
8181
*
8282
* // Perform reduction:
8383
* var out = assign( x, y, predicate );
84-
* // returns <ndarray>
85-
*
86-
* var v = out.get();
87-
* // returns 5
84+
* // returns <ndarray>[ 5 ]
8885
*/
8986
function assign( x, y, options, predicate, thisArg ) {
9087
var nargs;

lib/node_modules/@stdlib/ndarray/count-if/lib/index.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@
4949
*
5050
* // Perform reduction:
5151
* var out = countIf( x, predicate );
52-
* // returns <ndarray>
53-
*
54-
* var v = out.get();
55-
* // returns 5
52+
* // returns <ndarray>[ 5 ]
5653
*
5754
* @example
5855
* var Float64Array = require( '@stdlib/array/float64' );
@@ -86,10 +83,7 @@
8683
*
8784
* // Perform reduction:
8885
* var out = countIf.assign( x, y, predicate );
89-
* // returns <ndarray>
90-
*
91-
* var v = out.get();
92-
* // returns 5
86+
* // returns <ndarray>[ 5 ]
9387
*/
9488

9589
// MODULES //

lib/node_modules/@stdlib/ndarray/count-if/lib/main.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' );
8787
*
8888
* // Perform reduction:
8989
* var out = countIf( x, predicate );
90-
* // returns <ndarray>
91-
*
92-
* var v = out.get();
93-
* // returns 5
90+
* // returns <ndarray>[ 5 ]
9491
*/
9592
function countIf( x, options, predicate, thisArg ) {
9693
var nargs;

0 commit comments

Comments
 (0)