Skip to content

Commit f975b3f

Browse files
committed
refactor: add ndarray implementation
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent d0512ae commit f975b3f

File tree

5 files changed

+114
-44
lines changed

5 files changed

+114
-44
lines changed

lib/node_modules/@stdlib/blas/base/zaxpy/src/addon.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,32 @@ static napi_value addon( napi_env env, napi_callback_info info ) {
3737
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
3838
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 );
3939
STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 );
40-
STDLIB_NAPI_ARGV_COMPLEX128( env, za, argv, 1 );
41-
STDLIB_NAPI_ARGV_STRIDED_COMPLEX128ARRAY( env, ZX, N, strideX, argv, 2 );
42-
STDLIB_NAPI_ARGV_STRIDED_COMPLEX128ARRAY( env, ZY, N, strideY, argv, 4 );
43-
API_SUFFIX(c_zaxpy)( N, za, (void *)ZX, strideX, (void *)ZY, strideY );
40+
STDLIB_NAPI_ARGV_COMPLEX128( env, alpha, argv, 1 );
41+
STDLIB_NAPI_ARGV_STRIDED_COMPLEX128ARRAY( env, X, N, strideX, argv, 2 );
42+
STDLIB_NAPI_ARGV_STRIDED_COMPLEX128ARRAY( env, Y, N, strideY, argv, 4 );
43+
API_SUFFIX(c_zaxpy)( N, alpha, (void *)X, strideX, (void *)Y, strideY );
4444
return NULL;
4545
}
4646

47-
STDLIB_NAPI_MODULE_EXPORT_FCN( addon )
47+
/**
48+
* Receives JavaScript callback invocation data.
49+
*
50+
* @param env environment under which the function is invoked
51+
* @param info callback data
52+
* @return Node-API value
53+
*/
54+
static napi_value addon_method( napi_env env, napi_callback_info info ) {
55+
STDLIB_NAPI_ARGV( env, info, argv, argc, 8 );
56+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
57+
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 );
58+
STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 );
59+
STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 6 );
60+
STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 7 );
61+
STDLIB_NAPI_ARGV_COMPLEX128( env, alpha, argv, 1 );
62+
STDLIB_NAPI_ARGV_STRIDED_COMPLEX128ARRAY( env, X, N, strideX, argv, 2 );
63+
STDLIB_NAPI_ARGV_STRIDED_COMPLEX128ARRAY( env, Y, N, strideY, argv, 5 );
64+
API_SUFFIX(c_zaxpy_ndarray)( N, alpha, (void *)X, strideX, offsetX, (void *)Y, strideY, offsetY );
65+
return NULL;
66+
}
67+
68+
STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method )

lib/node_modules/@stdlib/blas/base/zaxpy/src/zaxpy.c

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,20 @@
1919
#include "stdlib/blas/base/zaxpy.h"
2020
#include "stdlib/blas/base/shared.h"
2121
#include "stdlib/complex/float64/ctor.h"
22-
#include "stdlib/complex/float64/base/mul.h"
23-
#include "stdlib/complex/float64/base/add.h"
22+
#include "stdlib/strided/base/stride2offset.h"
2423

2524
/**
2625
* Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant and adds the result to a double-precision complex floating-point vector.
2726
*
2827
* @param N number of indexed elements
29-
* @param za scalar constant
30-
* @param ZX first input array
31-
* @param strideX ZX stride length
32-
* @param ZY second input array
33-
* @param strideY ZY stride length
28+
* @param alpha scalar constant
29+
* @param X input array
30+
* @param strideX X stride length
31+
* @param Y output array
32+
* @param strideY Y stride length
3433
*/
35-
void API_SUFFIX(c_zaxpy)( const CBLAS_INT N, const stdlib_complex128_t za, void *ZX, const CBLAS_INT strideX, void *ZY, const CBLAS_INT strideY ) {
36-
stdlib_complex128_t zx;
37-
stdlib_complex128_t zy;
38-
CBLAS_INT i;
39-
40-
uint8_t *ip1 = (uint8_t *)ZX;
41-
uint8_t *ip2 = (uint8_t *)ZY;
42-
int64_t is1 = 16 * (int64_t)strideX;
43-
int64_t is2 = 16 * (int64_t)strideY;
44-
if ( N <= 0 || strideX <= 0 || strideY <= 0 ) {
45-
return;
46-
}
47-
for ( i = 0; i < N; i++, ip1 += is1, ip2 += is2 ) {
48-
zx = *(stdlib_complex128_t *)ip1;
49-
zy = *(stdlib_complex128_t *)ip2;
50-
*(stdlib_complex128_t *)ip2 = stdlib_base_complex128_add( stdlib_base_complex128_mul( za, zx ), zy );
51-
}
52-
return;
34+
void API_SUFFIX(c_zaxpy)( const CBLAS_INT N, const stdlib_complex128_t alpha, const void *X, const CBLAS_INT strideX, void *Y, const CBLAS_INT strideY ) {
35+
CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
36+
CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY );
37+
API_SUFFIX(c_zaxpy_ndarray)( N, alpha, X, strideX, ox, Y, strideY, oy );
5338
}

lib/node_modules/@stdlib/blas/base/zaxpy/src/zaxpy_cblas.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
* Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant and adds the result to a double-precision complex floating-point vector.
2626
*
2727
* @param N number of indexed elements
28-
* @param za scalar constant
29-
* @param ZX first input array
30-
* @param strideX ZX stride length
31-
* @param ZY second input array
32-
* @param strideY ZY stride length
28+
* @param alpha scalar constant
29+
* @param X first input array
30+
* @param strideX X stride length
31+
* @param Y second input array
32+
* @param strideY Y stride length
3333
*/
34-
void API_SUFFIX(c_zaxpy)( const CBLAS_INT N, const stdlib_complex128_t za, void *ZX, const CBLAS_INT strideX, void *ZY, const CBLAS_INT strideY ) {
35-
API_SUFFIX(cblas_zaxpy)( N, za, ZX, strideX, ZY, strideY );
34+
void API_SUFFIX(c_zaxpy)( const CBLAS_INT N, const stdlib_complex128_t alpha, void *X, const CBLAS_INT strideX, void *Y, const CBLAS_INT strideY ) {
35+
API_SUFFIX(cblas_zaxpy)( N, alpha, X, strideX, Y, strideY );
3636
}

lib/node_modules/@stdlib/blas/base/zaxpy/src/zaxpy_f.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
* Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant and adds the result to a double-precision complex floating-point vector.
2626
*
2727
* @param N number of indexed elements
28-
* @param za scalar constant
29-
* @param ZX first input array
30-
* @param strideX ZX stride length
31-
* @param ZY second input array
32-
* @param strideY ZY stride length
28+
* @param alpha scalar constant
29+
* @param X first input array
30+
* @param strideX X stride length
31+
* @param Y second input array
32+
* @param strideY Y stride length
3333
*/
34-
void API_SUFFIX(c_zaxpy)( const CBLAS_INT N, const stdlib_complex128_t za, void *ZX, const CBLAS_INT strideX, void *ZY, const CBLAS_INT strideY ) {
35-
zaxpy( &N, &za, ZX, &strideX, ZY, &strideY );
34+
void API_SUFFIX(c_zaxpy)( const CBLAS_INT N, const stdlib_complex128_t alpha, void *X, const CBLAS_INT strideX, void *Y, const CBLAS_INT strideY ) {
35+
zaxpy( &N, &alpha, X, &strideX, Y, &strideY );
3636
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
#include "stdlib/blas/base/zaxpy.h"
20+
#include "stdlib/blas/base/scabs1.h"
21+
#include "stdlib/blas/base/shared.h"
22+
#include "stdlib/complex/float64/ctor.h"
23+
#include "stdlib/complex/float64/base/add.h"
24+
#include "stdlib/complex/float64/base/mul.h"
25+
#include <stdint.h>
26+
27+
/**
28+
* Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant and adds the result to a double-precision complex floating-point vector using alternative indexing semantics.
29+
*
30+
* @param N number of indexed elements
31+
* @param alpha scalar constant
32+
* @param X input array
33+
* @param strideX X stride length
34+
* @param offsetX starting index for X
35+
* @param Y output array
36+
* @param strideY Y stride length
37+
* @param offsetY starting index for Y
38+
*/
39+
void API_SUFFIX(c_zaxpy_ndarray)( const CBLAS_INT N, const stdlib_complex128_t alpha, const void *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, void *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) {
40+
stdlib_complex128_t x;
41+
stdlib_complex128_t y;
42+
int64_t is1;
43+
int64_t is2;
44+
int64_t i;
45+
46+
if ( N <= 0 ) {
47+
return;
48+
}
49+
if ( c_scabs1( alpha ) == 0.0 ) {
50+
return;
51+
}
52+
stdlib_complex128_t *ip1 = (stdlib_complex128_t *)X;
53+
stdlib_complex128_t *ip2 = (stdlib_complex128_t *)Y;
54+
is1 = (int64_t)strideX;
55+
is2 = (int64_t)strideY;
56+
ip1 += offsetX;
57+
ip2 += offsetY;
58+
for ( i = 0; i < N; i++, ip1 += is1, ip2 += is2 ) {
59+
x = *ip1;
60+
y = *ip2;
61+
*ip2 = stdlib_base_complex128_add( stdlib_base_complex128_mul( alpha, x ), y );
62+
}
63+
return;
64+
}

0 commit comments

Comments
 (0)