Skip to content

Commit 2f2a300

Browse files
committed
feat: add c implementation for blas/bae/ssymv
--- 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 e1e1e0f commit 2f2a300

File tree

6 files changed

+445
-0
lines changed

6 files changed

+445
-0
lines changed

lib/node_modules/@stdlib/blas/base/ssymv/manifest.json

Whitespace-only changes.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2020 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+
# VARIABLES #
20+
21+
ifndef VERBOSE
22+
QUIET := @
23+
else
24+
QUIET :=
25+
endif
26+
27+
# Determine the OS ([1][1], [2][2]).
28+
#
29+
# [1]: https://en.wikipedia.org/wiki/Uname#Examples
30+
# [2]: http://stackoverflow.com/a/27776822/2225624
31+
OS ?= $(shell uname)
32+
ifneq (, $(findstring MINGW,$(OS)))
33+
OS := WINNT
34+
else
35+
ifneq (, $(findstring MSYS,$(OS)))
36+
OS := WINNT
37+
else
38+
ifneq (, $(findstring CYGWIN,$(OS)))
39+
OS := WINNT
40+
else
41+
ifneq (, $(findstring Windows_NT,$(OS)))
42+
OS := WINNT
43+
endif
44+
endif
45+
endif
46+
endif
47+
48+
49+
# RULES #
50+
51+
#/
52+
# Removes generated files for building an add-on.
53+
#
54+
# @example
55+
# make clean-addon
56+
#/
57+
clean-addon:
58+
$(QUIET) -rm -f *.o *.node
59+
60+
.PHONY: clean-addon
61+
62+
#/
63+
# Removes generated files.
64+
#
65+
# @example
66+
# make clean
67+
#/
68+
clean: clean-addon
69+
70+
.PHONY: clean
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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/ssymv.h"
20+
#include "stdlib/blas/base/shared.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_int32.h"
25+
#include "stdlib/napi/argv_float.h"
26+
#include "stdlib/napi/argv_strided_float32array.h"
27+
#include "stdlib/napi/argv_strided_float32array2d.h"
28+
#include <node_api.h>
29+
30+
/**
31+
* Receives JavaScript callback invocation data.
32+
*
33+
* @param env environment under which the function is invoked
34+
* @param info callback data
35+
* @return Node-API value
36+
*/
37+
static napi_value addon( napi_env env, napi_callback_info info ) {
38+
STDLIB_NAPI_ARGV( env, info, argv, argc, 11 );
39+
40+
STDLIB_NAPI_ARGV_INT32( env, order, argv, 0 );
41+
STDLIB_NAPI_ARGV_INT32( env, uplo, argv, 1 );
42+
43+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 2 );
44+
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 7 );
45+
STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 10 );
46+
STDLIB_NAPI_ARGV_INT64( env, LDA, argv, 5 );
47+
48+
STDLIB_NAPI_ARGV_FLOAT( env, alpha, argv, 3 );
49+
STDLIB_NAPI_ARGV_FLOAT( env, beta, argv, 8 );
50+
51+
CBLAS_INT sa1;
52+
CBLAS_INT sa2;
53+
54+
if ( order == CblasColMajor ) {
55+
sa1 = 1;
56+
sa2 = LDA;
57+
} else { // order === 'row-major'
58+
sa1 = LDA;
59+
sa2 = 1;
60+
}
61+
62+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 6 );
63+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 9 );
64+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY2D( env, A, N, N, sa1, sa2, argv, 4 );
65+
66+
API_SUFFIX(c_ssymv)( order, uplo, N, alpha, A, LDA, X, strideX, beta, Y, strideY );
67+
68+
return NULL;
69+
}
70+
71+
/**
72+
* Receives JavaScript callback invocation data.
73+
*
74+
* @param env environment under which the function is invoked
75+
* @param info callback data
76+
* @return Node-API value
77+
*/
78+
static napi_value addon_method( napi_env env, napi_callback_info info ) {
79+
STDLIB_NAPI_ARGV( env, info, argv, argc, 14 );
80+
81+
STDLIB_NAPI_ARGV_INT32( env, uplo, argv, 0 );
82+
83+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 1 );
84+
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 8 );
85+
STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 9 );
86+
STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 12 );
87+
STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 13 );
88+
STDLIB_NAPI_ARGV_INT64( env, strideA1, argv, 4 );
89+
STDLIB_NAPI_ARGV_INT64( env, strideA2, argv, 5 );
90+
STDLIB_NAPI_ARGV_INT64( env, offsetA, argv, 6 );
91+
92+
STDLIB_NAPI_ARGV_FLOAT( env, alpha, argv, 2 );
93+
STDLIB_NAPI_ARGV_FLOAT( env, beta, argv, 10 );
94+
95+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 7 );
96+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 11 );
97+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY2D( env, A, N, N, strideA1, strideA2, argv, 3 );
98+
99+
API_SUFFIX(c_ssymv_ndarray)( uplo, N, alpha, A, strideA1, strideA2, offsetA, X, strideX, offsetX, beta, Y, strideY, offsetY );
100+
101+
return NULL;
102+
}
103+
104+
STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method )
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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/ssymv.h"
20+
#include "stdlib/blas/base/shared.h"
21+
#include "stdlib/strided/base/stride2offset.h"
22+
23+
/**
24+
* Performs the matrix-vector operation `Y = α*A*X + β*Y` where `α` and `β` are scalars, `X` and `Y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form.
25+
*
26+
* @param order storage layout
27+
* @param uplo specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied
28+
* @param N number of elements along each dimension of `A`
29+
* @param alpha scalar constant
30+
* @param A input matrix
31+
* @param LDA stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`)
32+
* @param X first input array
33+
* @param strideX `X` stride length
34+
* @param beta scalar constant
35+
* @param Y second input array
36+
* @param strideY `Y` stride length
37+
*/
38+
void API_SUFFIX(c_ssymv)( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *A, const CBLAS_INT LDA, const float *X, const CBLAS_INT strideX, const float beta, float *Y, const CBLAS_INT strideY ) {
39+
CBLAS_INT sa1;
40+
CBLAS_INT sa2;
41+
CBLAS_INT ox;
42+
CBLAS_INT oy;
43+
44+
if ( order == CblasColMajor ) {
45+
sa1 = 1;
46+
sa2 = LDA;
47+
} else { // order === 'row-major'
48+
sa1 = LDA;
49+
sa2 = 1;
50+
}
51+
ox = stdlib_strided_stride2offset( N, strideX );
52+
oy = stdlib_strided_stride2offset( N, strideY );
53+
API_SUFFIX(c_ssymv_ndarray)( uplo, N, alpha, A, sa1, sa2, 0, X, strideX, ox, beta, Y, strideY, oy );
54+
return;
55+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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/ssymv.h"
20+
#include "stdlib/blas/base/ssymv_cblas.h"
21+
#include "stdlib/blas/base/shared.h"
22+
#include "stdlib/strided/base/min_view_buffer_index.h"
23+
#include "stdlib/ndarray/base/min_view_buffer_index.h"
24+
25+
/**
26+
* Performs the matrix-vector operation `Y = α*A*X + β*Y` where `α` and `β` are scalars, `X` and `Y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form.
27+
*
28+
* @param order storage layout
29+
* @param uplo specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied
30+
* @param N number of elements along each dimension of `A`
31+
* @param alpha scalar constant
32+
* @param A input matrix
33+
* @param LDA stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`)
34+
* @param X first input array
35+
* @param strideX `X` stride length
36+
* @param beta scalar constant
37+
* @param Y second input array
38+
* @param strideY `Y` stride length
39+
* @return output value
40+
*/
41+
float API_SUFFIX(c_ssymv)( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *A, const CBLAS_INT LDA, const float *X, const CBLAS_INT strideX, const float beta, float *Y, const CBLAS_INT strideY ) {
42+
CBLAS_INT sx = strideX;
43+
CBLAS_INT sy = strideY;
44+
if ( sx < 0 ) {
45+
sx = -sx;
46+
}
47+
if ( sy < 0 ) {
48+
sy = -sy;
49+
}
50+
return API_SUFFIX(cblas_ssymv)( order, uplo, N, alpha, A, LDA, X, sx, beta, Y, sy );
51+
}
52+
53+
/**
54+
* Performs the matrix-vector operation `Y = α*A*X + β*Y` using alternative indexing semantics, where `α` and `β` are scalars, `X` and `Y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form.
55+
*
56+
* @param uplo specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied
57+
* @param N number of elements along each dimension of `A`
58+
* @param alpha scalar constant
59+
* @param A input matrix
60+
* @param strideA1 stride of the first dimension of `A`
61+
* @param strideA2 stride of the second dimension of `A`
62+
* @param offsetA starting index for `A`
63+
* @param X first input array
64+
* @param strideX `X` stride length
65+
* @param offsetX starting `X` index
66+
* @param beta scalar constant
67+
* @param Y second input array
68+
* @param strideY `Y` stride length
69+
* @param offsetY starting `Y` index
70+
* @return output value
71+
*/
72+
float API_SUFFIX(c_ssymv_ndarray)( const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const float beta, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) {
73+
CBLAS_INT sx = strideX;
74+
CBLAS_INT sy = strideY;
75+
if ( sx < 0 ) {
76+
sx = -sx;
77+
}
78+
if ( sy < 0 ) {
79+
sy = -sy;
80+
}
81+
X += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); // adjust array pointer
82+
Y += stdlib_strided_min_view_buffer_index( N, strideY, offsetY ); // adjust array pointer
83+
const int64_t shape[] = { N, N };
84+
const int64_t strides[] = { strideA1, strideA2 };
85+
A += stdlib_ndarray_min_view_buffer_index( 2, shape, strides, offsetA ); // adjust array pointer
86+
return API_SUFFIX(cblas_ssymv)( order, uplo, N, alpha, A, LDA, X, sx, beta, Y, sy );
87+
}

0 commit comments

Comments
 (0)