Skip to content

Commit e72d12e

Browse files
feat: add C implementation for blas/base/dspmv
--- 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: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 499bdc0 commit e72d12e

23 files changed

Lines changed: 3594 additions & 8 deletions

lib/node_modules/@stdlib/blas/base/dspmv/README.md

Lines changed: 91 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2024 The Stdlib Authors.
5+
Copyright (c) 2026 The Stdlib Authors.
66
77
Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.
@@ -190,21 +190,72 @@ console.log( y );
190190
### Usage
191191

192192
```c
193-
TODO
193+
#include "stdlib/blas/base/dspmv.h"
194194
```
195195

196-
#### TODO
196+
#### c_dspmv( order, uplo, N, alpha, \*AP, \*X, strideX, beta, \*Y, strideY )
197197

198-
TODO.
198+
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 `AP`.
199+
200+
```c
201+
#include "stdlib/blas/base/shared.h"
202+
203+
const double AP[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
204+
const double x[] = { 1.0, 1.0, 1.0 };
205+
double y[] = { 1.0, 1.0, 1.0 };
206+
207+
c_dspmv( CblasColMajor, CblasLower, 3, 1.0, AP, x, 1, 1.0, y, 1 );
208+
```
209+
210+
The function accepts the following arguments:
211+
212+
- **order**: `[in] CBLAS_LAYOUT` storage layout.
213+
- **uplo**: `[in] CBLAS_UPLO` specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied.
214+
- **N**: `[in] CBLAS_INT` number of elements along each dimension of `A`.
215+
- **alpha**: `[in] double` scalar constant.
216+
- **AP**: `[in] double*` packed form of a symmetric matrix `A`.
217+
- **X**: `[in] double*` first input vector.
218+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
219+
- **beta**: `[in] double` scalar constant.
220+
- **Y**: `[inout] double*` second input vector.
221+
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
199222
200223
```c
201-
TODO
224+
void c_dspmv( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const double alpha, const double *AP, const double *X, const CBLAS_INT strideX, const double beta, double *Y, const CBLAS_INT strideY )
225+
```
226+
227+
#### c_dspmv_ndarray( order, uplo, N, alpha, \*AP, oap, \*X, sx, ox, beta, \*Y, sy, oy )
228+
229+
Performs the matrix-vector operation `y = α*A*x + β*y` using alternative indexing semantics and where `α` and `β` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form `AP`.
230+
231+
```c
232+
#include "stdlib/blas/base/shared.h"
233+
234+
const double AP[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
235+
const double x[] = { 1.0, 1.0, 1.0 };
236+
double y[] = { 1.0, 1.0, 1.0 };
237+
238+
c_dspmv_ndarray( CblasColMajor, CblasLower, 3, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 );
202239
```
203240
204-
TODO
241+
The function accepts the following arguments:
242+
243+
- **order**: `[in] CBLAS_LAYOUT` storage layout.
244+
- **uplo**: `[in] CBLAS_UPLO` specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied.
245+
- **N**: `[in] CBLAS_INT` number of elements along each dimension of `A`.
246+
- **alpha**: `[in] double` scalar.
247+
- **AP**: `[in] double*` packed form of a symmetric matrix `A`.
248+
- **oap**: `[in] CBLAS_INT` starting index for `AP`.
249+
- **X**: `[in] double*` first input vector.
250+
- **sx**: `[in] CBLAS_INT` stride length for `X`.
251+
- **ox**: `[in] CBLAS_INT` starting index for `X`.
252+
- **beta**: `[in] double` scalar.
253+
- **Y**: `[inout] double*` second input vector.
254+
- **sy**: `[in] CBLAS_INT` stride length for `Y`.
255+
- **oy**: `[in] CBLAS_INT` starting index for `Y`.
205256
206257
```c
207-
TODO
258+
void c_dspmv_ndarray( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const double alpha, const double *AP, const CBLAS_INT offsetAP, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double beta, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY )
208259
```
209260

210261
</section>
@@ -226,7 +277,39 @@ TODO
226277
### Examples
227278

228279
```c
229-
TODO
280+
#include "stdlib/blas/base/dspmv.h"
281+
#include "stdlib/blas/base/shared.h"
282+
#include <stdio.h>
283+
284+
int main( void ) {
285+
// Define `AP`, a packed form of a symmetric matrix `A`:
286+
const double AP[ 3*(3+1)/2 ] = {
287+
1.0, 2.0, 3.0, 4.0, 5.0, 6.0
288+
};
289+
290+
// Define `x` and `y` vectors:
291+
const double x[ 3 ] = { 1.0, 1.0, 1.0 };
292+
double y[ 3 ] = { 1.0, 1.0, 1.0 };
293+
294+
// Specify the number of elements along each dimension of `A`:
295+
const int N = 3;
296+
297+
// Perform the matrix-vector operation `y = α*A*x + β*y`:
298+
c_dspmv( CblasColMajor, CblasLower, N, 1.0, AP, x, 1, 1.0, y, 1 );
299+
300+
// Print the result:
301+
for ( int i = 0; i < N; i++ ) {
302+
printf( "y[ %i ] = %lf\n", i, y[ i ] );
303+
}
304+
305+
// Perform the matrix-vector operation `y = α*A*x + β*y` using alternative indexing semantics:
306+
c_dspmv_ndarray( CblasColMajor, CblasLower, N, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 );
307+
308+
// Print the result:
309+
for ( int i = 0; i < N; i++ ) {
310+
printf( "y[ %i ] = %lf\n", i, y[ i ] );
311+
}
312+
}
230313
```
231314
232315
</section>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var format = require( '@stdlib/string/format' );
27+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
28+
var pow = require( '@stdlib/math/base/special/pow' );
29+
var floor = require( '@stdlib/math/base/special/floor' );
30+
var tryRequire = require( '@stdlib/utils/try-require' );
31+
var pkg = require( './../package.json' ).name;
32+
33+
34+
// VARIABLES //
35+
36+
var dspmv = tryRequire( resolve( __dirname, './../lib/dspmv.native.js' ) );
37+
var opts = {
38+
'skip': ( dspmv instanceof Error )
39+
};
40+
var options = {
41+
'dtype': 'float64'
42+
};
43+
44+
45+
// FUNCTIONS //
46+
47+
/**
48+
* Creates a benchmark function.
49+
*
50+
* @private
51+
* @param {PositiveInteger} len - array length
52+
* @returns {Function} benchmark function
53+
*/
54+
function createBenchmark( len ) {
55+
var AP = uniform( len * ( len + 1 ) / 2, -10.0, 10.0, options );
56+
var x = uniform( len, -10.0, 10.0, options );
57+
var y = uniform( len, -10.0, 10.0, options );
58+
return benchmark;
59+
60+
/**
61+
* Benchmark function.
62+
*
63+
* @private
64+
* @param {Benchmark} b - benchmark instance
65+
*/
66+
function benchmark( b ) {
67+
var z;
68+
var i;
69+
70+
b.tic();
71+
for ( i = 0; i < b.iterations; i++ ) {
72+
z = dspmv( 'row-major', 'upper', len, 1.0, AP, x, 1, 1.0, y, 1 );
73+
if ( isnan( z[ i%z.length ] ) ) {
74+
b.fail( 'should not return NaN' );
75+
}
76+
}
77+
b.toc();
78+
if ( isnan( z[ i%z.length ] ) ) {
79+
b.fail( 'should not return NaN' );
80+
}
81+
b.pass( 'benchmark finished' );
82+
b.end();
83+
}
84+
}
85+
86+
87+
// MAIN //
88+
89+
/**
90+
* Main execution sequence.
91+
*
92+
* @private
93+
*/
94+
function main() {
95+
var len;
96+
var min;
97+
var max;
98+
var f;
99+
var i;
100+
101+
min = 1; // 10^min
102+
max = 6; // 10^max
103+
104+
for ( i = min; i <= max; i++ ) {
105+
len = floor( pow( pow( 10, i ), 1.0/2.0 ) );
106+
f = createBenchmark( len );
107+
bench( format( '%s::native:size=%d', pkg, len * ( len + 1 ) / 2 ), opts, f );
108+
}
109+
}
110+
111+
main();
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var format = require( '@stdlib/string/format' );
27+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
28+
var pow = require( '@stdlib/math/base/special/pow' );
29+
var floor = require( '@stdlib/math/base/special/floor' );
30+
var tryRequire = require( '@stdlib/utils/try-require' );
31+
var pkg = require( './../package.json' ).name;
32+
33+
34+
// VARIABLES //
35+
36+
var dspmv = tryRequire( resolve( __dirname, './../lib/dspmv.native.js' ) );
37+
var opts = {
38+
'skip': ( dspmv instanceof Error )
39+
};
40+
var options = {
41+
'dtype': 'float64'
42+
};
43+
44+
45+
// FUNCTIONS //
46+
47+
/**
48+
* Creates a benchmark function.
49+
*
50+
* @private
51+
* @param {PositiveInteger} len - array length
52+
* @returns {Function} benchmark function
53+
*/
54+
function createBenchmark( len ) {
55+
var AP = uniform( len * ( len + 1 ) / 2, -10.0, 10.0, options );
56+
var x = uniform( len, -10.0, 10.0, options );
57+
var y = uniform( len, -10.0, 10.0, options );
58+
return benchmark;
59+
60+
/**
61+
* Benchmark function.
62+
*
63+
* @private
64+
* @param {Benchmark} b - benchmark instance
65+
*/
66+
function benchmark( b ) {
67+
var z;
68+
var i;
69+
70+
b.tic();
71+
for ( i = 0; i < b.iterations; i++ ) {
72+
z = dspmv( 'row-major', 'upper', len, 1.0, AP, 0, x, 1, 0, 1.0, y, 1, 0 );
73+
if ( isnan( z[ i%z.length ] ) ) {
74+
b.fail( 'should not return NaN' );
75+
}
76+
}
77+
b.toc();
78+
if ( isnan( z[ i%z.length ] ) ) {
79+
b.fail( 'should not return NaN' );
80+
}
81+
b.pass( 'benchmark finished' );
82+
b.end();
83+
}
84+
}
85+
86+
87+
// MAIN //
88+
89+
/**
90+
* Main execution sequence.
91+
*
92+
* @private
93+
*/
94+
function main() {
95+
var len;
96+
var min;
97+
var max;
98+
var f;
99+
var i;
100+
101+
min = 1; // 10^min
102+
max = 6; // 10^max
103+
104+
for ( i = min; i <= max; i++ ) {
105+
len = floor( pow( pow( 10, i ), 1.0/2.0 ) );
106+
f = createBenchmark( len );
107+
bench( format( '%s:ndarray:size=%d', pkg, len * ( len + 1 ) / 2 ), opts, f );
108+
}
109+
}
110+
111+
main();

0 commit comments

Comments
 (0)