Skip to content

Commit 084389b

Browse files
committed
chore: fix and clean-up
--- 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 3d8ee07 commit 084389b

35 files changed

+1159
-646
lines changed

lib/node_modules/@stdlib/ndarray/base/unary-reduce-subarray-by/README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ The function accepts the following arguments:
101101
- **arrays**: array-like object containing one input ndarray and one output ndarray, followed by any additional ndarray arguments.
102102
- **dims**: list of dimensions over which to perform a reduction.
103103
- **options**: function options which are passed through to `fcn` (_optional_).
104-
- **clbk**: callback function which is passed through to `fcn`.
105-
- **thisArg**: callback execution context which is passed through to `fcn` (_optional_).
104+
- **clbk**: callback function.
105+
- **thisArg**: callback execution context (_optional_).
106106

107107
Each provided ndarray should be an object with the following properties:
108108

@@ -113,7 +113,7 @@ Each provided ndarray should be an object with the following properties:
113113
- **offset**: index offset.
114114
- **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style).
115115

116-
The invoked callback function is provided following arguments:
116+
The invoked callback function is provided the following arguments:
117117

118118
- **value**: input array element.
119119
- **indices**: current array element indices.
@@ -136,14 +136,14 @@ function clbk( value ) {
136136

137137
// Create data buffers:
138138
var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 0.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
139-
var ybuf = filled( false, 3 );
139+
var ybuf = filled( false, 6 );
140140

141141
// Define the array shapes:
142-
var xsh = [ 3, 1, 2 ];
142+
var xsh = [ 3, 2, 2 ];
143143
var ysh = [ 3, 2 ];
144144

145145
// Define the array strides:
146-
var sx = [ 2, 2, 1 ];
146+
var sx = [ 4, 2, 1 ];
147147
var sy = [ 2, 1 ];
148148

149149
// Define the index offsets:
@@ -178,12 +178,14 @@ var ctx = {
178178
unaryReduceSubarrayBy( everyBy, [ x, y ], [ 1 ], clbk, ctx );
179179

180180
var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order );
181-
// returns [ [ true, true ], [ true, true ], [ true, false ] ]
181+
// returns [ [ true, true ], [ true, false ], [ true, true ] ]
182182

183183
var count = ctx.count;
184-
// returns 6
184+
// returns 11
185185
```
186186

187+
#### TODO: document factory method
188+
187189
</section>
188190

189191
<!-- /.usage -->
@@ -197,15 +199,14 @@ var count = ctx.count;
197199
- The reduction function is expected to have the following signature:
198200

199201
```text
200-
fcn( arrays[, options], clbk[, thisArg] )
202+
fcn( arrays[, options], wrappedCallback )
201203
```
202204
203205
where
204206
205207
- **arrays**: array containing a subarray of the input ndarray and any additional ndarray arguments as zero-dimensional ndarrays.
206-
- **options**: function options which are passed through to `fcn` (_optional_).
207-
- **clbk**: callback function which is passed through to `fcn`.
208-
- **thisArg**: callback execution context which is passed through to `fcn` (_optional_).
208+
- **options**: function options (_optional_).
209+
- **wrappedCallback**: callback function. This function is a wrapper around a provided `clbk` argument.
209210
210211
- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before performing a reduction in order to achieve better performance.
211212
@@ -227,30 +228,29 @@ var everyBy = require( '@stdlib/ndarray/base/every-by' );
227228
var unaryReduceSubarrayBy = require( '@stdlib/ndarray/base/unary-reduce-subarray-by' );
228229
229230
function clbk( value ) {
230-
return value > 0;
231+
return value > -3;
231232
}
232233
233-
var N = 10;
234234
var x = {
235235
'dtype': 'generic',
236-
'data': discreteUniform( N, -5, 5, {
236+
'data': discreteUniform( 40, -5, 5, {
237237
'dtype': 'generic'
238238
}),
239-
'shape': [ 3, 1, 2 ],
240-
'strides': [ 1, 3, 3 ],
239+
'shape': [ 2, 5, 2, 2 ],
240+
'strides': [ 1, 2, 10, 20 ],
241241
'offset': 0,
242242
'order': 'column-major'
243243
};
244244
var y = {
245245
'dtype': 'generic',
246-
'data': filled( false, 2 ),
247-
'shape': [ 3, 2 ],
248-
'strides': [ 1, 3 ],
246+
'data': filled( false, 10 ),
247+
'shape': [ 2, 5 ],
248+
'strides': [ 1, 2 ],
249249
'offset': 0,
250250
'order': 'column-major'
251251
};
252252
253-
unaryReduceSubarrayBy( everyBy, [ x, y ], [ 1 ], clbk );
253+
unaryReduceSubarrayBy( everyBy, [ x, y ], [ 2, 3 ], clbk );
254254
255255
console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
256256
console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) );

lib/node_modules/@stdlib/ndarray/base/unary-reduce-subarray-by/docs/repl.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
subarray to a single scalar value. The function should have the
2727
following signature:
2828

29-
fcn( arrays[, options], clbk[, thisArg ] )
29+
fcn( arrays[, options], wrappedCallback )
3030

3131
where
3232

3333
- arrays: array containing a subarray of the input ndarray and any
3434
additional ndarray arguments as zero-dimensional ndarrays.
3535
- options: function options.
36-
- clbk: callback function.
37-
- thisArg: callback execution context.
36+
- wrappedCallbac: callback function. This function is a wrapper around a
37+
provided `clbk` argument.
3838

3939
arrays: ArrayLikeObject<ndarray>
4040
Array-like object containing one input ndarray and one output ndarray,
@@ -72,7 +72,7 @@
7272
// Define a trivial reduction function...
7373
> function fcn( arrays, clbk, thisArg ) {
7474
... var v = arrays[0].data[ arrays[0].offset ];
75-
... return clbk.call( thisArg, v, 0, arrays[0].ref );
75+
... return clbk.call( thisArg, v, [ 0 ], arrays[0] );
7676
... };
7777

7878
// Using minimal ndarray-like objects...

lib/node_modules/@stdlib/ndarray/base/unary-reduce-subarray-by/docs/types/index.d.ts

Lines changed: 91 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,48 +24,121 @@ import { ArrayLike } from '@stdlib/types/array';
2424
import { typedndarray } from '@stdlib/types/ndarray';
2525

2626
/**
27-
* Returns the result of the callback function.
27+
* Input ndarray.
28+
*/
29+
type InputArray<T> = typedndarray<T>;
30+
31+
/**
32+
* Output ndarray.
33+
*/
34+
type OutputArray<U> = typedndarray<U>;
35+
36+
/**
37+
* Additional ndarray arguments.
38+
*/
39+
type AdditionalArray<V> = typedndarray<V>;
40+
41+
/**
42+
* ndarray arguments.
43+
*/
44+
type ListOfArrays<T, U, V> = [ InputArray<T>, OutputArray<U>, ...Array<AdditionalArray<V>> ];
45+
46+
/**
47+
* ndarrays arguments passed to reduction function.
48+
*/
49+
type ReductionArrays<T, V> = [ InputArray<T>, ...Array<AdditionalArray<V>> ];
50+
51+
/**
52+
* Callback invoked for each ndarray element.
2853
*
29-
* @returns result of the callback function
54+
* @returns output value
3055
*/
31-
type Nullary<U> = ( this: U ) => unknown;
56+
type Nullary<W, ThisArg> = ( this: ThisArg ) => W;
3257

3358
/**
3459
* Returns the results of the callback function.
3560
*
3661
* @param value - current array element
37-
* @returns result of the callback function
62+
* @returns output value
3863
*/
39-
type Unary<T, U> = ( this: U, value: T ) => unknown;
64+
type Unary<T, W, ThisArg> = ( this: ThisArg, value: T ) => W;
4065

4166
/**
42-
* Returns the result of the callback function.
67+
* Callback invoked for each ndarray element.
4368
*
4469
* @param value - current array element
4570
* @param indices - current array element indices
46-
* @returns result of the callback function
71+
* @returns output value
4772
*/
48-
type Binary<T, U> = ( this: U, value: T, indices: Array<number> ) => unknown;
73+
type Binary<T, W, ThisArg> = ( this: ThisArg, value: T, indices: Array<number> ) => W;
4974

5075
/**
51-
* Returns the result of the callback function.
76+
* Callback invoked for each ndarray element.
5277
*
5378
* @param value - current array element
5479
* @param indices - current array element indices
5580
* @param arr - input array
56-
* @returns result of the callback function
81+
* @returns output value
5782
*/
58-
type Ternary<T, U> = ( this: U, value: T, indices: Array<number>, arr: typedndarray<T> ) => unknown;
83+
type Ternary<T, W, ThisArg> = ( this: ThisArg, value: T, indices: Array<number>, arr: typedndarray<T> ) => W;
5984

6085
/**
61-
* Returns the result of the callback function.
86+
* Callback invoked for each ndarray element.
6287
*
6388
* @param value - current array element
6489
* @param indices - current array element indices
6590
* @param arr - input array
66-
* @returns result of the callback function
91+
* @returns output value
92+
*/
93+
type Callback<T, W, ThisArg> = Nullary<W, ThisArg> | Unary<T, W, ThisArg> | Binary<T, W, ThisArg> | Ternary<T, W, ThisArg>;
94+
95+
/**
96+
* Unary reduction function.
97+
*
98+
* @param arrays - list of ndarrays
99+
* @param clbk - callback function
100+
* @returns reduction result
67101
*/
68-
type Callback<T, U> = Nullary<U> | Unary<T, U> | Binary<T, U> | Ternary<T, U>;
102+
type UnaryReductionFcn<T, U, W> = ( arrays: [ typedndarray<T> ], clbk: Callback<T, W, unknown> ) => U;
103+
104+
/**
105+
* Unary reduction function.
106+
*
107+
* @param arrays - list of ndarrays
108+
* @param options - function options
109+
* @param clbk - callback function
110+
* @returns reduction result
111+
*/
112+
type UnaryReductionFcnWithOptions<T, U, W> = ( arrays: [ typedndarray<T> ], options: Object, clbk: Callback<T, W, unknown> ) => U;
113+
114+
/**
115+
* Reduction function.
116+
*
117+
* @param arrays - list of ndarrays
118+
* @param clbk - callback function
119+
* @returns reduction result
120+
*/
121+
type ReductionFcn<T, U, V, W> = ( arrays: ReductionArrays<T, V>, clbk: Callback<T, W, unknown> ) => U;
122+
123+
/**
124+
* Reduction function.
125+
*
126+
* @param arrays - list of ndarrays
127+
* @param options - function options
128+
* @param clbk - callback function
129+
* @returns reduction result
130+
*/
131+
type ReductionFcnWithOptions<T, U, V, W> = ( arrays: ReductionArrays<T, V>, options: Object, clbk: Callback<T, W, unknown> ) => U;
132+
133+
/**
134+
* Reduction function.
135+
*
136+
* @param arrays - list of ndarrays
137+
* @param options - function options
138+
* @param clbk - callback function
139+
* @returns reduction result
140+
*/
141+
type Reduction<T, U, V, W> = UnaryReductionFcn<T, U, W> | UnaryReductionFcnWithOptions<T, U, W> | ReductionFcn<T, U, V, W> | ReductionFcnWithOptions<T, U, V, W>;
69142

70143
/**
71144
* Performs a reduction over a list of specified dimensions in an input ndarray according to a callback function and assigns results to a provided output ndarray.
@@ -83,14 +156,9 @@ type Callback<T, U> = Nullary<U> | Unary<T, U> | Binary<T, U> | Ternary<T, U>;
83156
* var everyBy = require( '@stdlib/ndarray/base/every-by' );
84157
*
85158
* function clbk( value ) {
86-
* this.count += 1;
87159
* return value > 0.0;
88160
* }
89161
*
90-
* var ctx = {
91-
* 'count': 0
92-
* };
93-
*
94162
* // Create data buffers:
95163
* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 0.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
96164
* var ybuf = filled( false, 3 );
@@ -128,12 +196,12 @@ type Callback<T, U> = Nullary<U> | Unary<T, U> | Binary<T, U> | Ternary<T, U>;
128196
* };
129197
*
130198
* // Perform a reduction:
131-
* unaryReduceSubarrayBy( everyBy, [ x, y ], [ 2, 3 ], clbk, ctx );
199+
* unaryReduceSubarrayBy( everyBy, [ x, y ], [ 2, 3 ], clbk );
132200
*
133201
* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order );
134202
* // returns [ [ true, false, true ] ]
135203
*/
136-
declare function unaryReduceSubarrayBy<T = unknown, U = unknown>( fcn: Function, arrays: ArrayLike<typedndarray<T>>, dims: ArrayLike<number>, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): void;
204+
declare function unaryReduceSubarrayBy<T = unknown, U = unknown, V = unknown, W = unknown, ThisArg = unknown>( fcn: Reduction<T, U, V, W>, arrays: ListOfArrays<T, U, V>, dims: ArrayLike<number>, clbk: Callback<T, W, ThisArg>, thisArg?: ThisParameterType<Callback<T, W, ThisArg>> ): void;
137205

138206
/**
139207
* Performs a reduction over a list of specified dimensions in an input ndarray according to a callback function and assigns results to a provided output ndarray.
@@ -152,14 +220,9 @@ declare function unaryReduceSubarrayBy<T = unknown, U = unknown>( fcn: Function,
152220
* var everyBy = require( '@stdlib/ndarray/base/every-by' );
153221
*
154222
* function clbk( value ) {
155-
* this.count += 1;
156223
* return value > 0.0;
157224
* }
158225
*
159-
* var ctx = {
160-
* 'count': 0
161-
* };
162-
*
163226
* // Create data buffers:
164227
* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 0.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
165228
* var ybuf = filled( false, 3 );
@@ -197,12 +260,12 @@ declare function unaryReduceSubarrayBy<T = unknown, U = unknown>( fcn: Function,
197260
* };
198261
*
199262
* // Perform a reduction:
200-
* unaryReduceSubarrayBy( everyBy, [ x, y ], [ 2, 3 ], {}, clbk, ctx );
263+
* unaryReduceSubarrayBy( everyBy, [ x, y ], [ 2, 3 ], {}, clbk );
201264
*
202265
* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order );
203266
* // returns [ [ true, false, true ] ]
204267
*/
205-
declare function unaryReduceSubarrayBy<T = unknown, U = unknown>( fcn: Function, arrays: ArrayLike<typedndarray<T>>, dims: ArrayLike<number>, options: Object, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): void;
268+
declare function unaryReduceSubarrayBy<T = unknown, U = unknown, V = unknown, W = unknown, ThisArg = unknown>( fcn: Reduction<T, U, V, W>, arrays: ListOfArrays<T, U, V>, dims: ArrayLike<number>, options: Object, clbk: Callback<T, W, ThisArg>, thisArg?: ThisParameterType<Callback<T, W, ThisArg>> ): void;
206269

207270

208271
// EXPORTS //

0 commit comments

Comments
 (0)