Skip to content

Commit f9681bd

Browse files
committed
Auto-generated commit
1 parent 9ec398c commit f9681bd

File tree

19 files changed

+414
-31
lines changed

19 files changed

+414
-31
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
### Features
1212

13+
- [`4b6bce8`](https://github.com/stdlib-js/stdlib/commit/4b6bce89254cfbbe7a008167ce7b4eccceaaea7e) - add support for non-string data types
14+
- [`55e56f0`](https://github.com/stdlib-js/stdlib/commit/55e56f0b239268c250b9e64d46f5914d24229e1b) - add support for non-string data types
15+
- [`a74c0e2`](https://github.com/stdlib-js/stdlib/commit/a74c0e2e7efd0b76b251d895f43d5c197512ba2b) - add support for non-string data types
16+
- [`6dd3bf6`](https://github.com/stdlib-js/stdlib/commit/6dd3bf6252e3808803c6a5ea00925247b592bd01) - add support for non-string data types
17+
- [`96ea877`](https://github.com/stdlib-js/stdlib/commit/96ea8778698f2979de10ac6d62d91b0d6bd65cae) - add support for struct and data type objects
1318
- [`25164a7`](https://github.com/stdlib-js/stdlib/commit/25164a7ae8ac5285255e2d8097f3e123d9db3a38) - add support for non-string data types
1419
- [`c6ce94c`](https://github.com/stdlib-js/stdlib/commit/c6ce94c5cf69a183cbe369a56411192d8d99abe1) - add support for non-string data types
1520
- [`360ed63`](https://github.com/stdlib-js/stdlib/commit/360ed63a0e83c2cc4261df2b6075e1cc2c8f5dec) - add support for non-string data tpes
@@ -566,6 +571,13 @@ A total of 24 issues were closed in this release:
566571

567572
<details>
568573

574+
- [`4b6bce8`](https://github.com/stdlib-js/stdlib/commit/4b6bce89254cfbbe7a008167ce7b4eccceaaea7e) - **feat:** add support for non-string data types _(by Athan Reines)_
575+
- [`55e56f0`](https://github.com/stdlib-js/stdlib/commit/55e56f0b239268c250b9e64d46f5914d24229e1b) - **feat:** add support for non-string data types _(by Athan Reines)_
576+
- [`a74c0e2`](https://github.com/stdlib-js/stdlib/commit/a74c0e2e7efd0b76b251d895f43d5c197512ba2b) - **feat:** add support for non-string data types _(by Athan Reines)_
577+
- [`2d8848b`](https://github.com/stdlib-js/stdlib/commit/2d8848b0a7e94aca604317a6d1e83b110d82f143) - **docs:** add comment _(by Athan Reines)_
578+
- [`6dd3bf6`](https://github.com/stdlib-js/stdlib/commit/6dd3bf6252e3808803c6a5ea00925247b592bd01) - **feat:** add support for non-string data types _(by Athan Reines)_
579+
- [`96ea877`](https://github.com/stdlib-js/stdlib/commit/96ea8778698f2979de10ac6d62d91b0d6bd65cae) - **feat:** add support for struct and data type objects _(by Athan Reines)_
580+
- [`7b1d601`](https://github.com/stdlib-js/stdlib/commit/7b1d6010a2b93231101815666acb7620185b650a) - **refactor:** use assertion utility _(by Athan Reines)_
569581
- [`25164a7`](https://github.com/stdlib-js/stdlib/commit/25164a7ae8ac5285255e2d8097f3e123d9db3a38) - **feat:** add support for non-string data types _(by Athan Reines)_
570582
- [`c6ce94c`](https://github.com/stdlib-js/stdlib/commit/c6ce94c5cf69a183cbe369a56411192d8d99abe1) - **feat:** add support for non-string data types _(by Athan Reines)_
571583
- [`360ed63`](https://github.com/stdlib-js/stdlib/commit/360ed63a0e83c2cc4261df2b6075e1cc2c8f5dec) - **feat:** add support for non-string data tpes _(by Athan Reines)_

base/assert/is-mostly-safe-data-type-cast/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var isMostlySafeCast = require( '@stdlib/ndarray/base/assert/is-mostly-safe-data
4242

4343
#### isMostlySafeCast( from, to )
4444

45-
Returns a `boolean` indicating whether an ndarray [data type][@stdlib/ndarray/dtypes] can be safely cast or, for floating-point data types, downcast to another ndarray [data type][@stdlib/ndarray/dtypes].
45+
Returns a boolean indicating whether an ndarray [data type][@stdlib/ndarray/dtypes] can be safely cast or, for floating-point data types, downcast to another ndarray [data type][@stdlib/ndarray/dtypes].
4646

4747
```javascript
4848
var bool = isMostlySafeCast( 'float32', 'float64' );

base/assert/is-mostly-safe-data-type-cast/docs/repl.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
Parameters
88
----------
9-
from: string
10-
ndarray data type.
9+
from: string|DataType
10+
Data type to cast from.
1111

12-
to: string
13-
ndarray data type.
12+
to: string|DataType
13+
Data type to cast to.
1414

1515
Returns
1616
-------

base/assert/is-mostly-safe-data-type-cast/docs/types/index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
// TypeScript Version: 4.1
2020

21+
/// <reference types="@stdlib/types"/>
22+
23+
import { DataType } from '@stdlib/types/ndarray';
24+
2125
/**
2226
* Returns a boolean indicating if a provided ndarray data type can be safely cast or, for floating-point data types, downcast to another ndarray data type.
2327
*
@@ -32,7 +36,7 @@
3236
* bool = isMostlySafeCast( 'float64', 'int32' );
3337
* // returns false
3438
*/
35-
declare function isMostlySafeCast( from: string, to: string ): boolean;
39+
declare function isMostlySafeCast( from: DataType, to: DataType ): boolean;
3640

3741

3842
// EXPORTS //

base/assert/is-mostly-safe-data-type-cast/lib/main.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// MODULES //
2222

2323
var casts = require( './../../../../mostly-safe-casts' );
24+
var resolveStr = require( './../../../../base/dtype-resolve-str' );
2425

2526

2627
// VARIABLES //
@@ -33,8 +34,8 @@ var TABLE = casts();
3334
/**
3435
* Returns a boolean indicating if a provided ndarray data type can be safely cast or, for floating-point data types, downcast to another ndarray data type.
3536
*
36-
* @param {string} from - ndarray data type
37-
* @param {string} to - ndarray data type
37+
* @param {*} from - ndarray data type
38+
* @param {*} to - ndarray data type
3839
* @returns {boolean} boolean indicating if a data type can be cast to another data type
3940
*
4041
* @example
@@ -45,10 +46,17 @@ var TABLE = casts();
4546
* // returns false
4647
*/
4748
function isMostlySafeCast( from, to ) {
48-
if ( from === to ) {
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 "mostly" safe cast
4953
return true;
5054
}
51-
return ( TABLE[ from ][ to ] > 0 );
55+
t = TABLE[ from ];
56+
if ( t ) {
57+
return t[ to ] > 0;
58+
}
59+
return false;
5260
}
5361

5462

base/assert/is-mostly-safe-data-type-cast/test/test.js

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@
1616
* limitations under the License.
1717
*/
1818

19+
/* eslint-disable max-len */
20+
1921
'use strict';
2022

2123
// MODULES //
2224

2325
var tape = require( 'tape' );
26+
var DataType = require( './../../../../dtype-ctor' );
27+
var structFactory = require( '@stdlib/dstructs/struct' );
2428
var dtypes = require( './../../../../dtypes' );
2529
var casts = require( './../../../../mostly-safe-casts' );
30+
var str2enum = require( './../../../../base/dtype-str2enum' );
2631
var isMostlySafeCast = require( './../lib' );
2732

2833

@@ -40,7 +45,7 @@ tape( 'main export is a function', function test( t ) {
4045
t.end();
4146
});
4247

43-
tape( 'the function returns a boolean indicating if an ndarray data type can be cast to another ndarray data type', function test( t ) {
48+
tape( 'the function returns a boolean indicating if an ndarray data type can be cast to another ndarray data type (strings)', function test( t ) {
4449
var expected;
4550
var actual;
4651
var dt;
@@ -57,3 +62,113 @@ tape( 'the function returns a boolean indicating if an ndarray data type can be
5762
}
5863
t.end();
5964
});
65+
66+
tape( 'the function returns a boolean indicating if an ndarray data type can be cast to another ndarray data type (enums)', function test( t ) {
67+
var expected;
68+
var actual;
69+
var dt;
70+
var i;
71+
var j;
72+
73+
for ( i = 0; i < DTYPES.length; i++ ) {
74+
dt = DTYPES[ i ];
75+
for ( j = 0; j < DTYPES.length; j++ ) {
76+
expected = ( CASTS[ dt ][ DTYPES[j] ] > 0 );
77+
actual = isMostlySafeCast( str2enum( dt ), str2enum( DTYPES[ j ] ) );
78+
t.strictEqual( actual, expected, 'returns expected value. from: '+dt+'. to: '+DTYPES[j]+'.' );
79+
}
80+
}
81+
t.end();
82+
});
83+
84+
tape( 'the function returns a boolean indicating if an ndarray data type can be cast to another ndarray data type (data type, strings)', function test( t ) {
85+
var expected;
86+
var actual;
87+
var dt;
88+
var i;
89+
var j;
90+
91+
for ( i = 0; i < DTYPES.length; i++ ) {
92+
dt = DTYPES[ i ];
93+
for ( j = 0; j < DTYPES.length; j++ ) {
94+
expected = ( CASTS[ dt ][ DTYPES[j] ] > 0 );
95+
actual = isMostlySafeCast( new DataType( dt ), new DataType( DTYPES[ j ] ) );
96+
t.strictEqual( actual, expected, 'returns expected value. from: '+dt+'. to: '+DTYPES[j]+'.' );
97+
}
98+
}
99+
t.end();
100+
});
101+
102+
tape( 'the function returns a boolean indicating if an ndarray data type can be cast to another ndarray data type (struct)', function test( t ) {
103+
var schemas;
104+
var values;
105+
var actual;
106+
var dt;
107+
var i;
108+
109+
schemas = [
110+
[
111+
{
112+
'name': 'foo',
113+
'type': 'float64'
114+
}
115+
],
116+
[
117+
{
118+
'name': 'bar',
119+
'type': 'float32'
120+
}
121+
]
122+
];
123+
values = [
124+
structFactory( schemas[ 0 ] ),
125+
structFactory( schemas[ 1 ] )
126+
];
127+
128+
for ( i = 0; i < values.length; i++ ) {
129+
dt = values[ i ];
130+
actual = isMostlySafeCast( dt, dt );
131+
t.strictEqual( actual, true, 'returns expected value. from: '+dt.layout+'. to: '+dt.layout+'.' );
132+
}
133+
actual = isMostlySafeCast( values[ 0 ], values[ 1 ] );
134+
t.strictEqual( actual, false, 'returns expected value' );
135+
136+
t.end();
137+
});
138+
139+
tape( 'the function returns a boolean indicating if an ndarray data type can be cast to another ndarray data type (data type, struct)', function test( t ) {
140+
var schemas;
141+
var values;
142+
var actual;
143+
var dt;
144+
var i;
145+
146+
schemas = [
147+
[
148+
{
149+
'name': 'foo',
150+
'type': 'float64'
151+
}
152+
],
153+
[
154+
{
155+
'name': 'bar',
156+
'type': 'float32'
157+
}
158+
]
159+
];
160+
values = [
161+
structFactory( schemas[ 0 ] ),
162+
structFactory( schemas[ 1 ] )
163+
];
164+
165+
for ( i = 0; i < values.length; i++ ) {
166+
dt = values[ i ];
167+
actual = isMostlySafeCast( new DataType( dt ), new DataType( dt ) );
168+
t.strictEqual( actual, true, 'returns expected value. from: '+dt.layout+'. to: '+dt.layout+'.' );
169+
}
170+
actual = isMostlySafeCast( new DataType( values[ 0 ] ), new DataType( values[ 1 ] ) );
171+
t.strictEqual( actual, false, 'returns expected value' );
172+
173+
t.end();
174+
});

base/assert/is-numeric-data-type/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var isNumericDataType = require( '@stdlib/ndarray/base/assert/is-numeric-data-ty
4242

4343
#### isNumericDataType( value )
4444

45-
Tests if an input `value` is a supported ndarray numeric data type.
45+
Tests if an input value is a supported ndarray numeric data type.
4646

4747
```javascript
4848
var bool = isNumericDataType( 'float32' );

base/assert/is-numeric-data-type/lib/main.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ var contains = require( '@stdlib/array/base/assert/contains' ).factory;
2424
var dtypes = require( './../../../../dtypes' );
2525

2626

27+
// VARIABLES //
28+
29+
var isDataType = contains( dtypes( 'numeric' ) );
30+
31+
2732
// MAIN //
2833

2934
/**
3035
* Tests whether an input value is a supported ndarray numeric data type.
3136
*
32-
* @name isNumericDataType
33-
* @type {Function}
3437
* @param {*} v - value to test
3538
* @returns {boolean} boolean indicating whether an input value is a supported ndarray numeric data type
3639
*
@@ -71,7 +74,9 @@ var dtypes = require( './../../../../dtypes' );
7174
* bool = isNumericDataType( 'foo' );
7275
* // returns false
7376
*/
74-
var isNumericDataType = contains( dtypes( 'numeric' ) );
77+
function isNumericDataType( v ) {
78+
return isDataType( String( v ) );
79+
}
7580

7681

7782
// EXPORTS //

base/assert/is-numeric-data-type/test/test.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// MODULES //
2222

2323
var tape = require( 'tape' );
24+
var DataType = require( './../../../../dtype-ctor' );
2425
var isNumericDataType = require( './../lib' );
2526

2627

@@ -48,7 +49,19 @@ tape( 'the function returns `true` if provided a supported ndarray numeric data
4849
'uint8c',
4950
'int16',
5051
'int32',
51-
'int8'
52+
'int8',
53+
54+
new DataType( 'complex64' ),
55+
new DataType( 'complex128' ),
56+
new DataType( 'float32' ),
57+
new DataType( 'float64' ),
58+
new DataType( 'uint16' ),
59+
new DataType( 'uint32' ),
60+
new DataType( 'uint8' ),
61+
new DataType( 'uint8c' ),
62+
new DataType( 'int16' ),
63+
new DataType( 'int32' ),
64+
new DataType( 'int8' )
5265
];
5366
for ( i = 0; i < values.length; i++ ) {
5467
bool = isNumericDataType( values[ i ] );
@@ -67,6 +80,8 @@ tape( 'the function returns `false` if not provided a supported ndarray numeric
6780
'binary',
6881
'generic',
6982

83+
new DataType( 'binary' ),
84+
7085
// Unsupported dtypes:
7186
'float',
7287
'int',

base/assert/is-real-data-type/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var isRealDataType = require( '@stdlib/ndarray/base/assert/is-real-data-type' );
4242

4343
#### isRealDataType( value )
4444

45-
Tests if an input `value` is a supported ndarray real-valued data type.
45+
Tests if an input value is a supported ndarray real-valued data type.
4646

4747
```javascript
4848
var bool = isRealDataType( 'float32' );

0 commit comments

Comments
 (0)