Skip to content

Commit 07b88a6

Browse files
committed
feat: add blas/base/ssbmv
--- 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: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - 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: na - 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: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent fcd86ae commit 07b88a6

40 files changed

+3986
-0
lines changed
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
21+
# ssbmv
22+
23+
> Perform the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric band matrix, with `K` super-diagonals.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var ssbmv = require( '@stdlib/blas/base/ssbmv' );
31+
```
32+
33+
#### ssbmv( order, uplo, N, K, α, A, x, LDA, sx, β, y, sy )
34+
35+
Performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric band matrix, with `K` super-diagonals.
36+
37+
```javascript
38+
var Float32Array = require( '@stdlib/array/float32' );
39+
40+
var A = new Float32Array( [ 1.0, 2.0, 0.0, 4.0, 3.0, 5.0 ] );
41+
var x = new Float32Array( [ 1.0, 2.0, 3.0 ] );
42+
var y = new Float32Array( [ 0.0, 0.0, 0.0 ] );
43+
44+
ssbmv( 'row-major', 'lower', 3, 1, 1.0, A, 2, x, 1, 0.0, y, 1 );
45+
// y => <Float32Array>[ 2.0, 17.0, 21.0 ]
46+
```
47+
48+
The function has the following parameters:
49+
50+
- **order**: storage layout.
51+
- **uplo**: specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied.
52+
- **N**: specifies the order of the matrix `A`.
53+
- **K**: specifies the number of super-diagonals of the matrix `A`
54+
- **α**: scalar constant.
55+
- **A**: packed banded form of a symmetric matrix `A` stored in linear memory as a [`Float32Array`][mdn-float32array].
56+
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`)
57+
- **x**: input [`Float32Array`][mdn-float32array].
58+
- **sx**: index increment for `x`.
59+
- **β**: scalar constant.
60+
- **y**: output [`Float32Array`][mdn-float32array].
61+
- **sy**: index increment for `y`.
62+
63+
The stride parameters determine how elements in the input arrays are accessed at runtime. For example, to iterate over the elements of `y` in reverse order,
64+
65+
```javascript
66+
var Float32Array = require( '@stdlib/array/float32' );
67+
68+
var A = new Float32Array( [ 1.0, 2.0, 0.0, 4.0, 3.0, 5.0 ] );
69+
var x = new Float32Array( [ 1.0, 2.0, 3.0 ] );
70+
var y = new Float32Array( [ 0.0, 0.0, 0.0 ] );
71+
72+
ssbmv( 'row-major', 'lower', 3, 1, 1.0, A, 2, x, 1, 0.0, y, -1 );
73+
// y => <Float32Array>[ 21.0, 17.0, 2.0 ]
74+
```
75+
76+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
77+
78+
<!-- eslint-disable stdlib/capitalized-comments -->
79+
80+
```javascript
81+
var Float32Array = require( '@stdlib/array/float32' );
82+
83+
// Initial arrays...
84+
var x0 = new Float32Array( [ 0.0, 1.0, 2.0, 3.0 ] );
85+
var y0 = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] );
86+
var A = new Float32Array( [ 1.0, 2.0, 0.0, 4.0, 3.0, 5.0 ] );
87+
88+
// Create offset views...
89+
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
90+
var y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
91+
92+
ssbmv( 'row-major', 'lower', 3, 1, 1.0, A, 2, x1, 1, 0.0, y1, 1 );
93+
// y0 => <Float32Array>[ 0.0, 2.0, 17.0, 21.0 ]
94+
```
95+
96+
#### ssbmv.ndarray( uplo, N, K, α, A, sa1, sa2, oa, x, sx, ox, β, y, sy, oy )
97+
98+
Performs the matrix-vector operation `y = alpha*A*x + beta*y` using alternative indexing semantics where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric band matrix, with `K` super-diagonals.
99+
100+
```javascript
101+
var Float32Array = require( '@stdlib/array/float32' );
102+
103+
var A = new Float32Array( [ 1.0, 2.0, 0.0, 4.0, 3.0, 5.0 ] );
104+
var x = new Float32Array( [ 1.0, 2.0, 3.0 ] );
105+
var y = new Float32Array( [ 0.0, 0.0, 0.0 ] );
106+
107+
ssbmv.ndarray( 'lower', 3, 1, 1.0, A, 2, 1, 0, x, 1, 0, 0.0, y, 1, 0 );
108+
// y => <Float32Array>[ 2.0, 17.0, 21.0 ]
109+
```
110+
111+
The function has the following additional parameters:
112+
113+
- **oa**: starting index for `A`.
114+
- **sa1**: first dimension index increment for `A`.
115+
- **sa2**: second dimension index increment for `A`.
116+
- **ox**: starting index for `x`.
117+
- **oy**: starting index for `y`.
118+
119+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example,
120+
121+
```javascript
122+
var Float32Array = require( '@stdlib/array/float32' );
123+
124+
var A = new Float32Array( [ 1.0, 2.0, 0.0, 4.0, 3.0, 5.0 ] );
125+
var x = new Float32Array( [ 0.0, 1.0, 2.0, 3.0 ] );
126+
var y = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] );
127+
128+
ssbmv.ndarray( 'lower', 3, 1, 1.0, A, 2, 1, 0, x, 1, 1, 0.0, y, 1, 1 );
129+
// y => <Float32Array>[ 0.0, 2.0, 17.0, 21.0 ]
130+
```
131+
132+
</section>
133+
134+
<!-- /.usage -->
135+
136+
<section class="notes">
137+
138+
## Notes
139+
140+
- `ssbmv()` corresponds to the [BLAS][blas] level 2 function [`ssbmv`][ssbmv].
141+
142+
</section>
143+
144+
<!-- /.notes -->
145+
146+
<section class="examples">
147+
148+
## Examples
149+
150+
<!-- eslint no-undef: "error" -->
151+
152+
```javascript
153+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
154+
var ssbmv = require( '@stdlib/blas/base/ssbmv' );
155+
156+
var opts = {
157+
'dtype': 'float32'
158+
};
159+
160+
var N = 3;
161+
var A = [ 1, 2, 0, 3, 4, 5 ];
162+
163+
var x = discreteUniform( N, -10, 10, opts );
164+
var y = discreteUniform( N, -10, 10, opts );
165+
166+
ssbmv.ndarray( 'upper', N, 1, 1.0, A, 1, 2, 0, x, 1, 0, 1.0, y, 1, 0 );
167+
console.log( y );
168+
```
169+
170+
</section>
171+
172+
<!-- /.examples -->
173+
174+
<!-- C interface documentation. -->
175+
176+
* * *
177+
178+
<section class="c">
179+
180+
## C APIs
181+
182+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
183+
184+
<section class="intro">
185+
186+
</section>
187+
188+
<!-- /.intro -->
189+
190+
<!-- C usage documentation. -->
191+
192+
<section class="usage">
193+
194+
### Usage
195+
196+
```c
197+
TODO
198+
```
199+
200+
#### TODO
201+
202+
TODO.
203+
204+
```c
205+
TODO
206+
```
207+
208+
TODO
209+
210+
```c
211+
TODO
212+
```
213+
214+
</section>
215+
216+
<!-- /.usage -->
217+
218+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
219+
220+
<section class="notes">
221+
222+
</section>
223+
224+
<!-- /.notes -->
225+
226+
<!-- C API usage examples. -->
227+
228+
<section class="examples">
229+
230+
### Examples
231+
232+
```c
233+
TODO
234+
```
235+
236+
</section>
237+
238+
<!-- /.examples -->
239+
240+
</section>
241+
242+
<!-- /.c -->
243+
244+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
245+
246+
<section class="related">
247+
248+
</section>
249+
250+
<!-- /.related -->
251+
252+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
253+
254+
<section class="links">
255+
256+
[blas]: http://www.netlib.org/blas
257+
258+
[ssbmv]: https://www.netlib.org/lapack/explore-html/da/dd4/group__hbmv_ga88a3a066357e907495d20d2b75a6f2ea.html
259+
260+
[mdn-float32array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
261+
262+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
263+
264+
</section>
265+
266+
<!-- /.links -->
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) 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+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var floor = require( '@stdlib/math/base/special/floor' );
28+
var pkg = require( './../package.json' ).name;
29+
var ssbmv = require( './../lib/ssbmv.js' );
30+
31+
32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float32'
36+
};
37+
38+
39+
// FUNCTIONS //
40+
41+
/**
42+
* Creates a benchmark function.
43+
*
44+
* @private
45+
* @param {PositiveInteger} len - array length
46+
* @returns {Function} benchmark function
47+
*/
48+
function createBenchmark( len ) {
49+
var x = uniform( len, -10.0, 10.0, options );
50+
var y = uniform( len, -10.0, 10.0, options );
51+
var A = [ 0,
52+
9,
53+
10,
54+
11,
55+
12,
56+
5,
57+
1,
58+
2,
59+
0 ];
60+
return benchmark;
61+
62+
/**
63+
* Benchmark function.
64+
*
65+
* @private
66+
* @param {Benchmark} b - benchmark instance
67+
*/
68+
function benchmark( b ) {
69+
var z;
70+
var i;
71+
72+
b.tic();
73+
for ( i = 0; i < b.iterations; i++ ) {
74+
z = ssbmv( 'row-major', 'upper', len, 1.0, 1, A, 2, x, 1, 1.0, y, 1 );
75+
if ( isnanf( z[ i%z.length ] ) ) {
76+
b.fail( 'should not return NaN' );
77+
}
78+
}
79+
b.toc();
80+
if ( isnanf( z[ i%z.length ] ) ) {
81+
b.fail( 'should not return NaN' );
82+
}
83+
b.pass( 'benchmark finished' );
84+
b.end();
85+
}
86+
}
87+
88+
89+
// MAIN //
90+
91+
/**
92+
* Main execution sequence.
93+
*
94+
* @private
95+
*/
96+
function main() {
97+
var len;
98+
var f;
99+
100+
len = floor( pow( pow( 10, 1 ), 1.0/2.0 ) );
101+
f = createBenchmark( len );
102+
bench( pkg+':size='+(len*len), f );
103+
}
104+
105+
main();

0 commit comments

Comments
 (0)