|
| 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 | +# gsyr |
| 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 gsyr = require( '@stdlib/blas/base/gsyr' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### gsyr( 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 = [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ]; |
| 41 | +var x = [ 1.0, 2.0, 3.0 ]; |
| 42 | + |
| 43 | +gsyr( 'row-major', 'upper', 3, 1.0, x, 1, A, 3 ); |
| 44 | +// A => [ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.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 array. |
| 54 | +- **sx**: stride length for `x`. |
| 55 | +- **A**: input matrix stored in linear memory. |
| 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 the elements of `x` in reverse order, |
| 59 | + |
| 60 | +```javascript |
| 61 | +var A = [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ]; |
| 62 | +var x = [ 3.0, 2.0, 1.0 ]; |
| 63 | + |
| 64 | +gsyr( 'row-major', 'upper', 3, 1.0, x, -1, A, 3 ); |
| 65 | +// A => <Float64Array>[ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.0, 10.0 ] |
| 66 | +``` |
| 67 | + |
| 68 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. |
| 69 | + |
| 70 | +<!-- eslint-disable stdlib/capitalized-comments --> |
| 71 | + |
| 72 | +```javascript |
| 73 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 74 | + |
| 75 | +// Initial arrays... |
| 76 | +var x0 = new Float64Array( [ 0.0, 3.0, 2.0, 1.0 ] ); |
| 77 | +var A = new Float64Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); |
| 78 | + |
| 79 | +// Create offset views... |
| 80 | +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 81 | + |
| 82 | +gsyr( 'row-major', 'upper', 3, 1.0, x1, -1, A, 3 ); |
| 83 | +// A => <Float64Array>[ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.0, 10.0 ] |
| 84 | +``` |
| 85 | + |
| 86 | +#### gsyr.ndarray( uplo, N, α, x, sx, ox, A, sa1, sa2, oa ) |
| 87 | + |
| 88 | +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. |
| 89 | + |
| 90 | +```javascript |
| 91 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 92 | + |
| 93 | +var A = [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ]; |
| 94 | +var x = [ 1.0, 2.0, 3.0 ]; |
| 95 | + |
| 96 | +gsyr.ndarray( 'upper', 3, 1.0, x, 1, 0, A, 3, 1, 0 ); |
| 97 | +// A => <Float64Array>[ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.0, 10.0 ] |
| 98 | +``` |
| 99 | + |
| 100 | +The function has the following additional parameters: |
| 101 | + |
| 102 | +- **ox**: starting index for `x`. |
| 103 | +- **sa1**: stride of the first dimension of `A`. |
| 104 | +- **sa2**: stride of the second dimension of `A`. |
| 105 | +- **oa**: starting index for `A`. |
| 106 | + |
| 107 | +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, |
| 108 | + |
| 109 | +```javascript |
| 110 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 111 | + |
| 112 | +var A = [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ]; |
| 113 | +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; |
| 114 | + |
| 115 | +gsyr.ndarray( 'upper', 3, 1.0, x, -2, 4, A, 3, 1, 0 ); |
| 116 | +// A => [ 26.0, 17.0, 8.0, 2.0, 10.0, 5.0, 3.0, 2.0, 2.0 ] |
| 117 | +``` |
| 118 | + |
| 119 | +</section> |
| 120 | + |
| 121 | +<!-- /.usage --> |
| 122 | + |
| 123 | +<section class="notes"> |
| 124 | + |
| 125 | +## Notes |
| 126 | + |
| 127 | +- `gsyr()` corresponds to the [BLAS][blas] level 2 function [`dsyr`][dsyr] with the exception that this implementation works with any array type, not just Float64Arrays. Depending on the environment, the typed versions ([`dsyr`][@stdlib/blas/base/dsyr], [`ssyr`][@stdlib/blas/base/ssyr], etc.) are likely to be significantly more performant. |
| 128 | +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). |
| 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 ones = require( '@stdlib/array/ones' ); |
| 143 | +var gsyr = require( '@stdlib/blas/base/gsyr' ); |
| 144 | + |
| 145 | +var opts = { |
| 146 | + 'dtype': 'gsyr' |
| 147 | +}; |
| 148 | + |
| 149 | +var N = 3; |
| 150 | + |
| 151 | +// Create N-by-N symmetric matrices: |
| 152 | +var A1 = ones( N*N, opts.dtype ); |
| 153 | +var A2 = ones( N*N, opts.dtype ); |
| 154 | + |
| 155 | +// Create a random vector: |
| 156 | +var x = discreteUniform( N, -10.0, 10.0, opts ); |
| 157 | + |
| 158 | +gsyr( 'row-major', 'upper', 3, 1.0, x, 1, A1, 3 ); |
| 159 | +console.log( A1 ); |
| 160 | + |
| 161 | +gsyr.ndarray( 'upper', 3, 1.0, x, 1, 0, A2, 3, 1, 0 ); |
| 162 | +console.log( A2 ); |
| 163 | +``` |
| 164 | + |
| 165 | +</section> |
| 166 | + |
| 167 | +<!-- /.examples --> |
| 168 | + |
| 169 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 170 | + |
| 171 | +<section class="related"> |
| 172 | + |
| 173 | +</section> |
| 174 | + |
| 175 | +<!-- /.related --> |
| 176 | + |
| 177 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 178 | + |
| 179 | +<section class="links"> |
| 180 | + |
| 181 | +[blas]: http://www.netlib.org/blas |
| 182 | + |
| 183 | +[dsyr]: https://www.netlib.org/lapack/explore-html/dc/d82/group__her_ga07f0e3f8592107877f12a554a41c7413.html#ga07f0e3f8592107877f12a554a41c7413 |
| 184 | + |
| 185 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 186 | + |
| 187 | +[@stdlib/blas/base/dsyr]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/dsyr |
| 188 | + |
| 189 | +[@stdlib/blas/base/ssyr]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/ssyr |
| 190 | + |
| 191 | +[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor |
| 192 | + |
| 193 | + |
| 194 | +</section> |
| 195 | + |
| 196 | +<!-- /.links --> |
0 commit comments