File tree 4 files changed +12
-29
lines changed
lib/node_modules/@stdlib/ndarray/promotion-rules
4 files changed +12
-29
lines changed Original file line number Diff line number Diff line change 12
12
13
13
Parameters
14
14
----------
15
- dtype1: string (optional)
16
- ndarray data type.
15
+ dtype1: any (optional)
16
+ ndarray data type value .
17
17
18
- dtype2: string (optional)
19
- ndarray data type.
18
+ dtype2: any (optional)
19
+ ndarray data type value .
20
20
21
21
Returns
22
22
-------
Original file line number Diff line number Diff line change @@ -29,8 +29,8 @@ interface Table {
29
29
/**
30
30
* Returns the ndarray data type with the smallest size and closest "kind" to which ndarray data types can be safely cast.
31
31
*
32
- * @param dtype1 - ndarray data type
33
- * @param dtype2 - ndarray data type
32
+ * @param dtype1 - ndarray data type value
33
+ * @param dtype2 - ndarray data type value
34
34
* @returns promotion rule(s) or null
35
35
*
36
36
* @example
@@ -45,7 +45,7 @@ interface Table {
45
45
* var dt = promotionRules( 'float32', 'foo' );
46
46
* // returns null
47
47
*/
48
- declare function promotionRules ( dtype1 : string , dtype2 : string ) : number | string | null ; // tslint-disable-line max-line-length
48
+ declare function promotionRules ( dtype1 : any , dtype2 : any ) : number | string | null ; // tslint-disable-line max-line-length
49
49
50
50
/**
51
51
* Returns a type promotion table displaying the ndarray data types with the smallest size and closest "kind" to which ndarray data types can be safely cast.
Original file line number Diff line number Diff line change @@ -29,26 +29,6 @@ import promotionRules = require( './index' );
29
29
promotionRules ( 'float32' , 'foo' ) ; // $ExpectType string | number | null
30
30
}
31
31
32
- // The function does not compile if provided a first argument that is not a string...
33
- {
34
- promotionRules ( 123 , 'float64' ) ; // $ExpectError
35
- promotionRules ( true , 'float64' ) ; // $ExpectError
36
- promotionRules ( false , 'float64' ) ; // $ExpectError
37
- promotionRules ( null , 'float64' ) ; // $ExpectError
38
- promotionRules ( { } , 'float64' ) ; // $ExpectError
39
- promotionRules ( ( x : number ) : number => x , 'float64' ) ; // $ExpectError
40
- }
41
-
42
- // The function does not compile if provided a second argument that is not a string...
43
- {
44
- promotionRules ( 'int32' , 123 ) ; // $ExpectError
45
- promotionRules ( 'int32' , true ) ; // $ExpectError
46
- promotionRules ( 'int32' , false ) ; // $ExpectError
47
- promotionRules ( 'int32' , null ) ; // $ExpectError
48
- promotionRules ( 'int32' , { } ) ; // $ExpectError
49
- promotionRules ( 'int32' , ( x : number ) : number => x ) ; // $ExpectError
50
- }
51
-
52
32
// The function does not compile if provided more than one argument...
53
33
{
54
34
promotionRules ( 'float32' ) ; // $ExpectError
Original file line number Diff line number Diff line change 22
22
23
23
var objectKeys = require ( '@stdlib/utils/keys' ) ;
24
24
var hasOwnProp = require ( '@stdlib/assert/has-own-property' ) ;
25
+ var resolve = require ( '@stdlib/ndarray/base/dtype-resolve-str' ) ;
25
26
var PROMOTION_RULES = require ( './promotion_rules.json' ) ;
26
27
27
28
@@ -66,8 +67,8 @@ function generateFullTable() {
66
67
/**
67
68
* Returns the ndarray data type with the smallest size and closest "kind" to which ndarray data types can be safely cast.
68
69
*
69
- * @param {string } [dtype1] - ndarray data type
70
- * @param {string } [dtype2] - ndarray data type
70
+ * @param {* } [dtype1] - ndarray data type value
71
+ * @param {* } [dtype2] - ndarray data type value
71
72
* @returns {(Object|integer|string|null) } promotion rule(s) or null
72
73
*
73
74
* @example
@@ -91,8 +92,10 @@ function promotionRules( dtype1, dtype2 ) {
91
92
if ( arguments . length === 0 ) {
92
93
return generateFullTable ( ) ;
93
94
}
95
+ dtype1 = resolve ( dtype1 ) ;
94
96
if ( hasOwnProp ( PROMOTION_RULES , dtype1 ) ) {
95
97
o = PROMOTION_RULES [ dtype1 ] ;
98
+ dtype2 = resolve ( dtype2 ) ;
96
99
if ( hasOwnProp ( o , dtype2 ) ) {
97
100
return o [ dtype2 ] ;
98
101
}
You can’t perform that action at this time.
0 commit comments