Skip to content

Commit e448eeb

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents 7d9b31b + ab2b25b commit e448eeb

File tree

270 files changed

+10626
-1477
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

270 files changed

+10626
-1477
lines changed

.github/workflows/autoclose.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,35 @@ jobs:
179179
GH_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
180180
GH_REPO: ${{ github.repository }}
181181
NUMBER: ${{ github.event.pull_request.number }}
182+
183+
# Define a job which closes a pull request if a pull request is considered stale:
184+
stale:
185+
186+
# Define job name:
187+
name: 'Check for stale label'
188+
189+
# Only run this job if the pull request has a specific label:
190+
if: "${{ github.event.label.name == 'autoclose: Stale' }}"
191+
192+
# Define job permissions:
193+
permissions:
194+
contents: read
195+
issues: write
196+
pull-requests: write
197+
198+
# Define the type of virtual host machine:
199+
runs-on: ubuntu-latest
200+
201+
# Define the sequence of job steps:
202+
steps:
203+
# Close the pull request:
204+
- name: 'Close pull request'
205+
run: gh pr close "$NUMBER" --comment "$BODY"
206+
env:
207+
GH_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
208+
GH_REPO: ${{ github.repository }}
209+
NUMBER: ${{ github.event.pull_request.number }}
210+
BODY: |
211+
This pull request has been automatically closed because it has been inactive for an extended period after changes were requested. If you still wish to pursue this contribution, feel free to reopen the pull request or submit a new one.
212+
213+
We appreciate your interest in contributing to stdlib!

.github/workflows/generate_pr_commit_message.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@ name: generate_pr_commit_message
2121

2222
# Workflow triggers:
2323
on:
24-
pull_request:
24+
pull_request_target:
2525
types:
2626
- labeled
2727

2828
# Global permissions:
2929
permissions:
30+
# Allow read-only access to the repository contents:
3031
contents: read
32+
33+
# Allow write access to issues, assignees, labels, and milestones:
3134
issues: write
35+
36+
# Allow write access to pull requests:
3237
pull-requests: write
3338

3439
# Workflow jobs:

.github/workflows/scripts/generate_pr_commit_message

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ main() {
112112
pr_commits=$(github_api "GET" "/repos/$REPO_OWNER/$REPO_NAME/pulls/$pr_number/commits")
113113

114114
# Extract co-authors from commits:
115-
co_authors=$(echo "$pr_commits" | jq -r '.[].commit.message' | grep -i "Co-authored-by:" | awk -F': ' '{print $2}' | sort | uniq | paste -sd '\n' -)
115+
co_authors=$(echo "$pr_commits" | jq -r '.[].commit.message' | grep -Eio "Co-authored-by:.*" | sort -u)
116116

117117
# Extract 'Signed-off-by' lines from commits:
118118
signed_off_bys=$(echo "$pr_commits" | jq -r '.[].commit.message' | grep -Eio 'Signed-off-by:.*' | sort -u)
@@ -147,6 +147,7 @@ main() {
147147
if [ -n "$ref_issues" ]; then
148148
commit_body+="\n$ref_issues"
149149
fi
150+
commit_body+="\n"
150151
if [ -n "$co_authors" ]; then
151152
commit_body+="\n$co_authors"
152153
fi

CONTRIBUTORS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Christopher Dambamuromo <[email protected]>
2121
2222
Daniel Killenberger <[email protected]>
2323
Daniel Yu <[email protected]>
24+
DebashisMaharana <[email protected]>
2425
Dominik Moritz <[email protected]>
2526
Dorrin Sotoudeh <[email protected]>
2627
EuniceSim142 <[email protected]>
@@ -99,6 +100,7 @@ Xiaochuan Ye <[email protected]>
99100
Yernar Yergaziyev <[email protected]>
100101
101102
nishant-s7 <[email protected]>
103+
olenkabilonizhka <[email protected]>
102104
orimiles5 <[email protected]>
103105
104106
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 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+
# cuanyByRight
22+
23+
> Cumulatively test whether at least one element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var cuanyByRight = require( '@stdlib/array/base/cuany-by-right' );
31+
```
32+
33+
#### cuanyByRight( x, predicate\[, thisArg] )
34+
35+
Cumulatively tests whether at least one element in a provided array passes a test implemented by a `predicate` function, while iterating from right-to-left.
36+
37+
```javascript
38+
function isPositive( value ) {
39+
return ( value > 0 );
40+
}
41+
42+
var x = [ 0, 0, 0, 1, 0 ];
43+
44+
var y = cuanyByRight( x, isPositive );
45+
// returns [ false, true, true, true, true ]
46+
```
47+
48+
The `predicate` function is provided three arguments:
49+
50+
- **value**: current array element.
51+
- **index**: current array element index.
52+
- **arr**: input array.
53+
54+
To set the `predicate` function execution context, provide a `thisArg`.
55+
56+
```javascript
57+
function isPositive( value ) {
58+
this.count += 1;
59+
return ( value > 0 );
60+
}
61+
62+
var x = [ 0, 1, 0, 0, 0 ];
63+
64+
var context = {
65+
'count': 0
66+
};
67+
68+
var out = cuanyByRight( x, isPositive, context );
69+
// returns [ false, false, false, true, true ]
70+
71+
var cnt = context.count;
72+
// returns 4
73+
```
74+
75+
#### cuanyByRight.assign( x, out, stride, offset, predicate\[, thisArg] )
76+
77+
Cumulatively tests whether at least one element in a provided array passes a test implemented by a `predicate` function, while iterating from right-to-left, and assigns results to a provided output array.
78+
79+
```javascript
80+
function isPositive( value ) {
81+
return ( value > 0 );
82+
}
83+
84+
var x = [ 0, 1, 0, 0, 0 ];
85+
var y = [ false, null, false, null, false, null, false, null, false, null ];
86+
87+
var out = cuanyByRight.assign( x, y, 2, 0, isPositive );
88+
// returns [ false, null, false, null, false, null, true, null, true, null ]
89+
90+
var bool = ( out === y );
91+
// returns true
92+
```
93+
94+
The function supports the following parameters:
95+
96+
- **x**: input array.
97+
- **out**: output array.
98+
- **stride**: output array stride.
99+
- **offset**: output array offset.
100+
- **predicate**: test function.
101+
102+
</section>
103+
104+
<!-- /.usage -->
105+
106+
<section class="notes">
107+
108+
</section>
109+
110+
<!-- /.notes -->
111+
112+
<section class="examples">
113+
114+
## Examples
115+
116+
<!-- eslint no-undef: "error" -->
117+
118+
```javascript
119+
function isPositive( value ) {
120+
return ( value > 0 );
121+
}
122+
123+
var bernoulli = require( '@stdlib/random/array/bernoulli' );
124+
var cuanyByRight = require( '@stdlib/array/base/cuany-by-right' );
125+
126+
// Create an array of random values:
127+
var x = bernoulli( 10, 0.1 );
128+
console.log( x );
129+
130+
var out = cuanyByRight( x, isPositive );
131+
console.log( out );
132+
```
133+
134+
</section>
135+
136+
<!-- /.examples -->
137+
138+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
139+
140+
<section class="related">
141+
142+
</section>
143+
144+
<!-- /.related -->
145+
146+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
147+
148+
<section class="links">
149+
150+
</section>
151+
152+
<!-- /.links -->
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 isArray = require( '@stdlib/assert/is-array' );
26+
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive;
27+
var filled = require( '@stdlib/array/base/filled' );
28+
var pkg = require( './../package.json' ).name;
29+
var cuanyByRight = require( './../lib' );
30+
31+
32+
// FUNCTIONS //
33+
34+
/**
35+
* Creates a benchmark function.
36+
*
37+
* @private
38+
* @param {PositiveInteger} len - array length
39+
* @returns {Function} benchmark function
40+
*/
41+
function createBenchmark( len ) {
42+
var x = filled( 1.5, len );
43+
return benchmark;
44+
45+
/**
46+
* Benchmark function.
47+
*
48+
* @private
49+
* @param {Benchmark} b - benchmark instance
50+
*/
51+
function benchmark( b ) {
52+
var y;
53+
var v;
54+
var i;
55+
56+
y = filled( false, len );
57+
58+
b.tic();
59+
for ( i = 0; i < b.iterations; i++ ) {
60+
v = cuanyByRight.assign( x, y, 1, 0, isPositiveInteger );
61+
if ( typeof v !== 'object' ) {
62+
b.fail( 'should return an array' );
63+
}
64+
}
65+
b.toc();
66+
if ( !isArray( v ) ) {
67+
b.fail( 'should return an array' );
68+
}
69+
b.pass( 'benchmark finished' );
70+
b.end();
71+
}
72+
}
73+
74+
75+
// MAIN //
76+
77+
/**
78+
* Main execution sequence.
79+
*
80+
* @private
81+
*/
82+
function main() {
83+
var len;
84+
var min;
85+
var max;
86+
var f;
87+
var i;
88+
89+
min = 1; // 10^min
90+
max = 6; // 10^max
91+
92+
for ( i = min; i <= max; i++ ) {
93+
len = pow( 10, i );
94+
f = createBenchmark( len );
95+
bench( pkg+':assign:len='+len, f );
96+
}
97+
}
98+
99+
main();
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 isArray = require( '@stdlib/assert/is-array' );
25+
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive;
26+
var pkg = require( './../package.json' ).name;
27+
var cuanyByRight = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var x;
34+
var i;
35+
var v;
36+
37+
x = [ 1, 1, 0, 0, 0 ];
38+
39+
b.tic();
40+
for ( i = 0; i < b.iterations; i++ ) {
41+
v = cuanyByRight( x, isPositiveInteger );
42+
if ( typeof v !== 'object' ) {
43+
b.fail( 'should return an array' );
44+
}
45+
}
46+
b.toc();
47+
if ( !isArray( v ) ) {
48+
b.fail( 'should return an array' );
49+
}
50+
b.pass( 'benchmark finished' );
51+
b.end();
52+
});

0 commit comments

Comments
 (0)