Skip to content

Commit 89b6e5e

Browse files
committed
feat: add BLAS Level 2 routine for dtpmv
1 parent 50b38f9 commit 89b6e5e

Some content is hidden

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

46 files changed

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

0 commit comments

Comments
 (0)