Skip to content

feat: add boolean dtype support to ndarray/dtypes #2550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions lib/node_modules/@stdlib/ndarray/dtypes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@license Apache-2.0

Copyright (c) 2018 The Stdlib Authors.
Copyright (c) 2024 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -52,6 +52,7 @@ var out = dtypes();
When not provided a data type "kind", the function returns an array containing the following data types:

- `binary`: binary.
- `bool`: boolean values.
- `complex64`: single-precision complex floating-point numbers.
- `complex128`: double-precision complex floating-point numbers.
- `float32`: single-precision floating-point numbers.
Expand All @@ -77,6 +78,7 @@ The function supports the following data type kinds:
- `floating_point`: floating-point data types.
- `real_floating_point`: real-valued floating-point data types.
- `complex_floating_point`: complex-valued floating-point data types.
- `boolean`: boolean data types.
- `integer`: integer data types.
- `signed_integer`: signed integer data types.
- `unsigned_integer`: unsigned integer data types.
Expand Down Expand Up @@ -106,17 +108,10 @@ The function supports the following data type kinds:
<!-- eslint no-undef: "error" -->

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

var DTYPES = dtypes();

function isdtype( str ) {
if ( indexOf( DTYPES, str ) === -1 ) {
return false;
}
return true;
}
var isdtype = contains( dtypes() );

var bool = isdtype( 'float64' );
// returns true
Expand Down
1 change: 1 addition & 0 deletions lib/node_modules/@stdlib/ndarray/dtypes/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- floating_point: floating-point data types.
- real_floating_point: real-valued floating-point data types.
- complex_floating_point: complex-valued floating-point data types.
- boolean: boolean data types.
- integer: integer data types.
- signed_integer: signed integer data types.
- unsigned_integer: unsigned integer data types.
Expand Down
11 changes: 2 additions & 9 deletions lib/node_modules/@stdlib/ndarray/dtypes/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,10 @@

'use strict';

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

var DTYPES = dtypes();

function isdtype( str ) {
if ( indexOf( DTYPES, str ) === -1 ) {
return false;
}
return true;
}
var isdtype = contains( dtypes() );

var bool = isdtype( 'float64' );
console.log( bool );
Expand Down
5 changes: 5 additions & 0 deletions lib/node_modules/@stdlib/ndarray/dtypes/lib/dtypes.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"all": [
"binary",
"bool",
"complex64",
"complex128",
"float32",
Expand All @@ -16,6 +17,7 @@
],
"typed": [
"binary",
"bool",
"complex64",
"complex128",
"float32",
Expand All @@ -42,6 +44,9 @@
"complex64",
"complex128"
],
"boolean": [
"bool"
],
"integer": [
"int16",
"int32",
Expand Down
20 changes: 19 additions & 1 deletion lib/node_modules/@stdlib/ndarray/dtypes/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ var DTYPES = [
'float64',

'complex64',
'complex128'
'complex128',

'bool'
];


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

expected = [
'binary',
'bool',
'complex64',
'complex128',
'float32',
Expand All @@ -86,6 +89,7 @@ tape( 'the function supports returning a list of ndarray data types (all)', func

expected = [
'binary',
'bool',
'complex64',
'complex128',
'float32',
Expand All @@ -111,6 +115,7 @@ tape( 'the function supports returning a list of ndarray data types (typed)', fu

expected = [
'binary',
'bool',
'complex64',
'complex128',
'float32',
Expand Down Expand Up @@ -173,6 +178,19 @@ tape( 'the function supports returning a list of complex-valued floating-point n
t.end();
});

tape( 'the function supports returning a list of boolean ndarray data types', function test( t ) {
var expected;
var actual;

expected = [
'bool'
];
actual = dtypes( 'boolean' );

t.deepEqual( actual, expected, 'returns expected value' );
t.end();
});

tape( 'the function supports returning a list of integer ndarray data types', function test( t ) {
var expected;
var actual;
Expand Down
68 changes: 64 additions & 4 deletions lib/node_modules/@stdlib/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1391,62 +1391,122 @@
/**
* Data type.
*/
type DataType = NumericDataType | 'binary' | 'generic'; // "all"
type DataType = NumericDataType | BooleanDataType | 'binary' | 'generic'; // "all"

/**
* Data type for real-valued ndarrays.
*/
type RealDataType = RealFloatingPointDataType | IntegerDataType; // "real"

/**
* Data type for real-valued ndarrays.
*/
type RealAndGenericDataType = RealDataType | 'generic'; // "real_and_generic"

/**
* Data type for floating-point ndarrays.
*/
type RealFloatingPointDataType = 'float64' | 'float32'; // "real_floating_point"

/**
* Data type for floating-point ndarrays.
*/
type RealFloatingPointAndGenericDataType = RealFloatingPointDataType | 'generic'; // "real_floating_point_and_generic"

/**
* Data type for integer ndarrays.
*/
type IntegerDataType = SignedIntegerDataType | UnsignedIntegerDataType; // "integer"

/**
* Data type for integer ndarrays.
*/
type IntegerAndGenericDataType = IntegerDataType | 'generic'; // "integer_and_generic"

/**
* Data type for signed integer ndarrays.
*/
type SignedIntegerDataType = 'int32' | 'int16' | 'int8'; // "signed_integer"

/**
* Data type for signed integer ndarrays.
*/
type SignedIntegerAndGenericDataType = SignedIntegerDataType | 'generic'; // "signed_integer_and_generic"

/**
* Data type for unsigned integer ndarrays.
*/
type UnsignedIntegerDataType = 'uint32' | 'uint16' | 'uint8' | 'uint8c'; // "unsigned_integer"

/**
* Data type for unsigned integer ndarrays.
*/
type UnsignedIntegerAndGenericDataType = UnsignedIntegerDataType | 'generic'; // "unsigned_integer_and_generic"

/**
* Data type for complex number ndarrays.
*/
type ComplexFloatingPointDataType = 'complex64' | 'complex128'; // "complex_floating_point"

/**
* Data type for complex number ndarrays.
*/
type ComplexFloatingPointAndGenericDataType = ComplexFloatingPointDataType | 'generic'; // "complex_floating_point_and_generic"

/**
* Data type for floating-point real or complex ndarrays.
*/
type FloatingPointDataType = RealFloatingPointDataType | ComplexFloatingPointDataType; // "floating_point"

/**
* Data type for floating-point real or complex ndarrays.
*/
type FloatingPointAndGenericDataType = FloatingPointDataType | 'generic'; // "floating_point_and_generic"

/**
* Data type for real-valued or complex number ndarrays.
*/
type NumericDataType = RealDataType | ComplexFloatingPointDataType; // "numeric"

/**
* Data type for real-valued or complex number ndarrays.
*/
type NumericAndGenericDataType = NumericDataType | 'generic'; // "numeric_and_generic"

/**
* Data type for boolean typed arrays.
*/
type BooleanDataType = 'bool'; // "boolean"

/**
* Data type for boolean and generic ndarrays.
*/
type BooleanAndGenericDataType = BooleanDataType | 'generic'; // "boolean_and_generic"

/**
* Data type for strictly "typed" ndarrays.
*/
type TypedDataType = NumericDataType; // "typed"
type TypedDataType = NumericDataType | BooleanDataType; // "typed"

/**
* Data type for strictly typed and generic ndarrays.
*/
type TypedAndGenericDataType = TypedDataType | 'generic'; // "typed_and_generic"

/**
* Strict data type "kinds".
*/
type StrictDataTypeKind = 'typed' | 'numeric' | 'real' | 'floating_point' | 'real_floating_point' | 'complex_floating_point' | 'integer' | 'signed_integer' | 'unsigned_integer' | 'boolean';

/**
* Data type "kinds".
*/
type DataTypeKind = 'all' | 'typed' | 'numeric' | 'real' | 'floating_point' | 'real_floating_point' | 'complex_floating_point' | 'integer' | 'signed_integer' | 'unsigned_integer';
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';

/**
* Output data type policy.
*/
type OutputPolicy = 'default' | 'same' | 'promoted' | 'bool' | 'numeric' | 'real' | 'floating_point' | 'real_floating_point' | 'complex_floating_point' | 'integer' | 'signed_integer' | 'unsigned_integer';
type OutputPolicy = 'default' | 'same' | 'promoted' | 'boolean' | 'numeric' | 'real' | 'floating_point' | 'real_floating_point' | 'complex_floating_point' | 'integer' | 'signed_integer' | 'unsigned_integer';

/**
* Array order.
Expand Down Expand Up @@ -3313,7 +3373,7 @@
/**
* Value associated with a property (default: `undefined`).
*/
value?: any;

Check warning on line 3376 in lib/node_modules/@stdlib/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type
}

/**
Expand Down Expand Up @@ -3347,7 +3407,7 @@
* - When the property is accessed, the function is called without arguments and with `this` set to the object through which the property is accessed (note: this may **not** be the object on which the property is defined due to inheritance).
* - The return value will be used as the value of the property.
*/
get?(): any;

Check warning on line 3410 in lib/node_modules/@stdlib/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* A function which serves as a setter for the property.
Expand All @@ -3357,7 +3417,7 @@
* - If omitted from a descriptor, a property value cannot be assigned.
* - When the property is assigned to, the function is called with one argument (the value being assigned to the property) and with `this` set to the object through which the property is assigned.
*/
set?( x: any ): void;

Check warning on line 3420 in lib/node_modules/@stdlib/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type
}

/**
Expand Down Expand Up @@ -3486,7 +3546,7 @@
* @example
* const rand: PRNG = () => 3.14;
*/
type PRNG = ( ...args: Array<any> ) => number;

Check warning on line 3549 in lib/node_modules/@stdlib/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

/**
* A pseudorandom number generator (PRNG) seed for the 32-bit Mersenne Twister (MT19937) PRNG.
Expand Down
Loading