Skip to content

Commit 16e0808

Browse files
Jaysukh-409kgryte
andauthored
feat: add boolean dtype support to ndarray/dtypes
PR-URL: #2550 Ref: #2547 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 66dce03 commit 16e0808

File tree

6 files changed

+96
-24
lines changed

6 files changed

+96
-24
lines changed

lib/node_modules/@stdlib/ndarray/dtypes/README.md

+5-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2018 The Stdlib Authors.
5+
Copyright (c) 2024 The Stdlib Authors.
66
77
Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.
@@ -52,6 +52,7 @@ var out = dtypes();
5252
When not provided a data type "kind", the function returns an array containing the following data types:
5353

5454
- `binary`: binary.
55+
- `bool`: boolean values.
5556
- `complex64`: single-precision complex floating-point numbers.
5657
- `complex128`: double-precision complex floating-point numbers.
5758
- `float32`: single-precision floating-point numbers.
@@ -77,6 +78,7 @@ The function supports the following data type kinds:
7778
- `floating_point`: floating-point data types.
7879
- `real_floating_point`: real-valued floating-point data types.
7980
- `complex_floating_point`: complex-valued floating-point data types.
81+
- `boolean`: boolean data types.
8082
- `integer`: integer data types.
8183
- `signed_integer`: signed integer data types.
8284
- `unsigned_integer`: unsigned integer data types.
@@ -106,17 +108,10 @@ The function supports the following data type kinds:
106108
<!-- eslint no-undef: "error" -->
107109

108110
```javascript
109-
var indexOf = require( '@stdlib/utils/index-of' );
111+
var contains = require( '@stdlib/array/base/assert/contains' ).factory;
110112
var dtypes = require( '@stdlib/ndarray/dtypes' );
111113

112-
var DTYPES = dtypes();
113-
114-
function isdtype( str ) {
115-
if ( indexOf( DTYPES, str ) === -1 ) {
116-
return false;
117-
}
118-
return true;
119-
}
114+
var isdtype = contains( dtypes() );
120115

121116
var bool = isdtype( 'float64' );
122117
// returns true

lib/node_modules/@stdlib/ndarray/dtypes/docs/repl.txt

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- floating_point: floating-point data types.
88
- real_floating_point: real-valued floating-point data types.
99
- complex_floating_point: complex-valued floating-point data types.
10+
- boolean: boolean data types.
1011
- integer: integer data types.
1112
- signed_integer: signed integer data types.
1213
- unsigned_integer: unsigned integer data types.

lib/node_modules/@stdlib/ndarray/dtypes/examples/index.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,10 @@
1818

1919
'use strict';
2020

21-
var indexOf = require( '@stdlib/utils/index-of' );
21+
var contains = require( '@stdlib/array/base/assert/contains' ).factory;
2222
var dtypes = require( './../lib' );
2323

24-
var DTYPES = dtypes();
25-
26-
function isdtype( str ) {
27-
if ( indexOf( DTYPES, str ) === -1 ) {
28-
return false;
29-
}
30-
return true;
31-
}
24+
var isdtype = contains( dtypes() );
3225

3326
var bool = isdtype( 'float64' );
3427
console.log( bool );

lib/node_modules/@stdlib/ndarray/dtypes/lib/dtypes.json

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"all": [
33
"binary",
4+
"bool",
45
"complex64",
56
"complex128",
67
"float32",
@@ -16,6 +17,7 @@
1617
],
1718
"typed": [
1819
"binary",
20+
"bool",
1921
"complex64",
2022
"complex128",
2123
"float32",
@@ -42,6 +44,9 @@
4244
"complex64",
4345
"complex128"
4446
],
47+
"boolean": [
48+
"bool"
49+
],
4550
"integer": [
4651
"int16",
4752
"int32",

lib/node_modules/@stdlib/ndarray/dtypes/test/test.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ var DTYPES = [
4343
'float64',
4444

4545
'complex64',
46-
'complex128'
46+
'complex128',
47+
48+
'bool'
4749
];
4850

4951

@@ -61,6 +63,7 @@ tape( 'the function returns a list of ndarray data types', function test( t ) {
6163

6264
expected = [
6365
'binary',
66+
'bool',
6467
'complex64',
6568
'complex128',
6669
'float32',
@@ -86,6 +89,7 @@ tape( 'the function supports returning a list of ndarray data types (all)', func
8689

8790
expected = [
8891
'binary',
92+
'bool',
8993
'complex64',
9094
'complex128',
9195
'float32',
@@ -111,6 +115,7 @@ tape( 'the function supports returning a list of ndarray data types (typed)', fu
111115

112116
expected = [
113117
'binary',
118+
'bool',
114119
'complex64',
115120
'complex128',
116121
'float32',
@@ -173,6 +178,19 @@ tape( 'the function supports returning a list of complex-valued floating-point n
173178
t.end();
174179
});
175180

181+
tape( 'the function supports returning a list of boolean ndarray data types', function test( t ) {
182+
var expected;
183+
var actual;
184+
185+
expected = [
186+
'bool'
187+
];
188+
actual = dtypes( 'boolean' );
189+
190+
t.deepEqual( actual, expected, 'returns expected value' );
191+
t.end();
192+
});
193+
176194
tape( 'the function supports returning a list of integer ndarray data types', function test( t ) {
177195
var expected;
178196
var actual;

lib/node_modules/@stdlib/types/index.d.ts

+64-4
Original file line numberDiff line numberDiff line change
@@ -1391,62 +1391,122 @@ declare module '@stdlib/types/ndarray' {
13911391
/**
13921392
* Data type.
13931393
*/
1394-
type DataType = NumericDataType | 'binary' | 'generic'; // "all"
1394+
type DataType = NumericDataType | BooleanDataType | 'binary' | 'generic'; // "all"
13951395

13961396
/**
13971397
* Data type for real-valued ndarrays.
13981398
*/
13991399
type RealDataType = RealFloatingPointDataType | IntegerDataType; // "real"
14001400

1401+
/**
1402+
* Data type for real-valued ndarrays.
1403+
*/
1404+
type RealAndGenericDataType = RealDataType | 'generic'; // "real_and_generic"
1405+
14011406
/**
14021407
* Data type for floating-point ndarrays.
14031408
*/
14041409
type RealFloatingPointDataType = 'float64' | 'float32'; // "real_floating_point"
14051410

1411+
/**
1412+
* Data type for floating-point ndarrays.
1413+
*/
1414+
type RealFloatingPointAndGenericDataType = RealFloatingPointDataType | 'generic'; // "real_floating_point_and_generic"
1415+
14061416
/**
14071417
* Data type for integer ndarrays.
14081418
*/
14091419
type IntegerDataType = SignedIntegerDataType | UnsignedIntegerDataType; // "integer"
14101420

1421+
/**
1422+
* Data type for integer ndarrays.
1423+
*/
1424+
type IntegerAndGenericDataType = IntegerDataType | 'generic'; // "integer_and_generic"
1425+
14111426
/**
14121427
* Data type for signed integer ndarrays.
14131428
*/
14141429
type SignedIntegerDataType = 'int32' | 'int16' | 'int8'; // "signed_integer"
14151430

1431+
/**
1432+
* Data type for signed integer ndarrays.
1433+
*/
1434+
type SignedIntegerAndGenericDataType = SignedIntegerDataType | 'generic'; // "signed_integer_and_generic"
1435+
14161436
/**
14171437
* Data type for unsigned integer ndarrays.
14181438
*/
14191439
type UnsignedIntegerDataType = 'uint32' | 'uint16' | 'uint8' | 'uint8c'; // "unsigned_integer"
14201440

1441+
/**
1442+
* Data type for unsigned integer ndarrays.
1443+
*/
1444+
type UnsignedIntegerAndGenericDataType = UnsignedIntegerDataType | 'generic'; // "unsigned_integer_and_generic"
1445+
14211446
/**
14221447
* Data type for complex number ndarrays.
14231448
*/
14241449
type ComplexFloatingPointDataType = 'complex64' | 'complex128'; // "complex_floating_point"
14251450

1451+
/**
1452+
* Data type for complex number ndarrays.
1453+
*/
1454+
type ComplexFloatingPointAndGenericDataType = ComplexFloatingPointDataType | 'generic'; // "complex_floating_point_and_generic"
1455+
14261456
/**
14271457
* Data type for floating-point real or complex ndarrays.
14281458
*/
14291459
type FloatingPointDataType = RealFloatingPointDataType | ComplexFloatingPointDataType; // "floating_point"
14301460

1461+
/**
1462+
* Data type for floating-point real or complex ndarrays.
1463+
*/
1464+
type FloatingPointAndGenericDataType = FloatingPointDataType | 'generic'; // "floating_point_and_generic"
1465+
14311466
/**
14321467
* Data type for real-valued or complex number ndarrays.
14331468
*/
14341469
type NumericDataType = RealDataType | ComplexFloatingPointDataType; // "numeric"
14351470

1471+
/**
1472+
* Data type for real-valued or complex number ndarrays.
1473+
*/
1474+
type NumericAndGenericDataType = NumericDataType | 'generic'; // "numeric_and_generic"
1475+
1476+
/**
1477+
* Data type for boolean typed arrays.
1478+
*/
1479+
type BooleanDataType = 'bool'; // "boolean"
1480+
1481+
/**
1482+
* Data type for boolean and generic ndarrays.
1483+
*/
1484+
type BooleanAndGenericDataType = BooleanDataType | 'generic'; // "boolean_and_generic"
1485+
14361486
/**
14371487
* Data type for strictly "typed" ndarrays.
14381488
*/
1439-
type TypedDataType = NumericDataType; // "typed"
1489+
type TypedDataType = NumericDataType | BooleanDataType; // "typed"
1490+
1491+
/**
1492+
* Data type for strictly typed and generic ndarrays.
1493+
*/
1494+
type TypedAndGenericDataType = TypedDataType | 'generic'; // "typed_and_generic"
1495+
1496+
/**
1497+
* Strict data type "kinds".
1498+
*/
1499+
type StrictDataTypeKind = 'typed' | 'numeric' | 'real' | 'floating_point' | 'real_floating_point' | 'complex_floating_point' | 'integer' | 'signed_integer' | 'unsigned_integer' | 'boolean';
14401500

14411501
/**
14421502
* Data type "kinds".
14431503
*/
1444-
type DataTypeKind = 'all' | 'typed' | 'numeric' | 'real' | 'floating_point' | 'real_floating_point' | 'complex_floating_point' | 'integer' | 'signed_integer' | 'unsigned_integer';
1504+
type DataTypeKind = StrictDataTypeKind | 'all' | 'typed_and_generic' | 'numeric_and_generic' | 'real_and_generic' | 'floating_point_and_generic' | 'real_floating_point_and_generic' | 'complex_floating_point_and_generic' | 'integer_and_generic' | 'signed_integer_and_generic' | 'unsigned_integer_and_generic' | 'boolean_and_generic';
14451505

14461506
/**
14471507
* Output data type policy.
14481508
*/
1449-
type OutputPolicy = 'default' | 'same' | 'promoted' | 'bool' | 'numeric' | 'real' | 'floating_point' | 'real_floating_point' | 'complex_floating_point' | 'integer' | 'signed_integer' | 'unsigned_integer';
1509+
type OutputPolicy = 'default' | 'same' | 'promoted' | 'boolean' | 'numeric' | 'real' | 'floating_point' | 'real_floating_point' | 'complex_floating_point' | 'integer' | 'signed_integer' | 'unsigned_integer';
14501510

14511511
/**
14521512
* Array order.

0 commit comments

Comments
 (0)