Skip to content

Commit 83f1483

Browse files
committed
Auto-generated commit
1 parent 60ca1ff commit 83f1483

File tree

12 files changed

+1342
-1
lines changed

12 files changed

+1342
-1
lines changed

CHANGELOG.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<section class="release" id="unreleased">
66

7-
## Unreleased (2025-04-09)
7+
## Unreleased (2025-04-10)
88

99
<section class="packages">
1010

@@ -458,6 +458,28 @@ This release closes the following issue:
458458

459459
<!-- /.package -->
460460

461+
<section class="package" id="array-base-count-ifs-unreleased">
462+
463+
#### [@stdlib/array/base/count-ifs](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/count-ifs)
464+
465+
<details>
466+
467+
<section class="features">
468+
469+
##### Features
470+
471+
- [`ae78e67`](https://github.com/stdlib-js/stdlib/commit/ae78e67351f0fdd6c42988d32d48bab0ae6ec65c) - add `array/base/count-ifs` [(#5952)](https://github.com/stdlib-js/stdlib/pull/5952)
472+
473+
</section>
474+
475+
<!-- /.features -->
476+
477+
</details>
478+
479+
</section>
480+
481+
<!-- /.package -->
482+
461483
<section class="package" id="array-base-fill-unreleased">
462484

463485
#### [@stdlib/array/base/fill](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/fill)
@@ -1671,6 +1693,7 @@ A total of 14 people contributed to this release. Thank you to the following con
16711693

16721694
<details>
16731695

1696+
- [`ae78e67`](https://github.com/stdlib-js/stdlib/commit/ae78e67351f0fdd6c42988d32d48bab0ae6ec65c) - **feat:** add `array/base/count-ifs` [(#5952)](https://github.com/stdlib-js/stdlib/pull/5952) _(by Muhammad Haris, Athan Reines)_
16741697
- [`b0da3de`](https://github.com/stdlib-js/stdlib/commit/b0da3de9a0fa3d1e657ee5a05dcca053fe74e515) - **feat:** `add array/base/linspace2d` [(#5464)](https://github.com/stdlib-js/stdlib/pull/5464) _(by Muhammad Haris, Athan Reines, stdlib-bot)_
16751698
- [`40de89d`](https://github.com/stdlib-js/stdlib/commit/40de89d0b84ab345f198d6a90696c0762efde887) - **feat:** add `array/base/reshape` [(#5639)](https://github.com/stdlib-js/stdlib/pull/5639) _(by Muhammad Haris, Athan Reines)_
16761699
- [`54534dd`](https://github.com/stdlib-js/stdlib/commit/54534ddb74b35d0b99915f8017ed9d9e692a7502) - **chore:** address commit comments [(#5978)](https://github.com/stdlib-js/stdlib/pull/5978) _(by Jay Soni, Athan Reines, stdlib-bot)_

CONTRIBUTORS

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Krishnendu Das <[email protected]>
8787
Kshitij-Dale <[email protected]>
8888
Lovelin Dhoni J B <[email protected]>
8989
90+
Mahfuza Humayra Mohona <[email protected]>
9091
Manik Sharma <[email protected]>
9192
Manvith M <[email protected]>
9293
Marcus Fantham <[email protected]>
@@ -119,6 +120,7 @@ Prashant Kumar Yadav <[email protected]>
119120
PrathamBhamare <[email protected]>
120121
Pratik Singh <[email protected]>
121122
Pratyush Kumar Chouhan <[email protected]>
123+
Pravesh Kunwar <[email protected]>
122124
Priyansh Prajapati <[email protected]>
123125
Priyanshu Agarwal <[email protected]>
124126
Pulkit Gupta <[email protected]>

base/count-ifs/README.md

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# countIfs
22+
23+
> Perform element-wise evaluation of one or more input arrays according to provided predicate functions and count the number of elements for which all predicates respectively return `true`.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var countIfs = require( '@stdlib/array/base/count-ifs' );
41+
```
42+
43+
#### countIfs( x0, predicate0\[, x1, predicate1\[, x2, predicate2\[, ...args]] )
44+
45+
Performs element-wise evaluation of one or more input arrays according to provided predicate functions and counts the number of elements for which all predicates respectively return `true`.
46+
47+
```javascript
48+
function predicate0( value ) {
49+
return ( value > 0 );
50+
}
51+
52+
function predicate1( value ) {
53+
return ( value < 3 );
54+
}
55+
56+
var x0 = [ 0, 1, 0, 1, 2 ];
57+
var x1 = [ 2, 3, 1, 2, 5 ];
58+
59+
var out = countIfs( x0, predicate0, x1, predicate1 );
60+
// returns 1
61+
```
62+
63+
The function has the following parameters:
64+
65+
- **x0**: first input array.
66+
- **predicate0**: first predicate function.
67+
- **x1**: second input array (_optional_).
68+
- **predicate1**: second predicate function (_optional_).
69+
- **x2**: third input array (_optional_).
70+
- **predicate2**: third predicate function (_optional_).
71+
- **args**: additional input arrays and corresponding predicate functions (_optional_).
72+
73+
Each predicate function is provided three arguments:
74+
75+
- **value**: current array element.
76+
- **index**: current array element index.
77+
- **arr**: the corresponding input array.
78+
79+
</section>
80+
81+
<!-- /.usage -->
82+
83+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
84+
85+
<section class="notes">
86+
87+
## Notes
88+
89+
- The function assumes that all input arrays have the same length.
90+
- The function supports array-like objects supporting the accessor protocol (e.g., [`Complex128Array`][@stdlib/array/complex128], [`Complex64Array`][@stdlib/array/complex64], etc).
91+
92+
</section>
93+
94+
<!-- /.notes -->
95+
96+
<!-- Package usage examples. -->
97+
98+
<section class="examples">
99+
100+
## Examples
101+
102+
<!-- eslint no-undef: "error" -->
103+
104+
<!-- eslint-disable max-len -->
105+
106+
```javascript
107+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
108+
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive;
109+
var isNegativeInteger = require( '@stdlib/assert/is-negative-integer' ).isPrimitive;
110+
var naryFunction = require( '@stdlib/utils/nary-function' );
111+
var countIfs = require( '@stdlib/array/base/count-ifs' );
112+
113+
var x = discreteUniform( 10, -5, 5, {
114+
'dtype': 'int32'
115+
});
116+
console.log( x );
117+
118+
var y = discreteUniform( 10, -5, 5, {
119+
'dtype': 'int32'
120+
});
121+
console.log( y );
122+
123+
var out = countIfs( x, naryFunction( isPositiveInteger, 1 ), y, naryFunction( isNegativeInteger, 1 ) );
124+
console.log( out );
125+
```
126+
127+
</section>
128+
129+
<!-- /.examples -->
130+
131+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
132+
133+
<section class="references">
134+
135+
</section>
136+
137+
<!-- /.references -->
138+
139+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
140+
141+
<section class="related">
142+
143+
</section>
144+
145+
<!-- /.related -->
146+
147+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
148+
149+
<section class="links">
150+
151+
[@stdlib/array/complex128]: https://github.com/stdlib-js/array/tree/main/complex128
152+
153+
[@stdlib/array/complex64]: https://github.com/stdlib-js/array/tree/main/complex64
154+
155+
</section>
156+
157+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var pow = require( '@stdlib/math/base/special/pow' );
25+
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
26+
var uniform = require( '@stdlib/random/array/uniform' );
27+
var pkg = require( './../package.json' ).name;
28+
var countIfs = require( './../lib' );
29+
30+
31+
// FUNCTIONS //
32+
33+
/**
34+
* First predicate function.
35+
*
36+
* @private
37+
* @param {number} v - value
38+
* @returns {boolean} result
39+
*/
40+
function predicate0( v ) {
41+
return v > 0.0;
42+
}
43+
44+
/**
45+
* Second predicate function.
46+
*
47+
* @private
48+
* @param {number} v - value
49+
* @returns {boolean} result
50+
*/
51+
function predicate1( v ) {
52+
return v < 0.0;
53+
}
54+
55+
/**
56+
* Creates a benchmark function.
57+
*
58+
* @private
59+
* @param {PositiveInteger} len - array length
60+
* @returns {Function} benchmark function
61+
*/
62+
function createBenchmark( len ) {
63+
var x0 = uniform( len, -1.0, 1.0, {
64+
'dype': 'generic'
65+
});
66+
var x1 = uniform( len, -1.0, 1.0, {
67+
'dype': 'generic'
68+
});
69+
return benchmark;
70+
71+
/**
72+
* Benchmark function.
73+
*
74+
* @private
75+
* @param {Benchmark} b - benchmark instance
76+
*/
77+
function benchmark( b ) {
78+
var out;
79+
var i;
80+
81+
b.tic();
82+
for ( i = 0; i < b.iterations; i++ ) {
83+
out = countIfs( x0, predicate0, x1, predicate1 );
84+
if ( typeof out !== 'number' ) {
85+
b.fail( 'should return a number' );
86+
}
87+
}
88+
b.toc();
89+
if ( !isNonNegativeInteger( out ) ) {
90+
b.fail( 'should return a nonnegative integer' );
91+
}
92+
b.pass( 'benchmark finished' );
93+
b.end();
94+
}
95+
}
96+
97+
98+
// MAIN //
99+
100+
/**
101+
* Main execution sequence.
102+
*
103+
* @private
104+
*/
105+
function main() {
106+
var len;
107+
var min;
108+
var max;
109+
var f;
110+
var i;
111+
112+
min = 1; // 10^min
113+
max = 6; // 10^max
114+
115+
for ( i = min; i <= max; i++ ) {
116+
len = pow( 10, i );
117+
118+
f = createBenchmark( len );
119+
bench( pkg+':dtype=generic,predicates=2,len='+len, f );
120+
}
121+
}
122+
123+
main();

base/count-ifs/docs/repl.txt

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
{{alias}}( x0, predicate0[, x1, predicate1[, x2, predicate2[, ...args]] )
3+
Performs element-wise evaluation of one or more input arrays according to
4+
provided predicate functions and counts the number of elements for which all
5+
predicates respectively return `true`.
6+
7+
Each predicate function is provided three arguments:
8+
9+
- value: current array element.
10+
- index: current array element index.
11+
- arr: the corresponding input array.
12+
13+
Parameters
14+
----------
15+
x0: ArrayLikeObject
16+
First input array.
17+
18+
predicate0: Function
19+
First predicate function.
20+
21+
x1: ArrayLikeObject (optional)
22+
Second input array.
23+
24+
predicate1: Function (optional)
25+
Second predicate function.
26+
27+
x2: ArrayLikeObject (optional)
28+
Third input array.
29+
30+
predicate2: Function (optional)
31+
Third predicate function.
32+
33+
...args: ArrayLikeObject|Function (optional)
34+
Additional input arrays and corresponding predicate functions.
35+
36+
Returns
37+
-------
38+
out: integer
39+
Result.
40+
41+
Examples
42+
--------
43+
> function f1( v ) { return ( v > 0 ); };
44+
> function f2( v ) { return ( v < 0 ); };
45+
> var out = {{alias}}( [ 0, 1, 1 ], f1, [ 1, -1, -1 ], f2 )
46+
2
47+
48+
See Also
49+
--------
50+

0 commit comments

Comments
 (0)