Skip to content

Commit 123d084

Browse files
Shabareesh ShettyShabareesh Shetty
authored andcommitted
chore: add complete implementation
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent f199be1 commit 123d084

36 files changed

+3146
-61
lines changed
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
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**: an `M` element input array.
56+
- **sx**: stride length for `x`.
57+
- **β**: scalar constant.
58+
- **y**: an `N` element input array.
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 [`ggemv`][ggemv] with the exception that this implementation works with any array type, not just Float64Arrays. Depending on the environment, the typed versions ([`ggemv`][@stdlib/blas/base/ggemv], [`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+
[ggemv]: 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/ggemv]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/ggemv
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 -->

lib/node_modules/@stdlib/blas/base/ggemv/lib/accessors.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
// MODULES //
2222

2323
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' );
24+
var dfill = require( '@stdlib/blas/ext/base/dfill' ).ndarray;
25+
var dscal = require( '@stdlib/blas/base/dscal' ).ndarray;
2426

2527

2628
// FUNCTIONS //
@@ -89,9 +91,9 @@ function isTransposed( str ) { // TODO: consider moving to a separate helper uti
8991
* ggemv( 'no-transpose', 2, 3, 1.0, arraylike2object( toAccessorArray( A ) ), 3, 1, 0, arraylike2object( toAccessorArray( x ) ), 1, 0, 1.0, arraylike2object( toAccessorArray( y ) ), 1, 0 );
9092
* // y => [ 7.0, 16.0 ]
9193
*/
92-
function ggemv( M, N, alpha, x, strideX, offsetX, y, strideY, offsetY, A, strideA1, strideA2, offsetA ) { // eslint-disable-line max-params, max-len
93-
var isrm;
94-
var getX;
94+
function ggemv( trans, M, N, alpha, A, strideA1, strideA2, offsetA, x, strideX, offsetX, beta, y, strideY, offsetY ) { // eslint-disable-line max-params, max-len
95+
var isrm;
96+
var getX;
9597
var getY;
9698
var getA;
9799
var setY;
@@ -108,9 +110,9 @@ function ggemv( M, N, alpha, x, strideX, offsetX, y, strideY, offsetY, A, stride
108110
var ia;
109111
var i1;
110112
var i0;
111-
var v;
113+
var v;
112114

113-
// Cache references to array data:
115+
// Cache references to array data:
114116
xbuf = x.data;
115117
ybuf = y.data;
116118
Abuf = A.data;
@@ -163,8 +165,8 @@ function ggemv( M, N, alpha, x, strideX, offsetX, y, strideY, offsetY, A, stride
163165
} else {
164166
iy = offsetY;
165167
for ( i0 = 0; i0 < ylen; i0++ ) {
166-
v = getA( Abuf, ia ) * tmp;
167-
setY( ybuf, iy, getY( ybuf, iy ) + v );
168+
v = getA( Abuf, ia ) * tmp;
169+
setY( ybuf, iy, getY( ybuf, iy ) + v );
168170
iy += strideY;
169171
ia += da0;
170172
}

lib/node_modules/@stdlib/blas/base/ggemv/lib/base.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,17 @@ function ggemv( trans, M, N, alpha, A, strideA1, strideA2, offsetA, x, strideX,
9696
var ia;
9797
var i1;
9898
var i0;
99-
var oa;
100-
var ox;
101-
var oy;
99+
var oa;
100+
var ox;
101+
var oy;
102102

103103
// Note on variable naming convention: da#, i# where # corresponds to the loop number, with `0` being the innermost loop...
104104

105-
ox = arraylike2object( x );
105+
ox = arraylike2object( x );
106106
oy = arraylike2object( y );
107107
oa = arraylike2object( A );
108108
if ( ox.accessorProtocol || oy.accessorProtocol || oa.accessorProtocol ) {
109-
accessors( M, N, alpha, ox, strideX, offsetX, oy, strideY, offsetY, oa, strideA1, strideA2, offsetA );
109+
accessors( trans, M, N, alpha, oa, strideA1, strideA2, offsetA, ox, strideX, offsetX, beta, oy, strideY, offsetY );
110110
return y;
111111
}
112112
isrm = isRowMajor( [ strideA1, strideA2 ] );
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"name": "@stdlib/blas/base/ggemv",
3+
"version": "0.0.0",
4+
"description": "Perform one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A**T*x + β*y`.",
5+
"license": "Apache-2.0",
6+
"author": {
7+
"name": "The Stdlib Authors",
8+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9+
},
10+
"contributors": [
11+
{
12+
"name": "The Stdlib Authors",
13+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14+
}
15+
],
16+
"main": "./lib",
17+
"directories": {
18+
"benchmark": "./benchmark",
19+
"doc": "./docs",
20+
"example": "./examples",
21+
"lib": "./lib",
22+
"test": "./test"
23+
},
24+
"types": "./docs/types",
25+
"scripts": {},
26+
"homepage": "https://github.com/stdlib-js/stdlib",
27+
"repository": {
28+
"type": "git",
29+
"url": "git://github.com/stdlib-js/stdlib.git"
30+
},
31+
"bugs": {
32+
"url": "https://github.com/stdlib-js/stdlib/issues"
33+
},
34+
"dependencies": {},
35+
"devDependencies": {},
36+
"engines": {
37+
"node": ">=0.10.0",
38+
"npm": ">2.7.0"
39+
},
40+
"os": [
41+
"aix",
42+
"darwin",
43+
"freebsd",
44+
"linux",
45+
"macos",
46+
"openbsd",
47+
"sunos",
48+
"win32",
49+
"windows"
50+
],
51+
"keywords": [
52+
"stdlib",
53+
"stdmath",
54+
"mathematics",
55+
"math",
56+
"blas",
57+
"level 2",
58+
"ggemv",
59+
"linear",
60+
"algebra",
61+
"subroutines",
62+
"array",
63+
"ndarray"
64+
]
65+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"order": "column-major",
3+
"trans": "no-transpose",
4+
"M": 4,
5+
"N": 2,
6+
"alpha": 0.0,
7+
"A": [ 1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0 ],
8+
"A_mat": [
9+
[ 1.0, 2.0 ],
10+
[ 3.0, 4.0 ],
11+
[ 5.0, 6.0 ],
12+
[ 7.0, 8.0 ]
13+
],
14+
"lda": 4,
15+
"strideA1": 1,
16+
"strideA2": 4,
17+
"offsetA": 0,
18+
"x": [ 1.0, 2.0 ],
19+
"strideX": 1,
20+
"offsetX": 0,
21+
"beta": 0.5,
22+
"y": [ 1.0, 2.0, 3.0, 4.0 ],
23+
"strideY": 1,
24+
"offsetY": 0,
25+
"y_out": [ 0.5, 1.0, 1.5, 2.0 ]
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"order": "column-major",
3+
"trans": "no-transpose",
4+
"M": 4,
5+
"N": 2,
6+
"alpha": 0.5,
7+
"A": [ 999.0, 1.0, 999.0, 3.0, 999.0, 5.0, 999.0, 7.0, 999.0, 2.0, 999.0, 4.0, 999.0, 6.0, 999.0, 8.0 ],
8+
"A_mat": [
9+
[ 1.0, 2.0 ],
10+
[ 3.0, 4.0 ],
11+
[ 5.0, 6.0 ],
12+
[ 7.0, 8.0 ]
13+
],
14+
"lda": 8,
15+
"strideA1": 2,
16+
"strideA2": 8,
17+
"offsetA": 1,
18+
"x": [ 3.0, 2.0, 1.0 ],
19+
"strideX": -1,
20+
"offsetX": 2,
21+
"beta": 0.5,
22+
"y": [ 1.0, 2.0, 3.0 ],
23+
"strideY": -1,
24+
"offsetY": 2,
25+
"y_out": [ 16.0, 6.0, 2.0 ]
26+
}

0 commit comments

Comments
 (0)