|
| 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 | +# ggemv |
| 22 | + |
| 23 | +> Perform one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var ggemv = require( '@stdlib/blas/base/ggemv' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### ggemv( order, trans, M, N, α, A, LDA, x, sx, β, y, sy ) |
| 34 | + |
| 35 | +Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; |
| 39 | +var x = [ 1.0, 1.0, 1.0 ]; |
| 40 | +var y = [ 1.0, 1.0 ]; |
| 41 | + |
| 42 | +ggemv( 'row-major', 'no-transpose', 2, 3, 1.0, A, 3, x, 1, 1.0, y, 1 ); |
| 43 | +// y => [ 7.0, 16.0 ] |
| 44 | +``` |
| 45 | + |
| 46 | +The function has the following parameters: |
| 47 | + |
| 48 | +- **order**: storage layout. |
| 49 | +- **trans**: specifies whether `A` should be transposed, conjugate-transposed, or not transposed. |
| 50 | +- **M**: number of rows in the matrix `A`. |
| 51 | +- **N**: number of columns in the matrix `A`. |
| 52 | +- **α**: scalar constant. |
| 53 | +- **A**: input matrix stored in linear memory. |
| 54 | +- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). |
| 55 | +- **x**: first input vector. |
| 56 | +- **sx**: stride length for `x`. |
| 57 | +- **β**: scalar constant. |
| 58 | +- **y**: second input vector. |
| 59 | +- **sy**: stride length for `y`. |
| 60 | + |
| 61 | +The stride parameters determine how operations are performed. For example, to iterate over every other element in `x` and `y`, |
| 62 | + |
| 63 | +```javascript |
| 64 | +var A = [ 1.0, 2.0, 3.0, 4.0 ]; |
| 65 | +var x = [ 1.0, 0.0, 1.0, 0.0 ]; |
| 66 | +var y = [ 1.0, 0.0, 1.0, 0.0 ]; |
| 67 | + |
| 68 | +ggemv( 'row-major', 'no-transpose', 2, 2, 1.0, A, 2, x, 2, 1.0, y, 2 ); |
| 69 | +// y => [ 4.0, 0.0, 8.0, 0.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, 1.0 ] ); |
| 81 | +var y0 = new Float64Array( [ 0.0, 1.0, 1.0 ] ); |
| 82 | +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 83 | + |
| 84 | +// Create offset views... |
| 85 | +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 86 | +var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 87 | + |
| 88 | +ggemv( 'row-major', 'no-transpose', 2, 2, 1.0, A, 2, x1, -1, 1.0, y1, -1 ); |
| 89 | +// y0 => <Float64Array>[ 0.0, 8.0, 4.0 ] |
| 90 | +``` |
| 91 | + |
| 92 | +#### ggemv.ndarray( trans, M, N, α, A, sa1, sa2, oa, x, sx, ox, β, y, sy, oy ) |
| 93 | + |
| 94 | +Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, using alternative indexing semantics and where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. |
| 95 | + |
| 96 | +```javascript |
| 97 | +var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; |
| 98 | +var x = [ 1.0, 1.0, 1.0 ]; |
| 99 | +var y = [ 1.0, 1.0 ]; |
| 100 | + |
| 101 | +ggemv.ndarray( 'no-transpose', 2, 3, 1.0, A, 3, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); |
| 102 | +// y => [ 7.0, 16.0 ] |
| 103 | +``` |
| 104 | + |
| 105 | +The function has the following additional parameters: |
| 106 | + |
| 107 | +- **sa1**: stride of the first dimension of `A`. |
| 108 | +- **sa2**: stride of the second dimension of `A`. |
| 109 | +- **oa**: starting index for `A`. |
| 110 | +- **ox**: starting index for `x`. |
| 111 | +- **oy**: starting index for `y`. |
| 112 | + |
| 113 | +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, |
| 114 | + |
| 115 | +```javascript |
| 116 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 117 | + |
| 118 | +var A = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; |
| 119 | +var x = [ 0.0, 1.0, 2.0, 3.0 ]; |
| 120 | +var y = [ 7.0, 8.0, 9.0, 10.0 ]; |
| 121 | + |
| 122 | +ggemv.ndarray( 'no-transpose', 2, 3, 1.0, A, 3, 1, 0, x, 1, 1, 1.0, y, -2, 2 ); |
| 123 | +// y => [ 39.0, 8.0, 23.0, 10.0 ] |
| 124 | +``` |
| 125 | + |
| 126 | +</section> |
| 127 | + |
| 128 | +<!-- /.usage --> |
| 129 | + |
| 130 | +<section class="notes"> |
| 131 | + |
| 132 | +## Notes |
| 133 | + |
| 134 | +- `ggemv()` corresponds to the [BLAS][blas] level 2 function [`dgemv`][dgemv] with the exception that this implementation works with any array type, not just Float64Arrays. Depending on the environment, the typed versions ([`dgemv`][@stdlib/blas/base/dgemv], [`sgemv`][@stdlib/blas/base/sgemv], etc.) are likely to be significantly more performant. |
| 135 | +- 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]). |
| 136 | + |
| 137 | +</section> |
| 138 | + |
| 139 | +<!-- /.notes --> |
| 140 | + |
| 141 | +<section class="examples"> |
| 142 | + |
| 143 | +## Examples |
| 144 | + |
| 145 | +<!-- eslint no-undef: "error" --> |
| 146 | + |
| 147 | +```javascript |
| 148 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 149 | +var ggemv = require( '@stdlib/blas/base/ggemv' ); |
| 150 | + |
| 151 | +var opts = { |
| 152 | + 'dtype': 'generic' |
| 153 | +}; |
| 154 | + |
| 155 | +var M = 3; |
| 156 | +var N = 3; |
| 157 | + |
| 158 | +var A = discreteUniform( M*N, 0, 255, opts ); |
| 159 | +var x = discreteUniform( N, 0, 255, opts ); |
| 160 | +var y = discreteUniform( M, 0, 255, opts ); |
| 161 | + |
| 162 | +ggemv( 'row-major', 'no-transpose', M, N, 1.0, A, N, x, 1, 1.0, y, 1 ); |
| 163 | +console.log( y ); |
| 164 | + |
| 165 | +ggemv.ndarray( 'no-transpose', M, N, 1.0, A, N, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); |
| 166 | +console.log( y ); |
| 167 | +``` |
| 168 | + |
| 169 | +</section> |
| 170 | + |
| 171 | +<!-- /.examples --> |
| 172 | + |
| 173 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 174 | + |
| 175 | +<section class="related"> |
| 176 | + |
| 177 | +</section> |
| 178 | + |
| 179 | +<!-- /.related --> |
| 180 | + |
| 181 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 182 | + |
| 183 | +<section class="links"> |
| 184 | + |
| 185 | +[blas]: http://www.netlib.org/blas |
| 186 | + |
| 187 | +[dgemv]: https://netlib.org/lapack/explore-html-3.6.1/d7/d15/group__double__blas__level2_gadd421a107a488d524859b4a64c1901a9.html |
| 188 | + |
| 189 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 190 | + |
| 191 | +[@stdlib/blas/base/dgemv]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/dgemv |
| 192 | + |
| 193 | +[@stdlib/blas/base/sgemv]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/sgemv |
| 194 | + |
| 195 | +[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor |
| 196 | + |
| 197 | +<!-- <related-links> --> |
| 198 | + |
| 199 | +<!-- </related-links> --> |
| 200 | + |
| 201 | +</section> |
| 202 | + |
| 203 | +<!-- /.links --> |
0 commit comments