From 90f2104f7ec0f9bc0e4f09e3d2235dda86cc8baf Mon Sep 17 00:00:00 2001 From: Jaysukh-409 Date: Tue, 18 Jun 2024 23:06:01 +0530 Subject: [PATCH 1/4] feat: add boolean dtype support in array/base/assert/has-same-values --- .../base/assert/has-same-values/lib/main.js | 10 ++++ .../base/assert/has-same-values/test/test.js | 48 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/lib/node_modules/@stdlib/array/base/assert/has-same-values/lib/main.js b/lib/node_modules/@stdlib/array/base/assert/has-same-values/lib/main.js index b98e05a9d882..3e812d884876 100644 --- a/lib/node_modules/@stdlib/array/base/assert/has-same-values/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/assert/has-same-values/lib/main.js @@ -22,9 +22,11 @@ var isComplex128Array = require( '@stdlib/array/base/assert/is-complex128array' ); var isComplex64Array = require( '@stdlib/array/base/assert/is-complex64array' ); +var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' ); var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); +var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' ); var isSameValue = require( '@stdlib/assert/is-same-value' ); @@ -150,6 +152,14 @@ function hasSameValues( x, y ) { if ( xo.accessorProtocol || yo.accessorProtocol ) { FLG = 2; + // If provided a boolean array, reinterpret as an uint8 typed array and test... + if ( isBooleanArray( x ) ) { + if ( isBooleanArray( y ) ) { + return internal( reinterpretBoolean( x, 0 ), reinterpretBoolean( y, 0 ) ); + } + return accessors( xo, yo ); + } + // If provided a complex number array, reinterpret as a real typed array and test interleaved real and imaginary components... if ( isComplex128Array( x ) ) { xr = reinterpret128( x, 0 ); diff --git a/lib/node_modules/@stdlib/array/base/assert/has-same-values/test/test.js b/lib/node_modules/@stdlib/array/base/assert/has-same-values/test/test.js index 19ddf560565f..666657a455b1 100644 --- a/lib/node_modules/@stdlib/array/base/assert/has-same-values/test/test.js +++ b/lib/node_modules/@stdlib/array/base/assert/has-same-values/test/test.js @@ -25,6 +25,7 @@ var AccessorArray = require( '@stdlib/array/base/accessor' ); var Float64Array = require( '@stdlib/array/float64' ); var Complex64Array = require( '@stdlib/array/complex64' ); var Complex128Array = require( '@stdlib/array/complex128' ); +var BooleanArray = require( '@stdlib/array/bool' ); var hasSameValues = require( './../lib' ); @@ -111,6 +112,23 @@ tape( 'if provided empty collections, the function returns `true` (mixed)', func t.end(); }); +tape( 'if provided empty collections, the function returns `true` (boolean array)', function test( t ) { + var out; + var x; + var y; + + x = new BooleanArray( [] ); + out = hasSameValues( x, x ); + t.strictEqual( out, true, 'returns expected value' ); + + x = new BooleanArray( [] ); + y = new BooleanArray( [] ); + out = hasSameValues( x, y ); + t.strictEqual( out, true, 'returns expected value' ); + + t.end(); +}); + tape( 'if provided empty collections, the function returns `true` (complex typed array)', function test( t ) { var out; var x; @@ -206,6 +224,23 @@ tape( 'the function returns `true` if both arrays have the same values (mixed)', t.end(); }); +tape( 'the function returns `true` if both arrays have the same values (boolean array)', function test( t ) { + var out; + var x; + var y; + + x = new BooleanArray( [ true, false, true ] ); + out = hasSameValues( x, x ); + t.strictEqual( out, true, 'returns expected value' ); + + x = new BooleanArray( [ true, false, true ] ); + y = new BooleanArray( [ true, false, true ] ); + out = hasSameValues( x, y ); + t.strictEqual( out, true, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns `true` if both arrays have the same values (real typed array)', function test( t ) { var out; var x; @@ -330,6 +365,19 @@ tape( 'the function returns `false` if both arrays do not have the same values ( t.end(); }); +tape( 'the function returns `false` if both arrays do not have the same values (boolean array)', function test( t ) { + var out; + var x; + var y; + + x = new BooleanArray( [ true, false, false, true ] ); + y = new BooleanArray( [ true, true, false, false ] ); + out = hasSameValues( x, y ); + t.strictEqual( out, false, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns `false` if both arrays do not have the same values (complex typed array)', function test( t ) { var out; var x; From 9caa6253c921dea3a3ee971e2c2ed7248075f046 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 18 Jun 2024 12:44:04 -0700 Subject: [PATCH 2/4] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/array/base/assert/has-same-values/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/base/assert/has-same-values/lib/main.js b/lib/node_modules/@stdlib/array/base/assert/has-same-values/lib/main.js index 3e812d884876..17fa9a56f0f5 100644 --- a/lib/node_modules/@stdlib/array/base/assert/has-same-values/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/assert/has-same-values/lib/main.js @@ -152,7 +152,7 @@ function hasSameValues( x, y ) { if ( xo.accessorProtocol || yo.accessorProtocol ) { FLG = 2; - // If provided a boolean array, reinterpret as an uint8 typed array and test... + // If provided boolean arrays, reinterpret the array to avoid using accessors to access array elements... if ( isBooleanArray( x ) ) { if ( isBooleanArray( y ) ) { return internal( reinterpretBoolean( x, 0 ), reinterpretBoolean( y, 0 ) ); From dfb8a5dbf2e59d61bb4f61f7a642065a5dce5d12 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 18 Jun 2024 12:44:23 -0700 Subject: [PATCH 3/4] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/array/base/assert/has-same-values/lib/main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/base/assert/has-same-values/lib/main.js b/lib/node_modules/@stdlib/array/base/assert/has-same-values/lib/main.js index 17fa9a56f0f5..b4739dcf3b11 100644 --- a/lib/node_modules/@stdlib/array/base/assert/has-same-values/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/assert/has-same-values/lib/main.js @@ -159,7 +159,6 @@ function hasSameValues( x, y ) { } return accessors( xo, yo ); } - // If provided a complex number array, reinterpret as a real typed array and test interleaved real and imaginary components... if ( isComplex128Array( x ) ) { xr = reinterpret128( x, 0 ); From a5e4d04393681f7cdbb63f4491798933bf60b38a Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 18 Jun 2024 12:46:49 -0700 Subject: [PATCH 4/4] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/array/base/assert/has-same-values/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/base/assert/has-same-values/lib/main.js b/lib/node_modules/@stdlib/array/base/assert/has-same-values/lib/main.js index b4739dcf3b11..62d32db9ec6c 100644 --- a/lib/node_modules/@stdlib/array/base/assert/has-same-values/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/assert/has-same-values/lib/main.js @@ -152,7 +152,7 @@ function hasSameValues( x, y ) { if ( xo.accessorProtocol || yo.accessorProtocol ) { FLG = 2; - // If provided boolean arrays, reinterpret the array to avoid using accessors to access array elements... + // If provided boolean arrays, reinterpret the arrays to avoid using accessors to access array elements... if ( isBooleanArray( x ) ) { if ( isBooleanArray( y ) ) { return internal( reinterpretBoolean( x, 0 ), reinterpretBoolean( y, 0 ) );