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 Mar 16, 2024
1 parent 52e3594 commit 5d6b6f8
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 53 deletions.
28 changes: 14 additions & 14 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@
#
# Contributors listed in alphabetical order.

Adarsh Palaskar <[email protected].com>
Aditya Sapra <[email protected].com>
Adarsh Palaskar <adarshpalaskar99@gmail.com>
Aditya Sapra <adityaework@gmail.com>
AgPriyanshu18 <[email protected]>
Ali Salesi <[email protected]>
Aman Bhansali <[email protected]>
Aman Bhansali <[email protected]>
Amit Jimiwal <[email protected]>
Anudeep Sanapala <[email protected].com>
Anudeep Sanapala <anudeep0306@gmail.com>
Athan Reines <[email protected]>
Brendan Graetz <[email protected]>
Bruno Fenzl <[email protected]>
Chinmay J <[email protected]>
Chinmay Joshi <[email protected]>
Christopher Dambamuromo <[email protected]>
Dan Rose <[email protected]>
Daniel Killenberger <[email protected]>
Dominik Moritz <[email protected]>
Dorrin Sotoudeh <[email protected]>
EuniceSim142 <[email protected]>
Frank Kovacs <[email protected]>
GUNJ JOSHI <gunjjoshi8372@gmail.com>
Golden <[email protected].com>
Golden Kumar <[email protected].com>
Gunj Joshi <gunjjoshi8372@gmail.com>
Harshita Kalani <[email protected]>
Jaimin Godhani <[email protected]>
James Gelok <[email protected]>
Expand Down Expand Up @@ -50,7 +50,7 @@ Pranav Goswami <[email protected]>
Praneki <[email protected]>
Pratik <[email protected]>
Priyansh <[email protected]>
Raunak Kumar Gupta <[email protected].com>
Raunak Kumar Gupta <raunakmodanwal321@gmail.com>
Rejoan Sardar <[email protected]>
Ricky Reusser <[email protected]>
Robert Gislason <[email protected]>
Expand All @@ -59,16 +59,16 @@ Rutam <[email protected]>
Ryan Seal <[email protected]>
Sai Srikar Dumpeti <[email protected]>
Seyyed Parsa Neshaei <[email protected]>
Shashank Shekhar Singh <[email protected].com>
Shashank Shekhar Singh <shashankshekharsingh1205@gmail.com>
Shraddheya Shendre <[email protected]>
Shubham <[email protected]>
Shubham Mishra <[email protected]>
Snehil Shah <[email protected]>
Spandan Barve <[email protected]>
Spandan Barve <[email protected]>
Stephannie Jiménez Gacha <[email protected]>
Utkarsh <[email protected]>
Utkarsh <http://[email protected]>
Utkarsh Raj <[email protected]>
Varad Gupta <[email protected]>
Yernar Yergaziyev <[email protected]>
nishant-s7 <[email protected]>
orimiles5 <[email protected]>
rei2hu <[email protected]>
utkarsh_raj <[email protected]>
vr-varad <[email protected]>
10 changes: 6 additions & 4 deletions base/count-same-value/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.

# countSameValue

> Count the number of elements that are equal to a given value in an array.
> Count the number of elements in an array that are equal to a specified value.
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

Expand All @@ -42,7 +42,7 @@ var countSameValue = require( '@stdlib/array/base/count-same-value' );

#### countSameValue( x, value )

Counts the number of elements that are equal to a given value in an array.
Counts the number of elements in an array that are equal to a specified value.

```javascript
var x = [ 0, 1, 0, 1, 2 ];
Expand Down Expand Up @@ -72,10 +72,12 @@ var out = countSameValue( x, 1 );
<!-- eslint no-undef: "error" -->

```javascript
var sample = require( '@stdlib/random/sample' );
var bernoulli = require( '@stdlib/random/array/bernoulli' );
var countSameValue = require( '@stdlib/array/base/count-same-value' );

var x = sample( [ 1, 2, 3, 4, 5 ] );
var x = bernoulli( 10, 0.5, {
'dtype': 'generic'
});
console.log( x );

var n = countSameValue( x, 1 );
Expand Down
5 changes: 3 additions & 2 deletions base/count-same-value/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

{{alias}}( x, value )
Counts the number of elements that are equal to a given value in an array.
Counts the number of elements in an array that are equal to a specified
value.

Parameters
----------
Expand All @@ -13,7 +14,7 @@
Returns
-------
out: integer
Number of elements that are equal to the given value.
Number of elements that are equal to the specified value.

Examples
--------
Expand Down
6 changes: 3 additions & 3 deletions base/count-same-value/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import { Collection } from '@stdlib/types/array';

/**
* Counts the number of elements that are equal to a given value in an array.
* Counts the number of elements in an array that are equal to a specified value.
*
* @param x - input array
* @param value - given value
* @returns number of elements that are equal to the given value
* @param value - search value
* @returns number of elements that are equal to a specified value
*
* @example
* var x = [ 0, 1, 0, 1, 1 ];
Expand Down
6 changes: 4 additions & 2 deletions base/count-same-value/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

'use strict';

var sample = require( '@stdlib/random/sample' );
var bernoulli = require( '@stdlib/random/array/bernoulli' );
var countSameValue = require( './../lib' );

var x = sample( [ 1, 2, 3, 4, 5 ] );
var x = bernoulli( 10, 0.5, {
'dtype': 'generic'
});
console.log( x );

var n = countSameValue( x, 1 );
Expand Down
2 changes: 1 addition & 1 deletion base/count-same-value/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'use strict';

/**
* Count the number of elements that are equal to a given value in an array.
* Count the number of elements in an array that are equal to a specified value.
*
* @module @stdlib/array/base/count-same-value
*
Expand Down
41 changes: 20 additions & 21 deletions base/count-same-value/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,30 @@
// MODULES //

var isComplexLike = require( '@stdlib/assert/is-complex-like' );
var real = require( '@stdlib/complex/real' );
var imag = require( '@stdlib/complex/imag' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex' );
var isComplexTypedArray = require( './../../../base/assert/is-complex-typed-array' );
var isAccessorArray = require( './../../../base/assert/is-accessor-array' );
var resolveGetter = require( './../../../base/resolve-getter' );
var isSameValue = require( '@stdlib/assert/is-same-value' );
var real = require( '@stdlib/complex/real' );
var imag = require( '@stdlib/complex/imag' );


// FUNCTIONS //

/**
* Counts the number of elements that are equal to a given value in an indexed array.
* Counts the number of elements in an array that are equal to a specified value.
*
* @private
* @param {Collection} x - input array
* @param {*} value - given value
* @returns {NonNegativeInteger} number of elements that are equal to the given value
* @param {*} value - search value
* @returns {NonNegativeInteger} number of elements that are equal to a specified value
*
* @example
* var x = [ 0, 1, 0, 1 ];
* var x = [ 0, 1, 0, 1, 1 ];
*
* var n = indexed( x, 1 );
* // returns 2
* // returns 3
*/
function indexed( x, value ) {
var n;
Expand All @@ -60,20 +60,20 @@ function indexed( x, value ) {
}

/**
* Counts the number of elements that are equal to a given value in an accessor array.
* Counts the number of elements in an accessor array that are equal to a specified value.
*
* @private
* @param {Collection} x - input array
* @param {*} value - given value
* @returns {NonNegativeInteger} number of elements that are equal to the given value
* @param {*} value - search value
* @returns {NonNegativeInteger} number of elements that are equal to a provided value
*
* @example
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
*
* var x = toAccessorArray( [ 0, 1, 0, 1 ] );
* var x = toAccessorArray( [ 0, 1, 0, 1, 1 ] );
*
* var n = accessors( x, 1 );
* // returns 2
* // returns 3
*/
function accessors( x, value ) {
var get;
Expand All @@ -92,16 +92,16 @@ function accessors( x, value ) {
}

/**
* Counts the number of elements that are equal to a given value in a complex array.
* Counts the number of elements in a complex array that are equal to a specified value.
*
* @private
* @param {Collection} x - input array
* @param {*} value - given value
* @returns {NonNegativeInteger} number of elements that are equal to the given value
* @param {*} value - search value
* @returns {NonNegativeInteger} number of elements that are equal to a specified value
*
* @example
* var Complex128 = require( '@stdlib/complex/float64' );
* var Complex128Array = require( '@stdlib/array/complex128' );
* var Complex128 = require( '@stdlib/complex/float64' );
*
* var x = new Complex128Array( [ 1.0, 2.0, 0.0, 0.0, 3.0, 4.0, 0.0, 0.0 ] );
*
Expand All @@ -118,15 +118,14 @@ function complex( x, value ) {
if ( !isComplexLike( value ) ) {
return 0;
}

re = real( value );
im = imag( value );

view = reinterpret( x, 0 );

n = 0;
for ( i = 0; i < view.length; i += 2 ) {
if ( isSameValue( view[ i ], re ) && isSameValue( view[ i + 1 ], im ) ) {
if ( isSameValue( view[ i ], re ) && isSameValue( view[ i+1 ], im ) ) {
n += 1;
}
}
Expand All @@ -137,11 +136,11 @@ function complex( x, value ) {
// MAIN //

/**
* Counts the number of elements that are equal to a given value in an array.
* Counts the number of elements in an array that are equal to a specified value.
*
* @param {Collection} x - input array
* @param {*} value - given value
* @returns {NonNegativeInteger} number of elements that are equal to the given value
* @param {*} value - search value
* @returns {NonNegativeInteger} number of elements that are equal to a specified value
*
* @example
* var x = [ 0, 1, 0, 1, 1 ];
Expand Down
5 changes: 3 additions & 2 deletions base/count-same-value/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@stdlib/array/base/count-same-value",
"version": "0.0.0",
"description": "Count the number of elements that are equal to a given value in an array.",
"description": "Count the number of elements in an array that are equal to a specified value.",
"license": "Apache-2.0",
"author": {
"name": "The Stdlib Authors",
Expand Down Expand Up @@ -60,6 +60,7 @@
"summation",
"countif",
"total",
"same"
"same",
"equal"
]
}
23 changes: 19 additions & 4 deletions base/count-same-value/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ tape( 'the function distinguishes between positive and negative zeros (generic)'
var x;

x = [ 0.0, -0.0, 0.0, -0.0, 0.0, NaN, 1.0 ];

expected = 3;
actual = countSameValue( x, 0.0 );
t.strictEqual( actual, expected, 'returns expected value' );

expected = 2;
actual = countSameValue( x, -0.0 );
t.strictEqual( actual, expected, 'returns expected value' );

t.end();
});

Expand All @@ -68,7 +73,7 @@ tape( 'the function considers all NaN values to be identical (generic)', functio
var actual;
var x;

x = [ NaN, 0, NaN, 2, NaN, 9, NaN ];
x = [ NaN, 0.0, NaN, 2.0, NaN, 9.0, NaN ];
expected = 4;
actual = countSameValue( x, NaN );

Expand All @@ -95,10 +100,15 @@ tape( 'the function distinguishes between positive and negative zeros (accessors
var x;

x = toAccessorArray( [ 0.0, -0.0, 0.0, -0.0, 0.0, NaN, 1.0 ] );

expected = 3;
actual = countSameValue( x, 0.0 );
t.strictEqual( actual, expected, 'returns expected value' );

expected = 2;
actual = countSameValue( x, -0.0 );
t.strictEqual( actual, expected, 'returns expected value' );

t.end();
});

Expand All @@ -107,7 +117,7 @@ tape( 'the function considers all NaN values to be identical (accessors)', funct
var actual;
var x;

x = toAccessorArray( [ NaN, 0, NaN, 2, NaN, 9, NaN ] );
x = toAccessorArray( [ NaN, 0.0, NaN, 2.0, NaN, 9.0, NaN ] );
expected = 4;
actual = countSameValue( x, NaN );

Expand All @@ -134,10 +144,15 @@ tape( 'the function distinguishes between positive and negative zeros (real type
var x;

x = new Float32Array( [ 0.0, -0.0, 0.0, -0.0, 0.0, NaN, 1.0 ] );

expected = 3;
actual = countSameValue( x, 0.0 );
t.strictEqual( actual, expected, 'returns expected value' );

expected = 2;
actual = countSameValue( x, -0.0 );
t.strictEqual( actual, expected, 'returns expected value' );

t.end();
});

Expand All @@ -146,7 +161,7 @@ tape( 'the function considers all NaN values to be identical (real typed array)'
var actual;
var x;

x = new Float32Array( [ NaN, 0, NaN, 2, NaN, 9, NaN ] );
x = new Float32Array( [ NaN, 0.0, NaN, 2.0, NaN, 9.0, NaN ] );
expected = 4;
actual = countSameValue( x, NaN );

Expand All @@ -172,7 +187,7 @@ tape( 'the function distinguishes between positive and negative zeros (complex t
var actual;
var x;

x = new Complex128Array( [ 0.0, -0.0, 0.0, -0.0, 0.0, 0.0, -0.0, -0.0, -0.0, 0.0 ] );
x = new Complex128Array( [ 0.0, -0.0, 0.0, -0.0, 0.0, 0.0, -0.0, -0.0, -0.0, 0.0 ] ); // eslint-disable-line max-len
expected = 2;
actual = countSameValue( x, new Complex128( 0.0, -0.0 ) );

Expand Down
9 changes: 9 additions & 0 deletions base/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,15 @@ setReadOnly( ns, 'copyIndexed', require( './../../base/copy-indexed' ) );
*/
setReadOnly( ns, 'countFalsy', require( './../../base/count-falsy' ) );

/**
* @name countSameValue
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/base/count-same-value}
*/
setReadOnly( ns, 'countSameValue', require( './../../base/count-same-value' ) );

/**
* @name countTruthy
* @memberof ns
Expand Down
Loading

0 comments on commit 5d6b6f8

Please sign in to comment.