Skip to content

Commit 2543137

Browse files
committed
Add support for providing a dtype enum (and other dtype values)
1 parent 3557b4d commit 2543137

File tree

4 files changed

+7
-15
lines changed

4 files changed

+7
-15
lines changed

lib/node_modules/@stdlib/ndarray/next-dtype/docs/repl.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
Parameters
1313
----------
14-
dtype: string (optional)
15-
ndarray data type.
14+
dtype: any (optional)
15+
ndarray data type value.
1616

1717
Returns
1818
-------

lib/node_modules/@stdlib/ndarray/next-dtype/docs/types/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
* - If a data type does not have a next larger data type or the next larger type is not supported, the function returns `-1`.
2828
* - If provided an unrecognized data type, the function returns `null`.
2929
*
30-
* @param dtype - ndarray data type
30+
* @param dtype - ndarray data type value
3131
* @returns next larger data type(s) or null
3232
*
3333
* @example
3434
* var dt = nextDataType( 'float32' );
3535
* // returns 'float64'
3636
*/
37-
declare function nextDataType( dtype?: string ): any;
37+
declare function nextDataType( dtype?: any ): any;
3838

3939

4040
// EXPORTS //

lib/node_modules/@stdlib/ndarray/next-dtype/docs/types/test.ts

-10
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@ import nextDataType = require( './index' );
2828
nextDataType( 'float' ); // $ExpectType any
2929
}
3030

31-
// The function does not compile if provided a value other than a string...
32-
{
33-
nextDataType( 123 ); // $ExpectError
34-
nextDataType( true ); // $ExpectError
35-
nextDataType( false ); // $ExpectError
36-
nextDataType( null ); // $ExpectError
37-
nextDataType( {} ); // $ExpectError
38-
nextDataType( ( x: number ): number => x ); // $ExpectError
39-
}
40-
4131
// The function does not compile if provided more than one argument...
4232
{
4333
nextDataType( 'float32', 123 ); // $ExpectError

lib/node_modules/@stdlib/ndarray/next-dtype/lib/main.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var objectKeys = require( '@stdlib/utils/keys' );
2424
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
25+
var resolveStr = require( '@stdlib/ndarray/base/dtype-resolve-str' );
2526
var NEXT_DTYPES = require( './next_dtypes.json' );
2627

2728

@@ -54,7 +55,7 @@ function generateTable() {
5455
/**
5556
* Returns the next larger ndarray data type of the same kind.
5657
*
57-
* @param {string} [dtype] - ndarray data type
58+
* @param {*} [dtype] - ndarray data type value
5859
* @returns {(Object|string|integer|null)} next larger data type(s) or null
5960
*
6061
* @example
@@ -65,6 +66,7 @@ function nextDataType( dtype ) {
6566
if ( arguments.length === 0 ) {
6667
return generateTable();
6768
}
69+
dtype = resolveStr( dtype );
6870
if ( hasOwnProp( NEXT_DTYPES, dtype ) ) {
6971
return NEXT_DTYPES[ dtype ];
7072
}

0 commit comments

Comments
 (0)