Skip to content

Commit 9360e31

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents aabe731 + 46cda32 commit 9360e31

39 files changed

+3164
-0
lines changed

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

+255
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
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+
# dsyr
22+
23+
> Perform the symmetric rank 1 operation `A = α*x*x^T + A`.
24+
25+
<section class = "usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var dsyr = require( '@stdlib/blas/base/dsyr' );
31+
```
32+
33+
#### dsyr( order, uplo, N, α, x, sx, A, LDA )
34+
35+
Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix.
36+
37+
```javascript
38+
var Float64Array = require( '@stdlib/array/float64' );
39+
40+
var A = new Float64Array( [ 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ] );
41+
var x = new Float64Array( [ 1.0, 2.0, 3.0 ] );
42+
43+
dsyr( 'row-major', 'upper', 3, 1.0, x, 1, A, 3 );
44+
// A => <Float64Array>[ 2.0, 4.0, 6.0, 0.0, 5.0, 8.0, 0.0, 0.0, 10.0 ]
45+
```
46+
47+
The function has the following parameters:
48+
49+
- **order**: storage layout.
50+
- **uplo**: specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced.
51+
- **N**: number of elements along each dimension of `A`.
52+
- **α**: scalar constant.
53+
- **x**: input [`Float64Array`][mdn-float64array].
54+
- **sx**: index increment for `x`.
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+
58+
The stride parameters determine how elements in the input arrays are accessed at runtime. For example, to iterate over every other element of `x` in reverse order,
59+
60+
```javascript
61+
var Float64Array = require( '@stdlib/array/float64' );
62+
63+
var A = new Float64Array( [ 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ] );
64+
var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
65+
66+
dsyr( 'row-major', 'upper', 3, 1.0, x, -2, A, 3 );
67+
// A => <Float64Array>[ 26.0, 17.0, 8.0, 0.0, 10.0, 5.0, 0.0, 0.0, 2.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 A = new Float64Array( [ 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.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+
dsyr( 'row-major', 'upper', 3, 1.0, x1, -1, A, 3 );
85+
// A => <Float64Array>[ 2.0, 3.0, 4.0, 0.0, 2.0, 3.0, 0.0, 0.0, 2.0 ]
86+
```
87+
88+
#### dsyr.ndarray( uplo, N, α, x, sx, ox, A, sa1, sa2, oa )
89+
90+
Performs the symmetric rank 1 operation `A = α*x*x^T + A`, using alternative indexing semantics and where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix.
91+
92+
```javascript
93+
var Float64Array = require( '@stdlib/array/float64' );
94+
95+
var A = new Float64Array( [ 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ] );
96+
var x = new Float64Array( [ 1.0, 2.0, 3.0 ] );
97+
98+
dsyr.ndarray( 'upper', 3, 1.0, x, 1, 0, A, 3, 1, 0 );
99+
// A => <Float64Array>[ 2.0, 4.0, 6.0, 0.0, 5.0, 8.0, 0.0, 0.0, 10.0 ]
100+
```
101+
102+
The function has the following additional parameters:
103+
104+
- **ox**: starting index for `x`.
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+
109+
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,
110+
111+
```javascript
112+
var Float64Array = require( '@stdlib/array/float64' );
113+
114+
var A = new Float64Array( [ 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ] );
115+
var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
116+
117+
dsyr.ndarray( 'upper', 3, 1.0, x, -2, 4, A, 3, 1, 0 );
118+
// A => <Float64Array>[ 26.0, 17.0, 8.0, 0.0, 10.0, 5.0, 0.0, 0.0, 2.0 ]
119+
```
120+
121+
</section>
122+
123+
<!-- /.usage -->
124+
125+
<section class="notes">
126+
127+
## Notes
128+
129+
- `dsyr()` corresponds to the [BLAS][blas] level 2 function [`dsyr`][blas-dsyr].
130+
131+
</section>
132+
133+
<!-- /.notes -->
134+
135+
<section class="examples">
136+
137+
## Examples
138+
139+
<!-- eslint no-undef: "error" -->
140+
141+
```javascript
142+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
143+
var ones = require( '@stdlib/array/ones' );
144+
var dsyr = require( '@stdlib/blas/base/dsyr' );
145+
146+
var opts = {
147+
'dtype': 'float64'
148+
};
149+
150+
var N = 3;
151+
152+
var A = ones( N*N, opts.dtype );
153+
var x = discreteUniform( N, -10.0, 10.0, opts );
154+
155+
dsyr( 'row-major', 'upper', 3, 1.0, x, 1, A, 3 );
156+
console.log( A );
157+
```
158+
159+
</section>
160+
161+
<!-- /.examples -->
162+
163+
<!-- C interface documentation. -->
164+
165+
* * *
166+
167+
<section class="c">
168+
169+
## C APIs
170+
171+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
172+
173+
<section class="intro">
174+
175+
</section>
176+
177+
<!-- /.intro -->
178+
179+
<!-- C usage documentation. -->
180+
181+
<section class="usage">
182+
183+
### Usage
184+
185+
```c
186+
TODO
187+
```
188+
189+
#### TODO
190+
191+
TODO.
192+
193+
```c
194+
TODO
195+
```
196+
197+
TODO
198+
199+
```c
200+
TODO
201+
```
202+
203+
</section>
204+
205+
<!-- /.usage -->
206+
207+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
208+
209+
<section class="notes">
210+
211+
</section>
212+
213+
<!-- /.notes -->
214+
215+
<!-- C API usage examples. -->
216+
217+
<section class="examples">
218+
219+
### Examples
220+
221+
```c
222+
TODO
223+
```
224+
225+
</section>
226+
227+
<!-- /.examples -->
228+
229+
</section>
230+
231+
<!-- /.c -->
232+
233+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
234+
235+
<section class="related">
236+
237+
</section>
238+
239+
<!-- /.related -->
240+
241+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
242+
243+
<section class="links">
244+
245+
[blas]: http://www.netlib.org/blas
246+
247+
[blas-dsyr]: https://www.netlib.org/lapack/explore-html/dc/d82/group__her_ga07f0e3f8592107877f12a554a41c7413.html#ga07f0e3f8592107877f12a554a41c7413
248+
249+
[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
250+
251+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
252+
253+
</section>
254+
255+
<!-- /.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 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 dsyr = require( './../lib/dsyr.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 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 = dsyr( 'row-major', 'upper', N, 1.0, x, 1, A, N );
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)