Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jun 29, 2024
1 parent ec6abcd commit f1a67c3
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ This release closes the following issue:

##### Features

- [`d1ef4ee`](https://github.com/stdlib-js/stdlib/commit/d1ef4ee589cb2a7a0d8bbc0b37be3cf3b7a6aad2) - add boolean dtype support to `array/base/count-same-value-zero` [(#2474)](https://github.com/stdlib-js/stdlib/pull/2474)
- [`1ed81b7`](https://github.com/stdlib-js/stdlib/commit/1ed81b78fd6469d374c7b033f258e709934539b2) - add `array/base/count-same-value-zero` [(##1384)](#1384)

</section>
Expand Down Expand Up @@ -2288,6 +2289,7 @@ A total of 13 people contributed to this release. Thank you to the following con

<details>

- [`d1ef4ee`](https://github.com/stdlib-js/stdlib/commit/d1ef4ee589cb2a7a0d8bbc0b37be3cf3b7a6aad2) - **feat:** add boolean dtype support to `array/base/count-same-value-zero` [(#2474)](https://github.com/stdlib-js/stdlib/pull/2474) _(by Jaysukh Makvana, Athan Reines)_
- [`fd396b3`](https://github.com/stdlib-js/stdlib/commit/fd396b360cbca9c4c000d3f33eed5dfc18de6d6b) - **feat:** add boolean dtype support to `array/base/count-same-value` [(#2473)](https://github.com/stdlib-js/stdlib/pull/2473) _(by Jaysukh Makvana, Athan Reines)_
- [`29615af`](https://github.com/stdlib-js/stdlib/commit/29615af970796a43f65f4b00d29bd23a122f2208) - **feat:** add `slice` and `subarray` methods to `array/bool` [(#2472)](https://github.com/stdlib-js/stdlib/pull/2472) _(by Jaysukh Makvana, Athan Reines)_
- [`83044a1`](https://github.com/stdlib-js/stdlib/commit/83044a19f51a143c06d5bb59900d08e02f66e3c4) - **docs:** update namespace TypeScript declarations [(#2465)](https://github.com/stdlib-js/stdlib/pull/2465) _(by stdlib-bot, Athan Reines)_
Expand Down
43 changes: 43 additions & 0 deletions base/count-same-value-zero/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
// MODULES //

var isComplexTypedArray = require( './../../../base/assert/is-complex-typed-array' );
var isBooleanArray = require( './../../../base/assert/is-booleanarray' );
var isComplexLike = require( '@stdlib/assert/is-complex-like' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var real = require( '@stdlib/complex/real' );
var imag = require( '@stdlib/complex/imag' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex' );
var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' );
var isAccessorArray = require( './../../../base/assert/is-accessor-array' );
var resolveGetter = require( './../../../base/resolve-getter' );
var isSameValueZero = require( '@stdlib/assert/is-same-value-zero' );
Expand Down Expand Up @@ -132,6 +135,43 @@ function complex( x, value ) {
return n;
}

/**
* Counts the number of elements in a boolean array that are equal to a specified value.
*
* @private
* @param {Collection} x - input array
* @param {*} value - search value
* @returns {NonNegativeInteger} number of elements that are equal to a specified value
*
* @example
* var BooleanArray = require( '@stdlib/array/bool' );
*
* var x = new BooleanArray( [ true, false, true, false, true ] );
*
* var n = boolean( x, true );
* // returns 3
*/
function boolean( x, value ) {
var view;
var n;
var v;
var i;

if ( !isBoolean( value ) ) {
return 0;
}
view = reinterpretBoolean( x, 0 );

v = ( value ) ? 1 : 0;
n = 0;
for ( i = 0; i < view.length; i++ ) {
if ( view[ i ] === v ) {
n += 1;
}
}
return n;
}


// MAIN //

Expand Down Expand Up @@ -160,6 +200,9 @@ function countSameValueZero( x, value ) {
if ( isComplexTypedArray( x, value ) ) {
return complex( x, value );
}
if ( isBooleanArray( x, value ) ) {
return boolean( x, value );
}
return accessors( x, value );
}
return indexed( x, value );
Expand Down
26 changes: 26 additions & 0 deletions base/count-same-value-zero/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
var tape = require( 'tape' );
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var Complex128Array = require( './../../../complex128' );
var BooleanArray = require( './../../../bool' );
var Int32Array = require( './../../../int32' );
var Float32Array = require( './../../../float32' );
var toAccessorArray = require( './../../../base/to-accessor-array' );
Expand Down Expand Up @@ -153,6 +154,31 @@ tape( 'the function considers all NaN values to be identical (real typed array)'
t.end();
});

tape( 'the function counts the number of same values (boolean array)', function test( t ) {
var expected;
var actual;
var x;

x = new BooleanArray( [ true, false, true, false, true ] );
expected = 3;
actual = countSameValueZero( x, true );

t.strictEqual( actual, expected, 'returns expected value' );

x = new BooleanArray( [ true, false, true, false, true ] );
expected = 2;
actual = countSameValueZero( x, false );

t.strictEqual( actual, expected, 'returns expected value' );

x = new BooleanArray( [ true, false, true, false, true ] );
expected = 0;
actual = countSameValueZero( x, 'beep' );

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

tape( 'the function counts the number of same values (complex typed array)', function test( t ) {
var expected;
var actual;
Expand Down

0 comments on commit f1a67c3

Please sign in to comment.