Skip to content

Commit d17456a

Browse files
authored
Merge branch 'stdlib-js:develop' into ccopy-wasm
2 parents db283ea + 7f76495 commit d17456a

File tree

17 files changed

+477
-122
lines changed

17 files changed

+477
-122
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/blas/base/scnrm2/README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ Computes the L2-norm of a complex single-precision floating-point vector.
181181
const float cx[] = { 0.3f, 0.1f, 0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.2f };
182182

183183
float norm = c_scnrm2( 4, (void *)cx, 1 );
184-
// returns 0.8
184+
// returns 0.8f
185185
```
186186
187187
The function accepts the following arguments:
@@ -194,6 +194,27 @@ The function accepts the following arguments:
194194
float c_scnrm2( const CBLAS_INT N, const void *CX, const CBLAS_INT strideX );
195195
```
196196

197+
#### c_scnrm2_ndarray( N, \*CX, strideX, offsetX )
198+
199+
Computes the L2-norm of a complex single-precision floating-point vector using alternative indexing semantics.
200+
201+
```c
202+
const float cx[] = { 0.3f, 0.1f, 0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.2f };
203+
204+
float norm = c_scnrm2_ndarray( 4, (void *)cx, 1, 0 );
205+
// returns 0.8f
206+
```
207+
208+
The function accepts the following arguments:
209+
210+
- **N**: `[in] CBLAS_INT` number of indexed elements.
211+
- **CX**: `[in] void*` input array.
212+
- **strideX**: `[in] CBLAS_INT` index increment for `CX`.
213+
214+
```c
215+
float c_scnrm2_ndarray( const CBLAS_INT N, const void *CX, const CBLAS_INT strideX, const CBLAS_INT offsetX );
216+
```
217+
197218
</section>
198219

199220
<!-- /.usage -->
@@ -227,7 +248,13 @@ int main( void ) {
227248
const int strideX = 1;
228249

229250
// Compute the L2-norm:
230-
c_scnrm2( N, (void *)cx, strideX );
251+
float norm = c_scnrm2( N, (void *)cx, strideX );
252+
253+
// Print the result:
254+
printf( "L2-norm: %f\n", norm );
255+
256+
// Compute the L2-norm using alternative indexing semantics:
257+
norm = c_scnrm2_ndarray( N, (void *)cx, -strideX, N-1 );
231258

232259
// Print the result:
233260
printf( "L2-norm: %f\n", norm );

lib/node_modules/@stdlib/blas/base/scnrm2/benchmark/c/benchmark.length.c

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static float rand_float( void ) {
9494
* @param len array length
9595
* @return elapsed time in seconds
9696
*/
97-
static double benchmark( int iterations, int len ) {
97+
static double benchmark1( int iterations, int len ) {
9898
float cx[ len*2 ];
9999
double elapsed;
100100
float norm;
@@ -121,6 +121,40 @@ static double benchmark( int iterations, int len ) {
121121
return elapsed;
122122
}
123123

124+
/**
125+
* Runs a benchmark.
126+
*
127+
* @param iterations number of iterations
128+
* @param len array length
129+
* @return elapsed time in seconds
130+
*/
131+
static double benchmark2( int iterations, int len ) {
132+
float cx[ len*2 ];
133+
double elapsed;
134+
float norm;
135+
double t;
136+
int i;
137+
138+
for ( i = 0; i < len*2; i += 2 ) {
139+
cx[ i ] = ( rand_float()*10000.0f ) - 5000.0f;
140+
cx[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f;
141+
}
142+
norm = 0.0f;
143+
t = tic();
144+
for ( i = 0; i < iterations; i++ ) {
145+
norm = c_scnrm2_ndarray( len, (void *)cx, 1, 0 );
146+
if ( norm != norm ) {
147+
printf( "should not return NaN\n" );
148+
break;
149+
}
150+
}
151+
elapsed = tic() - t;
152+
if ( norm != norm ) {
153+
printf( "should not return NaN\n" );
154+
}
155+
return elapsed;
156+
}
157+
124158
/**
125159
* Main execution sequence.
126160
*/
@@ -143,7 +177,14 @@ int main( void ) {
143177
for ( j = 0; j < REPEATS; j++ ) {
144178
count += 1;
145179
printf( "# c::%s:len=%d\n", NAME, len );
146-
elapsed = benchmark( iter, len );
180+
elapsed = benchmark1( iter, len );
181+
print_results( iter, elapsed );
182+
printf( "ok %d benchmark finished\n", count );
183+
}
184+
for ( j = 0; j < REPEATS; j++ ) {
185+
count += 1;
186+
printf( "# c::%s:ndarray:len=%d\n", NAME, len );
187+
elapsed = benchmark2( iter, len );
147188
print_results( iter, elapsed );
148189
printf( "ok %d benchmark finished\n", count );
149190
}

lib/node_modules/@stdlib/blas/base/scnrm2/examples/c/example.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,10 @@ int main( void ) {
3434

3535
// Print the result:
3636
printf( "L2-norm: %f\n", norm );
37+
38+
// Compute the L2-norm using alternative indexing semantics:
39+
norm = c_scnrm2_ndarray( N, (void *)cx, -strideX, N-1 );
40+
41+
// Print the result:
42+
printf( "L2-norm: %f\n", norm );
3743
}

lib/node_modules/@stdlib/blas/base/scnrm2/include/stdlib/blas/base/scnrm2.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ extern "C" {
3636
*/
3737
float API_SUFFIX(c_scnrm2)( const CBLAS_INT N, const void *CX, const CBLAS_INT strideX );
3838

39+
/**
40+
* Computes the L2-norm of a complex single-precision floating-point vector using alternative indexing semantics.
41+
*/
42+
float API_SUFFIX(c_scnrm2_ndarray)( const CBLAS_INT N, const void *CX, const CBLAS_INT strideX, const CBLAS_INT offsetX );
43+
3944
#ifdef __cplusplus
4045
}
4146
#endif

lib/node_modules/@stdlib/blas/base/scnrm2/lib/ndarray.native.js

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

2323
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' );
24-
var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' );
2524
var addon = require( './../src/addon.node' );
2625

2726

@@ -46,10 +45,8 @@ var addon = require( './../src/addon.node' );
4645
* // returns ~0.8
4746
*/
4847
function scnrm2( N, cx, strideX, offsetX ) {
49-
var viewCX;
50-
offsetX = minViewBufferIndex( N, strideX, offsetX );
51-
viewCX = reinterpret( cx, offsetX );
52-
return addon( N, viewCX, strideX );
48+
var viewCX = reinterpret( cx, 0 );
49+
return addon.ndarray( N, viewCX, strideX, offsetX );
5350
}
5451

5552

0 commit comments

Comments
 (0)