Skip to content

Commit e8ff8a5

Browse files
committed
Refactor to support non-string dtype values
1 parent 892b6e1 commit e8ff8a5

File tree

7 files changed

+37
-37
lines changed

7 files changed

+37
-37
lines changed

lib/node_modules/@stdlib/ndarray/dispatch/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fcn( x, y );
110110
The function accepts the following arguments:
111111

112112
- **fcns**: list of [ndarray][@stdlib/ndarray/ctor] functions.
113-
- **types**: one-dimensional list of [ndarray][@stdlib/ndarray/ctor] argument data types. The length of `types` must be the number of [ndarray][@stdlib/ndarray/ctor] functions multiplied by `nin+nout`. If `fcns` is a function, rather than a list, the number of [ndarray][@stdlib/ndarray/ctor] functions is computed as `types.length / (nin+nout)`.
113+
- **types**: one-dimensional list of [ndarray][@stdlib/ndarray/ctor] argument [data types][@stdlib/ndarray/dtypes]. The length of `types` must be the number of [ndarray][@stdlib/ndarray/ctor] functions multiplied by `nin+nout`. If `fcns` is a function, rather than a list, the number of [ndarray][@stdlib/ndarray/ctor] functions is computed as `types.length / (nin+nout)`.
114114
- **data**: [ndarray][@stdlib/ndarray/ctor] function data (e.g., callbacks). If a list, the length of `data` must equal the number of [ndarray][@stdlib/ndarray/ctor] functions. If `null`, a returned [ndarray][@stdlib/ndarray/ctor] function interface does **not** provide a `data` argument to an invoked [ndarray][@stdlib/ndarray/ctor] function.
115115
- **nargs**: total number of [ndarray][@stdlib/ndarray/ctor] function interface arguments.
116116
- **nin**: number of input [ndarrays][@stdlib/ndarray/ctor].
@@ -272,6 +272,8 @@ console.log( ybuf );
272272

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

275+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes
276+
275277
<!-- </related-links> -->
276278

277279
</section>

lib/node_modules/@stdlib/ndarray/dispatch/docs/types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ interface Dispatcher {
288288
* @param nin - number of input ndarrays
289289
* @param nout - number of output ndarrays
290290
* @throws first argument must be either a function or an array of functions
291-
* @throws second argument must be an array of strings
291+
* @throws second argument must be an array-like object
292292
* @throws third argument must be an array-like object or `null`
293293
* @throws third and first arguments must have the same number of elements
294294
* @throws fourth argument must be a positive integer
@@ -326,7 +326,7 @@ interface Dispatcher {
326326
* fcn( x, y );
327327
* // ybuf => <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0 ]
328328
*/
329-
declare function dispatch( fcns: ndarrayFcn | ArrayLike<ndarrayFcn>, types: ArrayLike<string>, data: ArrayLike<any> | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length
329+
declare function dispatch( fcns: ndarrayFcn | ArrayLike<ndarrayFcn>, types: ArrayLike<any>, data: ArrayLike<any> | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length
330330

331331

332332
// EXPORTS //

lib/node_modules/@stdlib/ndarray/dispatch/docs/types/test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ function array(): ndarray {
216216
dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError
217217
}
218218

219-
// The compiler throws an error if the function is provided a second argument which is not an array of strings...
219+
// The compiler throws an error if the function is provided a second argument which is not an array-like object...
220220
{
221221
const data = [ unary ];
222222

@@ -225,9 +225,7 @@ function array(): ndarray {
225225
dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError
226226
dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError
227227
dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError
228-
dispatch( ndarrayFcn, [ 1 ], data, 2, 1, 1 ); // $ExpectError
229228
dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError
230-
dispatch( ndarrayFcn, ( x: number ): number => x, data, 2, 1, 1 ); // $ExpectError
231229
}
232230

233231
// The compiler throws an error if the function is provided a third argument which is not an array-like object or null...

lib/node_modules/@stdlib/ndarray/dispatch/examples/add.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var Int32Array = require( '@stdlib/array/int32' );
2525
var ind2sub = require( '@stdlib/ndarray/ind2sub' );
2626
var ndarray = require( '@stdlib/ndarray/ctor' );
2727
var numel = require( '@stdlib/ndarray/base/numel' );
28+
var dtypes = require( '@stdlib/ndarray/dtypes' );
2829
var dispatch = require( './../lib' );
2930

3031
function add2( arrays ) {
@@ -84,15 +85,15 @@ var fcns = [
8485
];
8586

8687
var types = [
87-
'float64', 'float64', 'float64',
88-
'float32', 'float32', 'float32',
89-
'int32', 'int32', 'int32',
90-
'uint32', 'uint32', 'uint32',
91-
'int16', 'int16', 'int16',
92-
'uint16', 'uint16', 'uint16',
93-
'int8', 'int8', 'int8',
94-
'uint8', 'uint8', 'uint8',
95-
'uint8c', 'uint8c', 'uint8c'
88+
dtypes.float64, dtypes.float64, dtypes.float64,
89+
dtypes.float32, dtypes.float32, dtypes.float32,
90+
dtypes.int32, dtypes.int32, dtypes.int32,
91+
dtypes.uint32, dtypes.uint32, dtypes.uint32,
92+
dtypes.int16, dtypes.int16, dtypes.int16,
93+
dtypes.uint16, dtypes.uint16, dtypes.uint16,
94+
dtypes.int8, dtypes.int8, dtypes.int8,
95+
dtypes.uint8, dtypes.uint8, dtypes.uint8,
96+
dtypes.uint8c, dtypes.uint8c, dtypes.uint8c
9697
];
9798

9899
var add = dispatch( fcns, types, null, 3, 2, 1 );

lib/node_modules/@stdlib/ndarray/dispatch/examples/sin.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var sin = require( '@stdlib/math/base/special/sin' );
2727
var ind2sub = require( '@stdlib/ndarray/ind2sub' );
2828
var ndarray = require( '@stdlib/ndarray/ctor' );
2929
var numel = require( '@stdlib/ndarray/base/numel' );
30+
var dtypes = require( '@stdlib/strided/dtypes' );
3031
var dispatch = require( './../lib' );
3132

3233
function apply( arrays, fcn ) {
@@ -85,21 +86,21 @@ var fcns = [
8586
];
8687

8788
var types = [
88-
'float64', 'float64',
89-
'float32', 'float64',
90-
'float32', 'float32',
91-
'int32', 'float64',
92-
'uint32', 'float64',
93-
'int16', 'float64',
94-
'int16', 'float32',
95-
'uint16', 'float64',
96-
'uint16', 'float32',
97-
'int8', 'float64',
98-
'int8', 'float32',
99-
'uint8', 'float64',
100-
'uint8', 'float32',
101-
'uint8c', 'float64',
102-
'uint8c', 'float32'
89+
dtypes.float64, dtypes.float64,
90+
dtypes.float32, dtypes.float64,
91+
dtypes.float32, dtypes.float32,
92+
dtypes.int32, dtypes.float64,
93+
dtypes.uint32, dtypes.float64,
94+
dtypes.int16, dtypes.float64,
95+
dtypes.int16, dtypes.float32,
96+
dtypes.uint16, dtypes.float64,
97+
dtypes.uint16, dtypes.float32,
98+
dtypes.int8, dtypes.float64,
99+
dtypes.int8, dtypes.float32,
100+
dtypes.uint8, dtypes.float64,
101+
dtypes.uint8, dtypes.float32,
102+
dtypes.uint8c, dtypes.float64,
103+
dtypes.uint8c, dtypes.float32
103104
];
104105

105106
var data = [

lib/node_modules/@stdlib/ndarray/dispatch/lib/main.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' );
2525
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
2626
var isFunctionArray = require( '@stdlib/assert/is-function-array' );
2727
var isFunction = require( '@stdlib/assert/is-function' );
28-
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
2928
var isCollection = require( '@stdlib/assert/is-collection' );
3029
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
3130
var indexOfTypes = require( './index_of_types.js' );
@@ -37,13 +36,13 @@ var indexOfTypes = require( './index_of_types.js' );
3736
* Returns an ndarray function interface which performs multiple dispatch.
3837
*
3938
* @param {(FunctionArray|Function)} fcns - list of ndarray functions
40-
* @param {StringArray} types - one-dimensional list of ndarray argument data types
39+
* @param {Collection} types - one-dimensional list of ndarray argument data types
4140
* @param {(Collection|null)} data - ndarray function data (e.g., callbacks)
4241
* @param {PositiveInteger} nargs - total number of ndarray function interface arguments
4342
* @param {NonNegativeInteger} nin - number of input ndarrays
4443
* @param {NonNegativeInteger} nout - number of output ndarrays
4544
* @throws {TypeError} first argument must be either a function or an array of functions
46-
* @throws {TypeError} second argument must be an array of strings
45+
* @throws {TypeError} second argument must be an array-like object
4746
* @throws {TypeError} third argument must be an array-like object or `null`
4847
* @throws {Error} third and first arguments must have the same number of elements
4948
* @throws {TypeError} fourth argument must be a positive integer
@@ -91,8 +90,8 @@ function dispatch( fcns, types, data, nargs, nin, nout ) {
9190
} else if ( !isFunctionArray( fcns ) ) {
9291
throw new TypeError( 'invalid argument. First argument must be either a function or an array of functions. Value: `' + fcns + '`.' );
9392
}
94-
if ( !isStringArray( types ) ) {
95-
throw new TypeError( 'invalid argument. Second argument must be an array of strings. Value: `' + types + '`.' );
93+
if ( !isCollection( types ) ) {
94+
throw new TypeError( 'invalid argument. Second argument must be an array-like object. Value: `' + types + '`.' );
9695
}
9796
if ( !isCollection( data ) && data !== null ) {
9897
throw new TypeError( 'invalid argument. Third argument must be an array-like object or `null`. Value: `' + data + '`.' );

lib/node_modules/@stdlib/ndarray/dispatch/test/test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ tape( 'the function throws an error if not provided either a function or an arra
7171
}
7272
});
7373

74-
tape( 'the function throws an error if not provided an array of strings as a second argument', function test( t ) {
74+
tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) {
7575
var values;
7676
var i;
7777

@@ -84,7 +84,6 @@ tape( 'the function throws an error if not provided an array of strings as a sec
8484
false,
8585
null,
8686
void 0,
87-
[ '5', 5 ],
8887
{},
8988
function noop() {}
9089
];

0 commit comments

Comments
 (0)