Skip to content

Commit a3e9d9c

Browse files
committed
Merge branch 'develop' into number/float32/base/signbit
2 parents cc2d883 + 7e05335 commit a3e9d9c

File tree

37 files changed

+221
-84
lines changed

37 files changed

+221
-84
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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+
# Workflow name:
20+
name: 'Lint Copyright Years in Newly Added Files'
21+
22+
# Workflow triggers:
23+
on:
24+
pull_request:
25+
types: [opened, synchronize, reopened]
26+
27+
# Global permissions:
28+
permissions:
29+
# Allow read-only access to the repository contents:
30+
contents: read
31+
32+
# Workflow jobs:
33+
jobs:
34+
# Define a job for linting copyright years in newly added files:
35+
lint:
36+
name: 'Lint Copyright Years'
37+
runs-on: ubuntu-latest
38+
39+
steps:
40+
# Checkout the repository:
41+
- name: 'Checkout repository'
42+
# Pin action to full length commit SHA
43+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
44+
with:
45+
# Specify whether to remove untracked files before checking out the repository:
46+
clean: true
47+
48+
# Limit clone depth to the last 1000 commits:
49+
fetch-depth: 100
50+
51+
# Specify whether to download Git-LFS files:
52+
lfs: false
53+
timeout-minutes: 10
54+
55+
# Get list of newly added files:
56+
- name: 'Get list of newly added files'
57+
id: added-files
58+
run: |
59+
page=1
60+
files=""
61+
while true; do
62+
new_files=$(curl -s \
63+
-H "Accept: application/vnd.github.v3+json" \
64+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
65+
"${{ github.api_url }}/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files?page=$page&per_page=100" \
66+
| jq -r '.[] | select(.status == "added") | .filename')
67+
if [ -z "$new_files" ]; then
68+
break
69+
fi
70+
files="$files $new_files"
71+
page=$((page+1))
72+
done
73+
files=$(echo "$files" | tr '\n' ' ' | sed 's/^ //;s/ $//')
74+
echo "files=${files}" >> $GITHUB_OUTPUT
75+
76+
# Check copyright years in newly added files:
77+
- name: 'Check copyright years'
78+
run: |
79+
current_year=$(date +"%Y")
80+
files="${{ steps.added-files.outputs.files }}"
81+
exit_code=0
82+
83+
echo "## 📄 Copyright Year Check Results" >> $GITHUB_STEP_SUMMARY
84+
echo "_Only newly added files are checked for the current year in the copyright notice._" >> $GITHUB_STEP_SUMMARY
85+
echo "" >> $GITHUB_STEP_SUMMARY
86+
87+
if [[ -z "$files" ]]; then
88+
echo "No newly added files to check." >> $GITHUB_STEP_SUMMARY
89+
exit 0
90+
fi
91+
92+
for file in $files; do
93+
if [[ ! -f "$file" ]]; then
94+
continue
95+
fi
96+
97+
# Check if file contains stdlib copyright notice:
98+
year=$(grep -oP \
99+
'Copyright \(c\) \K[0-9]{4}(?= The Stdlib Authors\.)' \
100+
"$file")
101+
102+
if [[ -n "$year" ]]; then
103+
if [[ "$year" == "$current_year" ]]; then
104+
echo "- ✅ \`$file\`: Year is correct (**$year**)" >> $GITHUB_STEP_SUMMARY
105+
else
106+
echo "- ❌ **Error**: \`$file\` — Expected year **$current_year**, found **$year**" >> $GITHUB_STEP_SUMMARY
107+
exit_code=1
108+
fi
109+
else
110+
echo "- ⚠️ No copyright notice found in \`$file\`" >> $GITHUB_STEP_SUMMARY
111+
fi
112+
done
113+
114+
exit $exit_code

lib/node_modules/@stdlib/math/base/special/bernoulli/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var v = bernoulli( 0 );
4343
// returns 1.0
4444

4545
v = bernoulli( 1 );
46-
// returns 0.0
46+
// returns 0.5
4747

4848
v = bernoulli( 2 );
4949
// returns ~0.167
@@ -158,7 +158,7 @@ double out = stdlib_base_bernoulli( 0 );
158158
// returns 1.0
159159

160160
out = stdlib_base_bernoulli( 1 );
161-
// returns 0.0
161+
// returns 0.5
162162
```
163163

164164
The function accepts the following arguments:

lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/benchmark.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
25-
var floor = require( '@stdlib/math/base/special/floor' );
24+
var randu = require( '@stdlib/random/array/discrete-uniform' );
2625
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2726
var pkg = require( './../package.json' ).name;
2827
var bernoulli = require( './../lib' );
@@ -35,10 +34,11 @@ bench( pkg, function benchmark( b ) {
3534
var y;
3635
var i;
3736

37+
x = randu( 100, 0, 500 );
38+
3839
b.tic();
3940
for ( i = 0; i < b.iterations; i++ ) {
40-
x = floor( randu()*500.0 );
41-
y = bernoulli( x );
41+
y = bernoulli( x[ i % x.length ] );
4242
if ( isnan( y ) ) {
4343
b.fail( 'should not return NaN' );
4444
}

lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/benchmark.native.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
26-
var floor = require( '@stdlib/math/base/special/floor' );
25+
var randu = require( '@stdlib/random/array/discrete-uniform' );
2726
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2827
var tryRequire = require( '@stdlib/utils/try-require' );
2928
var pkg = require( './../package.json' ).name;
@@ -44,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4443
var y;
4544
var i;
4645

46+
x = randu( 100, 0, 500 );
47+
4748
b.tic();
4849
for ( i = 0; i < b.iterations; i++ ) {
49-
x = floor( randu() * 500.0 );
50-
y = bernoulli( x );
50+
y = bernoulli( x[ i % x.length ] );
5151
if ( isnan( y ) ) {
5252
b.fail( 'should not return NaN' );
5353
}

lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/c/native/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,18 @@ static double rand_double( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94-
double x;
94+
double x[ 100 ];
9595
double y;
9696
double t;
9797
int i;
9898

99+
for ( i = 0; i < 100; i++ ) {
100+
x[ i ] = ( 500.0 * rand_double() );
101+
}
102+
99103
t = tic();
100104
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = ( 500.0 * rand_double() );
102-
y = stdlib_base_bernoulli( x );
105+
y = stdlib_base_bernoulli( (int)( x[ i % 100 ] ) );
103106
if ( y != y ) {
104107
printf( "should not return NaN\n" );
105108
break;

lib/node_modules/@stdlib/math/base/special/bernoulli/docs/repl.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
> var y = {{alias}}( 0 )
2222
1.0
2323
> y = {{alias}}( 1 )
24-
0.0
24+
0.5
2525
> y = {{alias}}( 2 )
2626
~0.167
2727
> y = {{alias}}( 3 )

lib/node_modules/@stdlib/math/base/special/bernoulli/docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*
3131
* @example
3232
* var y = bernoulli( 1 );
33-
* // returns 0.0
33+
* // returns 0.5
3434
*
3535
* @example
3636
* var y = bernoulli( 2 );

lib/node_modules/@stdlib/math/base/special/bernoulli/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* // returns 1.0
3131
*
3232
* y = bernoulli( 1 );
33-
* // returns 0.0
33+
* // returns 0.5
3434
*
3535
* y = bernoulli( 2 );
3636
* // returns ~0.166

lib/node_modules/@stdlib/math/base/special/bernoulli/lib/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var MAX_BERNOULLI = 258|0; // asm type annotation
4747
*
4848
* @example
4949
* var y = bernoulli( 1 );
50-
* // returns 0.0
50+
* // returns 0.5
5151
*
5252
* @example
5353
* var y = bernoulli( 2 );
@@ -85,6 +85,9 @@ function bernoulli( n ) {
8585
if ( isnan( n ) || !isNonNegativeInteger( n ) ) {
8686
return NaN;
8787
}
88+
if ( n === 1 ) {
89+
return 0.5;
90+
}
8891
if ( isOdd( n ) ) {
8992
return 0.0;
9093
}

lib/node_modules/@stdlib/math/base/special/bernoulli/lib/native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var addon = require( './../src/addon.node' );
3737
*
3838
* @example
3939
* var y = bernoulli( 1 );
40-
* // returns 0.0
40+
* // returns 0.5
4141
*
4242
* @example
4343
* var y = bernoulli( 2 );

0 commit comments

Comments
 (0)