Skip to content

Commit 270d773

Browse files
committed
refactor!: modify dispatch table to support type signatures
--- 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: skipped - 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: na - task: lint_license_headers status: passed ---
1 parent 2b48dd6 commit 270d773

5 files changed

Lines changed: 81 additions & 14 deletions

File tree

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-factory/README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,21 @@ var policy = 'same';
5151
var unary = unaryStrided1dDispatchFactory( table, [ dtypes ], dtypes, policy );
5252
```
5353

54-
- **table**: strided reduction function dispatch table. Must have a `'default'` property and a corresponding strided reduction function. May have additional properties corresponding to specific data types and associated specialized strided reduction functions.
54+
The function has the following parameters:
55+
56+
- **table**: strided reduction function dispatch table. Must have the following properties:
57+
58+
- **default**: default strided reduction function which should be invoked when provided ndarrays have data types which do not have a corresponding specialized implementation.
59+
60+
A dispatch table may have the following additional properties:
61+
62+
- **types**: one-dimensional list of ndarray data types describing specialized input ndarray argument signatures. Only the input ndarray argument data types should be specified. Output ndarray and additional input ndarray argument data types should be omitted and are not considered during dispatch. The length of `types` must equal the number of strided functions specified by `fcns` (i.e., for every input ndarray data type, there must be a corresponding strided reduction function in `fcns`).
63+
- **fcns**: list of strided reduction functions which are specific to specialized input ndarray argument signatures.
64+
5565
- **idtypes**: list containing lists of supported input data types for each input ndarray argument.
56-
- **odtypes**: list of supported input data types.
66+
67+
- **odtypes**: list of supported output data types.
68+
5769
- **policy**: output data type policy.
5870

5971
#### unary( x\[, ...args]\[, options] )
@@ -182,6 +194,16 @@ The function accepts the following options:
182194

183195
## Notes
184196

197+
- A strided reduction function should have the following signature:
198+
199+
```text
200+
f( arrays )
201+
```
202+
203+
where
204+
205+
- **arrays**: array containing an input ndarray, followed by any additional ndarray arguments.
206+
185207
- The output data type policy only applies to the function returned by `factory`. For the `assign` method, the output ndarray is allowed to have any data type.
186208
187209
</section>
@@ -197,6 +219,8 @@ The function accepts the following options:
197219
<!-- eslint no-undef: "error" -->
198220
199221
```javascript
222+
var dmax = require( '@stdlib/stats/base/ndarray/dmax' );
223+
var smax = require( '@stdlib/stats/base/ndarray/smax' );
200224
var base = require( '@stdlib/stats/base/ndarray/max' );
201225
var uniform = require( '@stdlib/random/array/uniform' );
202226
var dtypes = require( '@stdlib/ndarray/dtypes' );
@@ -214,6 +238,14 @@ var policy = 'same';
214238
215239
// Define a dispatch table:
216240
var table = {
241+
'types': [
242+
'float64', // input
243+
'float32' // input
244+
],
245+
'fcns': [
246+
dmax,
247+
smax
248+
],
217249
'default': base
218250
};
219251

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-factory/docs/repl.txt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,29 @@
44

55
Parameters
66
----------
7-
table: Function
8-
Dispatch table containing strided array reduction functions.
7+
table: Object
8+
Dispatch table containing strided reduction functions. The table object
9+
must have the following property:
10+
11+
- default: default strided reduction function to invoke when provided
12+
ndarrays have data types which do not have a corresponding specialized
13+
implementation.
14+
15+
The table may having the following additional properties:
16+
17+
- types: one-dimensional list of ndarray data types describing
18+
specialized input ndarray argument signatures.
19+
- fcns: list of strided reduction functions which are specific to
20+
specialized input ndarray argument signatures.
21+
22+
A strided reduction function should have the following signature:
23+
24+
f( arrays )
25+
26+
where
27+
28+
- arrays: array containing an input ndarray, followed by any additional
29+
ndarray arguments.
930

1031
idtypes: Array<Array<string>>
1132
List containing lists of supported input array data types for each input

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-factory/docs/types/index.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ interface BaseDispatchTable<T, U> {
8989
/**
9090
* Dispatch table.
9191
*/
92-
type DispatchTable<T, U> = {
92+
interface DispatchTable<T, U> extends BaseDispatchTable<T, U> {
9393
/**
94-
* Default strided reduction function.
94+
* One-dimensional list of ndarray data types describing specialized input ndarray argument signatures.
9595
*/
96-
default: Unary<T, U> | UnaryWithAdditionalArrays<T, U>;
97-
} & {
96+
types: ArrayLike<DataType>;
97+
9898
/**
99-
* Strided reduction functions specific to particular data types.
99+
* List of strided reduction functions which are specific to specialized input ndarray argument signatures.
100100
*/
101-
[ K in DataType ]?: Unary<T, U> | UnaryWithAdditionalArrays<T, U>;
102-
};
101+
fcns: ArrayLike<Unary<T, U> | UnaryWithAdditionalArrays<T, U>>;
102+
}
103103

104104
/**
105105
* Interface for performing a reduction on an ndarray.
@@ -248,7 +248,7 @@ interface UnaryFunction<T, U> {
248248
* var v = y.get();
249249
* // returns 2.0
250250
*/
251-
declare function factory<T = unknown, U = unknown>( table: DispatchTable<T, U>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, policy: OutputPolicy ): UnaryFunction<T, U>;
251+
declare function factory<T = unknown, U = unknown>( table: DispatchTable<T, U> | BaseDispatchTable<T, U>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, policy: OutputPolicy ): UnaryFunction<T, U>;
252252

253253

254254
// EXPORTS //

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-factory/examples/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
'use strict';
2020

21+
var dmax = require( '@stdlib/stats/base/ndarray/dmax' );
22+
var smax = require( '@stdlib/stats/base/ndarray/smax' );
2123
var base = require( '@stdlib/stats/base/ndarray/max' );
2224
var uniform = require( '@stdlib/random/array/uniform' );
2325
var dtypes = require( '@stdlib/ndarray/dtypes' );
@@ -35,6 +37,14 @@ var policy = 'same';
3537

3638
// Define a dispatch table:
3739
var table = {
40+
'types': [
41+
'float64', // input
42+
'float32' // input
43+
],
44+
'fcns': [
45+
dmax,
46+
smax
47+
],
3848
'default': base
3949
};
4050

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-factory/lib/main.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@ var UnaryStrided1dDispatch = require( '@stdlib/ndarray/base/unary-reduce-strided
2929
/**
3030
* Returns a function for performing a reduction on a provided ndarray.
3131
*
32-
* @param {Object} table - dispatch table containing strided array reduction functions
32+
* @param {Object} table - dispatch table
33+
* @param {Function} table.default - default strided reduction function
34+
* @param {StringArray} [table.types] - one-dimensional list of ndarray data types describing specialized input ndarray argument signatures
35+
* @param {ArrayLikeObject<Function>} [table.fcns] - list of strided reduction functions which are specific to specialized input ndarray argument signatures
3336
* @param {ArrayLikeObject<StringArray>} idtypes - list containing lists of supported input data types for each ndarray argument
3437
* @param {StringArray} odtypes - list of supported output data types
3538
* @param {string} policy - output data type policy
36-
* @throws {TypeError} first argument must be an object
39+
* @throws {TypeError} first argument must be an object having valid properties
3740
* @throws {TypeError} second argument must be an array containing arrays of supported data types
3841
* @throws {TypeError} third argument must be an array of supported data types
3942
* @throws {TypeError} fourth argument must be a supported output data type policy
43+
* @throws {Error} first argument must be an object having valid properties
4044
* @returns {Function} function for performing a reduction on an ndarray
4145
*
4246
* @example

0 commit comments

Comments
 (0)