Skip to content

Commit e597522

Browse files
committed
Auto-generated commit
1 parent 4d2a053 commit e597522

File tree

15 files changed

+936
-6
lines changed

15 files changed

+936
-6
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2025-06-19)
7+
## Unreleased (2025-06-20)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`eac188f`](https://github.com/stdlib-js/stdlib/commit/eac188f4def9fa545e9e0cfcd5731a66337fcd1a) - add support for struct data types
14+
- [`99ecc69`](https://github.com/stdlib-js/stdlib/commit/99ecc6907e9c26dabe4dd8e8dfb3b08d10d622c3) - add `isStructDataType` to namespace
15+
- [`d20a2ea`](https://github.com/stdlib-js/stdlib/commit/d20a2ea2cba39ea485abb500861a1fdc2088a36c) - add `ndarray/base/assert/is-struct-data-type`
1316
- [`9a30157`](https://github.com/stdlib-js/stdlib/commit/9a3015754f96452f5f205d91338bbc92def20249) - add `unaryReduceStrided1dDispatchByFactory` to namespace
1417
- [`50ebfa6`](https://github.com/stdlib-js/stdlib/commit/50ebfa6340bddbb7627195e27bdf7ece3a6f1198) - add `unaryReduceStrided1dDispatchBy` to namespace
1518
- [`64103e2`](https://github.com/stdlib-js/stdlib/commit/64103e22a2cf0fcad5914d53885d09e311fef6ee) - add `ndarray/base/unary-reduce-strided1d-dispatch-by-factory`
@@ -440,6 +443,9 @@ A total of 20 issues were closed in this release:
440443

441444
<details>
442445

446+
- [`eac188f`](https://github.com/stdlib-js/stdlib/commit/eac188f4def9fa545e9e0cfcd5731a66337fcd1a) - **feat:** add support for struct data types _(by Athan Reines)_
447+
- [`99ecc69`](https://github.com/stdlib-js/stdlib/commit/99ecc6907e9c26dabe4dd8e8dfb3b08d10d622c3) - **feat:** add `isStructDataType` to namespace _(by Athan Reines)_
448+
- [`d20a2ea`](https://github.com/stdlib-js/stdlib/commit/d20a2ea2cba39ea485abb500861a1fdc2088a36c) - **feat:** add `ndarray/base/assert/is-struct-data-type` _(by Athan Reines)_
443449
- [`599c41f`](https://github.com/stdlib-js/stdlib/commit/599c41f5fb2ec89c381b7902319b779be8cc6bd5) - **docs:** remove extra empty lines [(#7405)](https://github.com/stdlib-js/stdlib/pull/7405) _(by stdlib-bot)_
444450
- [`3bc4c9f`](https://github.com/stdlib-js/stdlib/commit/3bc4c9f1bf064e7d07f3b2f62d8d0c3c1a305c05) - **chore:** fix C lint errors [(#7397)](https://github.com/stdlib-js/stdlib/pull/7397) _(by Lokesh Ranjan)_
445451
- [`c68bdbf`](https://github.com/stdlib-js/stdlib/commit/c68bdbf98a4bb5a85cc6f04c26bc43b49b3218b7) - **chore:** fix EditorConfig lint errors [(#7310)](https://github.com/stdlib-js/stdlib/pull/7310) _(by Deepak Singh)_

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

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

4343
#### isDataType( value )
4444

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

4747
```javascript
4848
var bool = isDataType( 'float32' );
@@ -60,6 +60,10 @@ bool = isDataType( 'int32' );
6060

6161
<section class="notes">
6262

63+
## Notes
64+
65+
- The function returns `true` when provided any supported ndarray [data type][@stdlib/ndarray/dtypes] and when provided a [struct][@stdlib/dstructs/struct] constructor describing a fixed-width composite data type.
66+
6367
</section>
6468

6569
<!-- /.notes -->
@@ -139,6 +143,10 @@ bool = isDataType( 'foo' );
139143

140144
<section class="links">
141145

146+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray/tree/main/dtypes
147+
148+
[@stdlib/dstructs/struct]: https://github.com/stdlib-js/dstructs-struct
149+
142150
</section>
143151

144152
<!-- /.links -->

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@
2020

2121
// MODULES //
2222

23+
var isStructDataType = require( './../../../../base/assert/is-struct-data-type' );
2324
var contains = require( '@stdlib/array/base/assert/contains' ).factory;
2425
var dtypes = require( './../../../../dtypes' );
2526

2627

28+
// VARIABLES //
29+
30+
var isDType = contains( dtypes() );
31+
32+
2733
// MAIN //
2834

2935
/**
3036
* Tests whether an input value is a supported ndarray data type.
3137
*
32-
* @name isDataType
33-
* @type {Function}
3438
* @param {*} v - value to test
3539
* @returns {boolean} boolean indicating whether an input value is a supported ndarray data type
3640
*
@@ -71,7 +75,9 @@ var dtypes = require( './../../../../dtypes' );
7175
* bool = isDataType( 'foo' );
7276
* // returns false
7377
*/
74-
var isDataType = contains( dtypes() );
78+
function isDataType( v ) {
79+
return ( isDType( v ) || isStructDataType( v ) );
80+
}
7581

7682

7783
// EXPORTS //

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,20 @@
2121
// MODULES //
2222

2323
var tape = require( 'tape' );
24+
var structFactory = require( '@stdlib/dstructs/struct' );
2425
var isDataType = require( './../lib' );
2526

2627

28+
// VARIABLES //
29+
30+
var Struct = structFactory([
31+
{
32+
'name': 'foo',
33+
'type': 'float64'
34+
}
35+
]);
36+
37+
2738
// TESTS //
2839

2940
tape( 'main export is a function', function test( t ) {
@@ -50,7 +61,10 @@ tape( 'the function returns `true` if provided a supported ndarray data type', f
5061
'uint16',
5162
'uint32',
5263
'uint8',
53-
'uint8c'
64+
'uint8c',
65+
66+
// Custom struct dtypes:
67+
Struct
5468
];
5569
for ( i = 0; i < values.length; i++ ) {
5670
bool = isDataType( values[ i ] );
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# isStructDataType
22+
23+
> Test if an input value is a supported ndarray struct data type.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var isStructDataType = require( '@stdlib/ndarray/base/assert/is-struct-data-type' );
41+
```
42+
43+
#### isStructDataType( value )
44+
45+
Tests if an input value is a supported ndarray struct data type.
46+
47+
```javascript
48+
var structFactory = require( '@stdlib/dstructs/struct' );
49+
50+
var Struct = structFactory([
51+
{
52+
'name': 'foo',
53+
'type': 'float64'
54+
}
55+
]);
56+
57+
var bool = isStructDataType( Struct );
58+
// returns true
59+
60+
bool = isStructDataType( 'int32' );
61+
// returns false
62+
```
63+
64+
</section>
65+
66+
<!-- /.usage -->
67+
68+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
69+
70+
<section class="notes">
71+
72+
</section>
73+
74+
<!-- /.notes -->
75+
76+
<!-- Package usage examples. -->
77+
78+
<section class="examples">
79+
80+
## Examples
81+
82+
<!-- eslint no-undef: "error" -->
83+
84+
```javascript
85+
var structFactory = require( '@stdlib/dstructs/struct' );
86+
var isStructDataType = require( '@stdlib/ndarray/base/assert/is-struct-data-type' );
87+
88+
var Struct = structFactory([
89+
{
90+
'name': 'foo',
91+
'type': 'float64'
92+
}
93+
]);
94+
95+
var bool = isStructDataType( Struct );
96+
// returns true
97+
98+
bool = isStructDataType( 'binary' );
99+
// returns false
100+
101+
bool = isStructDataType( 'float32' );
102+
// returns false
103+
104+
bool = isStructDataType( 'float64' );
105+
// returns false
106+
107+
bool = isStructDataType( 'generic' );
108+
// returns false
109+
110+
bool = isStructDataType( 'int16' );
111+
// returns false
112+
113+
bool = isStructDataType( 'int32' );
114+
// returns false
115+
116+
bool = isStructDataType( 'int8' );
117+
// returns false
118+
119+
bool = isStructDataType( 'uint16' );
120+
// returns false
121+
122+
bool = isStructDataType( 'uint32' );
123+
// returns false
124+
125+
bool = isStructDataType( 'uint8' );
126+
// returns false
127+
128+
bool = isStructDataType( 'uint8c' );
129+
// returns false
130+
131+
bool = isStructDataType( '' );
132+
// returns false
133+
134+
bool = isStructDataType( 'foo' );
135+
// returns false
136+
```
137+
138+
</section>
139+
140+
<!-- /.examples -->
141+
142+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
143+
144+
<section class="references">
145+
146+
</section>
147+
148+
<!-- /.references -->
149+
150+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
151+
152+
<section class="related">
153+
154+
</section>
155+
156+
<!-- /.related -->
157+
158+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
159+
160+
<section class="links">
161+
162+
</section>
163+
164+
<!-- /.links -->
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
25+
var structFactory = require( '@stdlib/dstructs/struct' );
26+
var pkg = require( './../package.json' ).name;
27+
var isStructDataType = require( './../lib' );
28+
29+
30+
// VARIABLES //
31+
32+
var Struct = structFactory([
33+
{
34+
'name': 'foo',
35+
'type': 'float64'
36+
}
37+
]);
38+
39+
40+
// MAIN //
41+
42+
bench( pkg+'::true', function benchmark( b ) {
43+
var values;
44+
var out;
45+
var v;
46+
var i;
47+
48+
values = [
49+
Struct,
50+
Struct
51+
];
52+
53+
b.tic();
54+
for ( i = 0; i < b.iterations; i++ ) {
55+
v = values[ i%values.length ];
56+
out = isStructDataType( v );
57+
if ( typeof out !== 'boolean' ) {
58+
b.fail( 'should return a boolean' );
59+
}
60+
}
61+
b.toc();
62+
if ( !isBoolean( out ) ) {
63+
b.fail( 'should return a boolean' );
64+
}
65+
b.pass( 'benchmark finished' );
66+
b.end();
67+
});
68+
69+
bench( pkg+'::false', function benchmark( b ) {
70+
var values;
71+
var out;
72+
var v;
73+
var i;
74+
75+
values = [
76+
'binary',
77+
'float32',
78+
'float64',
79+
'generic',
80+
'int16',
81+
'int32',
82+
'int8',
83+
'uint16',
84+
'uint32',
85+
'uint8',
86+
'uint8c',
87+
'foo',
88+
'bar',
89+
'',
90+
'beep',
91+
'boop'
92+
];
93+
94+
b.tic();
95+
for ( i = 0; i < b.iterations; i++ ) {
96+
v = values[ i%values.length ];
97+
out = isStructDataType( v );
98+
if ( typeof out !== 'boolean' ) {
99+
b.fail( 'should return a boolean' );
100+
}
101+
}
102+
b.toc();
103+
if ( !isBoolean( out ) ) {
104+
b.fail( 'should return a boolean' );
105+
}
106+
b.pass( 'benchmark finished' );
107+
b.end();
108+
});

0 commit comments

Comments
 (0)