Skip to content

Commit b508f8c

Browse files
committed
added addon.c
1 parent 24e4afe commit b508f8c

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
#include "stdlib/blas/ext/base/dapxsumors.h"
21+
#include "stdlib/napi/export.h"
22+
#include "stdlib/napi/argv.h"
23+
#include "stdlib/napi/argv_int64.h"
24+
#include "stdlib/napi/argv_strided_float64array.h"
25+
#include <node_api.h>
26+
#include <assert.h>
27+
28+
/**
29+
* Receives JavaScript callback invocation data.
30+
*
31+
* @private
32+
* @param env environment under which the function is invoked
33+
* @param info callback data
34+
* @return Node-API value
35+
*/
36+
static napi_value addon( napi_env env, napi_callback_info info ) {
37+
STDLIB_NAPI_ARGV( env, info, argv, argc, 4 );
38+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
39+
STDLIB_NAPI_ARGV_DOUBLE( env, alpha, argv, 1 );
40+
STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 );
41+
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 2 );
42+
43+
napi_value v;
44+
napi_status status = napi_create_double( env, stdlib_strided_dapxsumors( N, alpha, (double *)X, stride ), &v );
45+
assert( status == napi_ok );
46+
47+
return v;
48+
}
49+
50+
STDLIB_NAPI_MODULE_EXPORT_FCN( addon )

lib/node_modules/@stdlib/blas/ext/base/dapxsumors/test/test.dapxsumors.native.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) {
227227
2.0
228228
]);
229229

230-
N = floor( x.length / 2 );
231-
v = dapxsumors( N, 5.0, x, 2 );
230+
v = dapxsumors( 4, 5.0, x, 2 );
232231

233232
t.strictEqual( v, 25.0, 'returns expected value' );
234233
t.end();
@@ -250,8 +249,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test
250249
2.0
251250
]);
252251

253-
N = floor( x.length / 2 );
254-
v = dapxsumors( N, 5.0, x, -2 );
252+
v = dapxsumors( 4, 5.0, x, -2 );
255253

256254
t.strictEqual( v, 25.0, 'returns expected value' );
257255
t.end();
@@ -288,9 +286,8 @@ tape( 'the function supports view offsets', opts, function test( t ) {
288286
]);
289287

290288
x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
291-
N = floor(x1.length / 2);
292289

293-
v = dapxsumors( N, 5.0, x1, 2 );
290+
v = dapxsumors( 4, 5.0, x1, 2 );
294291
t.strictEqual( v, 25.0, 'returns expected value' );
295292

296293
t.end();

0 commit comments

Comments
 (0)