Skip to content

Commit 2254a56

Browse files
aman-095kgryte
andauthored
feat!: add blas/base/strmv
BREAKING CHANGE: rename `none` transpose operation to `no-transpose` in `@stdlib/types` To migrate, users should change their usage of `none` to `no-transpose`. This change enhances code readability and aligns the string literal with the C enumeration constant. PR-URL: #2535 Ref: #2039 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent 4300111 commit 2254a56

Some content is hidden

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

49 files changed

+3948
-2
lines changed

Diff for: lib/node_modules/@stdlib/blas/base/strmv/README.md

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