Skip to content

Commit 0cd0eaf

Browse files
committed
feat: add blas/base/dtbmv
--- 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 1d9ed30 commit 0cd0eaf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

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

0 commit comments

Comments
 (0)