@stdlib/ndarray-base-assert-is-same-kind-data-type-cast 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +1 -1
- package/README.md +7 -7
- package/dist/index.js +3 -3
- package/dist/index.js.map +3 -3
- package/docs/types/index.d.ts +5 -1
- package/lib/main.js +12 -4
- package/manifest.json +39 -39
- package/package.json +4 -4
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -65,7 +65,7 @@ var isSameKindCast = require( '@stdlib/ndarray-base-assert-is-same-kind-data-typ
|
|
|
65
65
|
|
|
66
66
|
#### isSameKindCast( from, to )
|
|
67
67
|
|
|
68
|
-
Returns a
|
|
68
|
+
Returns a boolean indicating whether an ndarray [data type][@stdlib/ndarray/dtypes] can be safely cast to, or is of the same "kind" as, another ndarray [data type][@stdlib/ndarray/dtypes] (e.g., casting between signed integers or between floats).
|
|
69
69
|
|
|
70
70
|
```javascript
|
|
71
71
|
var bool = isSameKindCast( 'float32', 'float64' );
|
|
@@ -97,7 +97,7 @@ bool = isSameKindCast( 'uint16', 'int16' );
|
|
|
97
97
|
|
|
98
98
|
```javascript
|
|
99
99
|
var cartesianSquare = require( '@stdlib/array-cartesian-square' );
|
|
100
|
-
var dtypes = require( '@stdlib/ndarray-
|
|
100
|
+
var dtypes = require( '@stdlib/ndarray-base-dtype-strings' );
|
|
101
101
|
var isSameKindCast = require( '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast' );
|
|
102
102
|
|
|
103
103
|
// Generate a list of dtype pairs:
|
|
@@ -156,7 +156,7 @@ See [LICENSE][stdlib-license].
|
|
|
156
156
|
|
|
157
157
|
## Copyright
|
|
158
158
|
|
|
159
|
-
Copyright © 2016-
|
|
159
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
160
160
|
|
|
161
161
|
</section>
|
|
162
162
|
|
|
@@ -169,8 +169,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
169
169
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/ndarray-base-assert-is-same-kind-data-type-cast.svg
|
|
170
170
|
[npm-url]: https://npmjs.org/package/@stdlib/ndarray-base-assert-is-same-kind-data-type-cast
|
|
171
171
|
|
|
172
|
-
[test-image]: https://github.com/stdlib-js/ndarray-base-assert-is-same-kind-data-type-cast/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
173
|
-
[test-url]: https://github.com/stdlib-js/ndarray-base-assert-is-same-kind-data-type-cast/actions/workflows/test.yml?query=branch:v0.
|
|
172
|
+
[test-image]: https://github.com/stdlib-js/ndarray-base-assert-is-same-kind-data-type-cast/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
173
|
+
[test-url]: https://github.com/stdlib-js/ndarray-base-assert-is-same-kind-data-type-cast/actions/workflows/test.yml?query=branch:v0.3.0
|
|
174
174
|
|
|
175
175
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/ndarray-base-assert-is-same-kind-data-type-cast/main.svg
|
|
176
176
|
[coverage-url]: https://codecov.io/github/stdlib-js/ndarray-base-assert-is-same-kind-data-type-cast?branch=main
|
|
@@ -182,8 +182,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
182
182
|
|
|
183
183
|
-->
|
|
184
184
|
|
|
185
|
-
[chat-image]: https://img.shields.io/
|
|
186
|
-
[chat-url]: https://
|
|
185
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
186
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
187
187
|
|
|
188
188
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
189
189
|
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
var
|
|
3
|
-
});var
|
|
1
|
+
"use strict";var u=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=u(function(l,t){
|
|
2
|
+
var n=require('@stdlib/ndarray-same-kind-casts/dist'),i=require('@stdlib/ndarray-base-dtype-resolve-str/dist'),v=n();function c(e,r){var s;return e=i(e),r=i(r),e===r?!0:(s=v[e],s?s[r]>0:!1)}t.exports=c
|
|
3
|
+
});var q=a();module.exports=q;
|
|
4
4
|
/** @license Apache-2.0 */
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../lib/main.js", "../lib/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar sameKindCasts = require( '@stdlib/ndarray-same-kind-casts' );\n\n\n// VARIABLES //\n\nvar TABLE = sameKindCasts();\n\n\n// MAIN //\n\n/**\n* Returns a boolean indicating if a provided ndarray data type can be safely cast to, or is of the same \"kind\" as, another ndarray data type.\n*\n* @param {
|
|
5
|
-
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,iCAAkC,
|
|
6
|
-
"names": ["require_main", "__commonJSMin", "exports", "module", "sameKindCasts", "TABLE", "isSameKindCast", "from", "to", "main"]
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar sameKindCasts = require( '@stdlib/ndarray-same-kind-casts' );\nvar resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );\n\n\n// VARIABLES //\n\nvar TABLE = sameKindCasts();\n\n\n// MAIN //\n\n/**\n* Returns a boolean indicating if a provided ndarray data type can be safely cast to, or is of the same \"kind\" as, another ndarray data type.\n*\n* @param {*} from - ndarray data type\n* @param {*} to - ndarray data type\n* @returns {boolean} boolean indicating if a data type can be cast to another data type\n*\n* @example\n* var bool = isSameKindCast( 'float32', 'float64' );\n* // returns true\n*\n* bool = isSameKindCast( 'uint16', 'int16' );\n* // returns false\n*/\nfunction isSameKindCast( from, to ) {\n\tvar t;\n\tfrom = resolveStr( from );\n\tto = resolveStr( to );\n\tif ( from === to ) { // note: for \"struct\" data types, require strict equality to be considered a safe cast\n\t\treturn true;\n\t}\n\tt = TABLE[ from ];\n\tif ( t ) {\n\t\treturn t[ to ] > 0;\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isSameKindCast;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Determine if an ndarray data type can be safely cast to, or is of the same \"kind\" as, another ndarray data type.\n*\n* @module @stdlib/ndarray-base-assert-is-same-kind-data-type-cast\n*\n* @example\n* var isSameKindCast = require( '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast' );\n*\n* var bool = isSameKindCast( 'float32', 'float64' );\n* // returns true\n*\n* bool = isSameKindCast( 'uint16', 'int16' );\n* // returns false\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
|
+
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,iCAAkC,EAC3DC,EAAa,QAAS,wCAAyC,EAK/DC,EAAQF,EAAc,EAmB1B,SAASG,EAAgBC,EAAMC,EAAK,CACnC,IAAIC,EAGJ,OAFAF,EAAOH,EAAYG,CAAK,EACxBC,EAAKJ,EAAYI,CAAG,EACfD,IAASC,EACN,IAERC,EAAIJ,EAAOE,CAAK,EACXE,EACGA,EAAGD,CAAG,EAAI,EAEX,GACR,CAKAN,EAAO,QAAUI,IC3BjB,IAAII,EAAO,IAKX,OAAO,QAAUA",
|
|
6
|
+
"names": ["require_main", "__commonJSMin", "exports", "module", "sameKindCasts", "resolveStr", "TABLE", "isSameKindCast", "from", "to", "t", "main"]
|
|
7
7
|
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
|
|
19
19
|
// TypeScript Version: 4.1
|
|
20
20
|
|
|
21
|
+
/// <reference types="@stdlib/types"/>
|
|
22
|
+
|
|
23
|
+
import { DataType } from '@stdlib/types/ndarray';
|
|
24
|
+
|
|
21
25
|
/**
|
|
22
26
|
* Returns a boolean indicating if a provided ndarray data type can be safely cast to, or is of the same "kind" as, another ndarray data type.
|
|
23
27
|
*
|
|
@@ -32,7 +36,7 @@
|
|
|
32
36
|
* bool = isSameKindCast( 'uint16', 'int16' );
|
|
33
37
|
* // returns false
|
|
34
38
|
*/
|
|
35
|
-
declare function isSameKindCast( from:
|
|
39
|
+
declare function isSameKindCast( from: DataType, to: DataType ): boolean;
|
|
36
40
|
|
|
37
41
|
|
|
38
42
|
// EXPORTS //
|
package/lib/main.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
// MODULES //
|
|
22
22
|
|
|
23
23
|
var sameKindCasts = require( '@stdlib/ndarray-same-kind-casts' );
|
|
24
|
+
var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );
|
|
24
25
|
|
|
25
26
|
|
|
26
27
|
// VARIABLES //
|
|
@@ -33,8 +34,8 @@ var TABLE = sameKindCasts();
|
|
|
33
34
|
/**
|
|
34
35
|
* Returns a boolean indicating if a provided ndarray data type can be safely cast to, or is of the same "kind" as, another ndarray data type.
|
|
35
36
|
*
|
|
36
|
-
* @param {
|
|
37
|
-
* @param {
|
|
37
|
+
* @param {*} from - ndarray data type
|
|
38
|
+
* @param {*} to - ndarray data type
|
|
38
39
|
* @returns {boolean} boolean indicating if a data type can be cast to another data type
|
|
39
40
|
*
|
|
40
41
|
* @example
|
|
@@ -45,10 +46,17 @@ var TABLE = sameKindCasts();
|
|
|
45
46
|
* // returns false
|
|
46
47
|
*/
|
|
47
48
|
function isSameKindCast( from, to ) {
|
|
48
|
-
|
|
49
|
+
var t;
|
|
50
|
+
from = resolveStr( from );
|
|
51
|
+
to = resolveStr( to );
|
|
52
|
+
if ( from === to ) { // note: for "struct" data types, require strict equality to be considered a safe cast
|
|
49
53
|
return true;
|
|
50
54
|
}
|
|
51
|
-
|
|
55
|
+
t = TABLE[ from ];
|
|
56
|
+
if ( t ) {
|
|
57
|
+
return t[ to ] > 0;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
52
60
|
}
|
|
53
61
|
|
|
54
62
|
|
package/manifest.json
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
2
|
+
"options": {},
|
|
3
|
+
"fields": [
|
|
4
|
+
{
|
|
5
|
+
"field": "src",
|
|
6
|
+
"resolve": true,
|
|
7
|
+
"relative": true
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"field": "include",
|
|
11
|
+
"resolve": true,
|
|
12
|
+
"relative": true
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"field": "libraries",
|
|
16
|
+
"resolve": false,
|
|
17
|
+
"relative": false
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"field": "libpath",
|
|
21
|
+
"resolve": true,
|
|
22
|
+
"relative": false
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"confs": [
|
|
26
|
+
{
|
|
27
|
+
"src": [
|
|
28
|
+
"./src/main.c"
|
|
29
|
+
],
|
|
30
|
+
"include": [
|
|
31
|
+
"./include"
|
|
32
|
+
],
|
|
33
|
+
"libraries": [],
|
|
34
|
+
"libpath": [],
|
|
35
|
+
"dependencies": [
|
|
36
|
+
"@stdlib/ndarray-dtypes",
|
|
37
|
+
"@stdlib/ndarray-same-kind-casts"
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
41
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/ndarray-base-assert-is-same-kind-data-type-cast",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Determine if an ndarray data type can be safely cast to, or is of the same kind as, another ndarray data type.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -32,8 +32,9 @@
|
|
|
32
32
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@stdlib/ndarray-
|
|
36
|
-
"@stdlib/ndarray-
|
|
35
|
+
"@stdlib/ndarray-base-dtype-resolve-str": "^0.2.2",
|
|
36
|
+
"@stdlib/ndarray-dtypes": "^0.3.0",
|
|
37
|
+
"@stdlib/ndarray-same-kind-casts": "^0.3.0"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {},
|
|
39
40
|
"engines": {
|
|
@@ -75,7 +76,6 @@
|
|
|
75
76
|
"utils",
|
|
76
77
|
"util"
|
|
77
78
|
],
|
|
78
|
-
"__stdlib__": {},
|
|
79
79
|
"funding": {
|
|
80
80
|
"type": "opencollective",
|
|
81
81
|
"url": "https://opencollective.com/stdlib"
|