Skip to content

Commit bd36d63

Browse files
Merge branch 'stdlib-js:develop' into test-dnanasumors
2 parents e66c345 + 7f76495 commit bd36d63

File tree

42 files changed

+1289
-294
lines changed

Some content is hidden

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

42 files changed

+1289
-294
lines changed

lib/node_modules/@stdlib/_tools/scripts/publish_packages.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,10 @@ function publish( pkg, clbk ) {
10611061
}
10621062
fs.copyFileSync( join( __dirname, 'templates', 'workflow_cancel.yml.txt' ), join( dist, '.github', 'workflows', 'cancel.yml' ) );
10631063

1064+
workflow = readFileSync( join( __dirname, 'templates', 'workflow_test_published_package.yml.txt' ), 'utf8' );
1065+
workflow = replace( workflow, '{{cron}}', schedule );
1066+
writeFileSync( join( dist, '.github', 'workflows', 'test_published_package.yml' ), workflow );
1067+
10641068
// Write the current date to the `.keepalive` file...
10651069
if ( flags[ 'keep-alive' ] ) {
10661070
fs.writeFileSync( join( dist, '.github', '.keepalive' ), new Date().toISOString() + '\n' );
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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: test_published_package
21+
22+
# Workflow triggers:
23+
on:
24+
# Run workflow on a weekly schedule:
25+
schedule:
26+
# * is a special character in YAML so you have to quote this string
27+
- cron: '{{cron}}'
28+
29+
# Run workflow upon completion of `publish` workflow run:
30+
workflow_run:
31+
workflows: ["publish"]
32+
types: [completed]
33+
34+
# Allow workflow to be manually run:
35+
workflow_dispatch:
36+
37+
# Workflow jobs:
38+
jobs:
39+
test-published:
40+
# Define a display name:
41+
name: 'Test running examples of published package'
42+
43+
# Define the type of virtual host machine:
44+
runs-on: ubuntu-latest
45+
46+
# Define environment variables:
47+
env:
48+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
49+
50+
# Run workflow job if `publish` workflow run is successful or when the workflow is manually run:
51+
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
52+
53+
# Define the job's steps:
54+
steps:
55+
# Checkout the repository:
56+
- name: 'Checkout repository'
57+
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
58+
59+
# Install Node.js:
60+
- name: 'Install Node.js'
61+
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
62+
with:
63+
node-version: 20
64+
timeout-minutes: 5
65+
66+
# Create test directory and run examples:
67+
- name: 'Create test directory and run examples'
68+
run: |
69+
cd ..
70+
mkdir test-published
71+
cd test-published
72+
73+
# Copy example file:
74+
cp $GITHUB_WORKSPACE/examples/index.js .
75+
76+
# Create a minimal package.json
77+
echo '{
78+
"name": "test-published",
79+
"version": "1.0.0",
80+
"main": "index.js",
81+
"dependencies": {}
82+
}' > package.json
83+
84+
# Get package name and modify example file:
85+
PACKAGE_NAME=$(jq -r '.name' $GITHUB_WORKSPACE/package.json)
86+
ESCAPED_PACKAGE_NAME=$(echo "$PACKAGE_NAME" | sed 's/[\/&]/\\&/g')
87+
88+
sed -i "s/require( '.\/..\/lib' )/require( '$ESCAPED_PACKAGE_NAME' )/g" index.js
89+
90+
# Extract and install dependencies:
91+
DEPS=$(grep -oP "require\(\s*'([^']+)'\s*\)" index.js | sed "s/require(\s*'//" | sed "s/'\s*)//" | grep -v "^\.")
92+
for dep in $DEPS; do
93+
npm install $dep --save
94+
done
95+
96+
# Run the example:
97+
node index.js
98+
99+
# Send Slack notification if job fails:
100+
- name: 'Send notification to Slack in case of failure'
101+
uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2
102+
with:
103+
status: ${{ job.status }}
104+
channel: '#npm-ci'
105+
if: failure()

lib/node_modules/@stdlib/array/bool/README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ Invokes a function once for each array element.
869869

870870
```javascript
871871
function log( v, i ) {
872-
console.log( '%s: %s', i, v.toString() );
872+
console.log( '%s: %s', i.toString(), v.toString() );
873873
}
874874

875875
var arr = new BooleanArray( 3 );
@@ -897,7 +897,7 @@ To set the function execution context, provide a `thisArg`.
897897
```javascript
898898
function fcn( v, i ) {
899899
this.count += 1;
900-
console.log( '%s: %s', i, v.toString() );
900+
console.log( '%s: %s', i.toString(), v.toString() );
901901
}
902902

903903
var arr = new BooleanArray( 3 );
@@ -911,11 +911,6 @@ arr.set( false, 1 );
911911
arr.set( true, 2 );
912912

913913
arr.forEach( fcn, context );
914-
/* =>
915-
0: 1 + 1i
916-
1: 2 + 2i
917-
2: 3 + 3i
918-
*/
919914

920915
var count = context.count;
921916
// returns 3

lib/node_modules/@stdlib/array/fixed-endian-factory/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,65 @@ var v = arr.get( 0 );
306306
// returns 1.0
307307
```
308308

309+
<a name="method-for-each"></a>
310+
311+
#### TypedArrayFE.prototype.forEach( callbackFn\[, thisArg] )
312+
313+
Invokes a function once for each array element.
314+
315+
```javascript
316+
function log( v, i ) {
317+
console.log( '%s: %s', i.toString(), v.toString() );
318+
}
319+
320+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
321+
322+
var arr = new Float64ArrayFE( 'little-endian', 3 );
323+
324+
arr.set( 1.5, 0 );
325+
arr.set( 2.5, 1 );
326+
arr.set( 3.5, 2 );
327+
328+
arr.forEach( log );
329+
/* =>
330+
0: 1.5
331+
1: 2.5
332+
2: 3.5
333+
*/
334+
```
335+
336+
The invoked function is provided three arguments:
337+
338+
- **value**: current array element.
339+
- **index**: current array element index.
340+
- **arr**: the array on which this method was called.
341+
342+
To set the function execution context, provide a `thisArg`.
343+
344+
```javascript
345+
function fcn( v, i ) {
346+
this.count += 1;
347+
console.log( '%s: %s', i.toString(), v.toString() );
348+
}
349+
350+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
351+
352+
var arr = new Float64ArrayFE( 'little-endian', 3 );
353+
354+
var context = {
355+
'count': 0
356+
};
357+
358+
arr.set( 1.0, 0 );
359+
arr.set( 2.0, 1 );
360+
arr.set( 3.0, 2 );
361+
362+
arr.forEach( fcn, context );
363+
364+
var count = context.count;
365+
// returns 3
366+
```
367+
309368
<a name="method-get"></a>
310369

311370
#### TypedArrayFE.prototype.get( i )
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var pkg = require( './../package.json' ).name;
26+
var factory = require( './../lib' );
27+
28+
29+
// VARIABLES //
30+
31+
var Float64ArrayFE = factory( 'float64' );
32+
33+
34+
// MAIN //
35+
36+
bench( pkg+':forEach', function benchmark( b ) {
37+
var arr;
38+
var i;
39+
40+
arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 2.0, 1.0 ] );
41+
42+
b.tic();
43+
for ( i = 0; i < b.iterations; i++ ) {
44+
arr.forEach( check );
45+
if ( arr.length !== 4 ) {
46+
b.fail( 'should not change an array length' );
47+
}
48+
}
49+
b.toc();
50+
if ( arr.length !== 4 ) {
51+
b.fail( 'should not change an array length' );
52+
}
53+
b.pass( 'benchmark finished' );
54+
b.end();
55+
56+
function check( v ) {
57+
if ( isnan( v ) ) {
58+
b.fail( 'should not return NaN' );
59+
}
60+
}
61+
});
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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 zeroTo = require( '@stdlib/array/zero-to' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var pkg = require( './../package.json' ).name;
28+
var factory = require( './../lib' );
29+
30+
31+
// VARIABLES //
32+
33+
var Float64ArrayFE = factory( 'float64' );
34+
35+
36+
// FUNCTIONS //
37+
38+
/**
39+
* Creates a benchmark function.
40+
*
41+
* @private
42+
* @param {PositiveInteger} len - array length
43+
* @returns {Function} benchmark function
44+
*/
45+
function createBenchmark( len ) {
46+
var arr = new Float64ArrayFE( 'little-endian', zeroTo( len ) );
47+
return benchmark;
48+
49+
/**
50+
* Benchmark function.
51+
*
52+
* @private
53+
* @param {Benchmark} b - benchmark instance
54+
*/
55+
function benchmark( b ) {
56+
var i;
57+
58+
b.tic();
59+
for ( i = 0; i < b.iterations; i++ ) {
60+
arr.forEach( callback );
61+
if ( arr.length !== len ) {
62+
b.fail( 'should not change an array length' );
63+
}
64+
}
65+
b.toc();
66+
if ( arr.length !== len ) {
67+
b.fail( 'should not change an array length' );
68+
}
69+
b.pass( 'benchmark finished' );
70+
b.end();
71+
72+
function callback( value ) {
73+
if ( isnan( value ) ) {
74+
throw new Error( 'something went wrong' );
75+
}
76+
}
77+
}
78+
}
79+
80+
81+
// MAIN //
82+
83+
/**
84+
* Main execution sequence.
85+
*
86+
* @private
87+
*/
88+
function main() {
89+
var len;
90+
var min;
91+
var max;
92+
var f;
93+
var i;
94+
95+
min = 1; // 10^min
96+
max = 6; // 10^max
97+
98+
for ( i = min; i <= max; i++ ) {
99+
len = pow( 10, i );
100+
f = createBenchmark( len );
101+
bench( pkg+':forEach:len='+len, f );
102+
}
103+
}
104+
105+
main();

0 commit comments

Comments
 (0)