From 9c7a3a435f886989e4fdbc0751b09454e9da6304 Mon Sep 17 00:00:00 2001 From: Jaysukh-409 Date: Wed, 10 Jul 2024 18:52:38 +0530 Subject: [PATCH 1/4] feat: add boolean dtype support to ndarray/dtypes --- .../@stdlib/ndarray/dtypes/README.md | 4 +++- .../@stdlib/ndarray/dtypes/docs/repl.txt | 1 + .../@stdlib/ndarray/dtypes/lib/dtypes.json | 5 +++++ .../@stdlib/ndarray/dtypes/test/test.js | 20 ++++++++++++++++++- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/dtypes/README.md b/lib/node_modules/@stdlib/ndarray/dtypes/README.md index 2ecd8167b86a..9ebc045d9b08 100644 --- a/lib/node_modules/@stdlib/ndarray/dtypes/README.md +++ b/lib/node_modules/@stdlib/ndarray/dtypes/README.md @@ -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. @@ -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. @@ -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 values. - `integer`: integer data types. - `signed_integer`: signed integer data types. - `unsigned_integer`: unsigned integer data types. diff --git a/lib/node_modules/@stdlib/ndarray/dtypes/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/dtypes/docs/repl.txt index e653135cc001..796d25392e10 100644 --- a/lib/node_modules/@stdlib/ndarray/dtypes/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/dtypes/docs/repl.txt @@ -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 values. - integer: integer data types. - signed_integer: signed integer data types. - unsigned_integer: unsigned integer data types. diff --git a/lib/node_modules/@stdlib/ndarray/dtypes/lib/dtypes.json b/lib/node_modules/@stdlib/ndarray/dtypes/lib/dtypes.json index d9aacf2350e5..388acce3abde 100644 --- a/lib/node_modules/@stdlib/ndarray/dtypes/lib/dtypes.json +++ b/lib/node_modules/@stdlib/ndarray/dtypes/lib/dtypes.json @@ -1,6 +1,7 @@ { "all": [ "binary", + "bool", "complex64", "complex128", "float32", @@ -16,6 +17,7 @@ ], "typed": [ "binary", + "bool", "complex64", "complex128", "float32", @@ -42,6 +44,9 @@ "complex64", "complex128" ], + "boolean": [ + "bool" + ], "integer": [ "int16", "int32", diff --git a/lib/node_modules/@stdlib/ndarray/dtypes/test/test.js b/lib/node_modules/@stdlib/ndarray/dtypes/test/test.js index 863ded24bab8..adc13f6a9d82 100644 --- a/lib/node_modules/@stdlib/ndarray/dtypes/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/dtypes/test/test.js @@ -43,7 +43,9 @@ var DTYPES = [ 'float64', 'complex64', - 'complex128' + 'complex128', + + 'bool' ]; @@ -61,6 +63,7 @@ tape( 'the function returns a list of ndarray data types', function test( t ) { expected = [ 'binary', + 'bool', 'complex64', 'complex128', 'float32', @@ -86,6 +89,7 @@ tape( 'the function supports returning a list of ndarray data types (all)', func expected = [ 'binary', + 'bool', 'complex64', 'complex128', 'float32', @@ -111,6 +115,7 @@ tape( 'the function supports returning a list of ndarray data types (typed)', fu expected = [ 'binary', + 'bool', 'complex64', 'complex128', 'float32', @@ -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 values 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; From 47cd44d5aaae537593b151cd59d39f252668abfb Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 13 Jul 2024 01:29:20 -0700 Subject: [PATCH 2/4] feat: add boolean dtype and update data type kinds --- lib/node_modules/@stdlib/types/index.d.ts | 68 +++++++++++++++++++++-- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/types/index.d.ts b/lib/node_modules/@stdlib/types/index.d.ts index d982705d4fbc..055e22a26622 100644 --- a/lib/node_modules/@stdlib/types/index.d.ts +++ b/lib/node_modules/@stdlib/types/index.d.ts @@ -1391,62 +1391,122 @@ declare module '@stdlib/types/ndarray' { /** * 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. From 1bd4cda1370ed37583a6fb6a66c5ae8f61a25fba Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 13 Jul 2024 01:34:05 -0700 Subject: [PATCH 3/4] docs: update examples and fix descriptions --- lib/node_modules/@stdlib/ndarray/dtypes/README.md | 13 +++---------- .../@stdlib/ndarray/dtypes/examples/index.js | 11 ++--------- .../@stdlib/ndarray/dtypes/test/test.js | 2 +- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/dtypes/README.md b/lib/node_modules/@stdlib/ndarray/dtypes/README.md index 9ebc045d9b08..c9885cf90bf9 100644 --- a/lib/node_modules/@stdlib/ndarray/dtypes/README.md +++ b/lib/node_modules/@stdlib/ndarray/dtypes/README.md @@ -78,7 +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 values. +- `boolean`: boolean data types. - `integer`: integer data types. - `signed_integer`: signed integer data types. - `unsigned_integer`: unsigned integer data types. @@ -108,17 +108,10 @@ The function supports the following data type kinds: ```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 diff --git a/lib/node_modules/@stdlib/ndarray/dtypes/examples/index.js b/lib/node_modules/@stdlib/ndarray/dtypes/examples/index.js index dffc96660208..c781abb1f6a8 100644 --- a/lib/node_modules/@stdlib/ndarray/dtypes/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/dtypes/examples/index.js @@ -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 ); diff --git a/lib/node_modules/@stdlib/ndarray/dtypes/test/test.js b/lib/node_modules/@stdlib/ndarray/dtypes/test/test.js index adc13f6a9d82..73b146758fe1 100644 --- a/lib/node_modules/@stdlib/ndarray/dtypes/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/dtypes/test/test.js @@ -178,7 +178,7 @@ tape( 'the function supports returning a list of complex-valued floating-point n t.end(); }); -tape( 'the function supports returning a list of boolean values ndarray data types', function test( t ) { +tape( 'the function supports returning a list of boolean ndarray data types', function test( t ) { var expected; var actual; From 3aedab0cffe00bd9dc4f4d8c6a5807cb95130efb Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 13 Jul 2024 01:35:01 -0700 Subject: [PATCH 4/4] docs: fix description --- lib/node_modules/@stdlib/ndarray/dtypes/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/dtypes/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/dtypes/docs/repl.txt index 796d25392e10..8d41c200d8aa 100644 --- a/lib/node_modules/@stdlib/ndarray/dtypes/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/dtypes/docs/repl.txt @@ -7,7 +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 values. + - boolean: boolean data types. - integer: integer data types. - signed_integer: signed integer data types. - unsigned_integer: unsigned integer data types.