Skip to content

Commit f199be1

Browse files
committed
feat: add blas/base/ggemv
1 parent d8dd116 commit f199be1

File tree

13 files changed

+3326
-0
lines changed

13 files changed

+3326
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
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 ggemv = require( './../lib' );
30+
31+
32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float64'
36+
};
37+
38+
39+
// FUNCTIONS //
40+
41+
/**
42+
* Create a benchmark function.
43+
*
44+
* @private
45+
* @param {PositiveInteger} N - array length
46+
* @returns {Function} benchmark function
47+
*/
48+
function createBenchmark( N ) {
49+
var x = uniform( N, -10.0, 10.0, options );
50+
var y = uniform( N, -10.0, 10.0, options );
51+
var A = uniform( N*N, -10.0, 10.0, options );
52+
return benchmark;
53+
54+
function benchmark( b ) {
55+
var z;
56+
var i;
57+
58+
b.tic();
59+
for ( i = 0; i < b.iterations; i++ ) {
60+
z = ggemv( 'row-major', 'no-transpose', N, N, 1.0, A, N, x, 1, 1.0, y, 1 );
61+
if ( isnan( z[ i%z.length ] ) ) {
62+
b.fail( 'should not return NaN' );
63+
}
64+
}
65+
b.toc();
66+
if ( isnan( z[ i%z.length ] ) ) {
67+
b.fail( 'should not return NaN' );
68+
}
69+
b.pass( 'benchmark finished' );
70+
b.end();
71+
}
72+
}
73+
74+
75+
// MAIN //
76+
77+
function main() {
78+
var min;
79+
var max;
80+
var N;
81+
var f;
82+
var i;
83+
84+
min = 1; // 10^min
85+
max = 6; // 10^max
86+
87+
for ( i = min; i <= max; i++ ) {
88+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
89+
f = createBenchmark( N );
90+
bench( pkg+':size='+(N*N), f );
91+
}
92+
}
93+
94+
main();
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
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 ggemv = require( './../lib' ).ndarray;
30+
31+
32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float64'
36+
};
37+
38+
39+
// FUNCTIONS //
40+
41+
/**
42+
* Create a benchmark function.
43+
*
44+
* @private
45+
* @param {PositiveInteger} N - array dimension size
46+
* @returns {Function} benchmark function
47+
*/
48+
function createBenchmark( N ) {
49+
var x = uniform( N, -10.0, 10.0, options );
50+
var y = uniform( N, -10.0, 10.0, options );
51+
var A = uniform( N*N, -10.0, 10.0, options );
52+
return benchmark;
53+
54+
function benchmark( b ) {
55+
var z;
56+
var i;
57+
58+
b.tic();
59+
for ( i = 0; i < b.iterations; i++ ) {
60+
z = ggemv( 'no-transpose', N, N, 1.0, A, N, 1, 0, x, 1, 0, 1.0, y, 1, 0 );
61+
if ( isnan( z[ i%z.length ] ) ) {
62+
b.fail( 'should not return NaN' );
63+
}
64+
}
65+
b.toc();
66+
if ( isnan( z[ i%z.length ] ) ) {
67+
b.fail( 'should not return NaN' );
68+
}
69+
b.pass( 'benchmark finished' );
70+
b.end();
71+
}
72+
}
73+
74+
75+
// MAIN //
76+
77+
function main() {
78+
var min;
79+
var max;
80+
var N;
81+
var f;
82+
var i;
83+
84+
min = 1; // 10^min
85+
max = 6; // 10^max
86+
87+
for ( i = min; i <= max; i++ ) {
88+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
89+
f = createBenchmark( N );
90+
bench( pkg+':ndarray:size='+(N*N), f );
91+
}
92+
}
93+
94+
main();
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
2+
{{alias}}( order, trans, M, N, α, A, lda, x, sx, β, y, sy )
3+
Performs one of the matrix-vector operations `y = α*A*x + β*y` or
4+
`y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are
5+
vectors, and `A` is an `M` by `N` matrix.
6+
7+
Indexing is relative to the first index. To introduce an offset, use typed
8+
array views.
9+
10+
If `M` or `N` is equal to `0`, the function returns `y` unchanged.
11+
12+
If `α` equals `0` and `β` equals `1`, the function returns `y` unchanged.
13+
14+
Parameters
15+
----------
16+
order: string
17+
Row-major (C-style) or column-major (Fortran-style) order.
18+
19+
trans: string
20+
Specifies whether `A` should be transposed, conjugate-transposed, or not
21+
transposed.
22+
23+
M: integer
24+
Number of rows in `A`.
25+
26+
N: integer
27+
Number of columns in `A`.
28+
29+
α: number
30+
Scalar constant.
31+
32+
A: Array<number>|TypedArray
33+
Input matrix.
34+
35+
lda: integer
36+
Stride of the first dimension of `A` (a.k.a., leading dimension of the
37+
matrix `A`).
38+
39+
x: Array<number>|TypedArray
40+
First input vector.
41+
42+
sx: integer
43+
Stride length for `x`.
44+
45+
β: number
46+
Scalar constant.
47+
48+
y: Array<number>|TypedArray
49+
Second input vector.
50+
51+
sy: integer
52+
Stride length for `y`.
53+
54+
Returns
55+
-------
56+
y: Array<number>|TypedArray
57+
Second input vector.
58+
59+
Examples
60+
--------
61+
// Standard Usage:
62+
> var x = [ 1.0, 1.0 ];
63+
> var y = [ 1.0, 1.0 ];
64+
> var A = [ 1.0, 2.0, 3.0, 4.0 ];
65+
> var order = 'row-major';
66+
> var trans = 'no-transpose';
67+
> {{alias}}( order, trans, 2, 2, 1.0, A, 2, x, 1, 1.0, y, 1 )
68+
[ 4.0, 8.0 ]
69+
70+
// Advanced indexing:
71+
> x = [ 1.0, 1.0 ];
72+
> y = [ 1.0, 1.0 ];
73+
> A = [ 1.0, 2.0, 3.0, 4.0 ];
74+
> {{alias}}( order, trans, 2, 2, 1.0, A, 2, x, -1, 1.0, y, -1 )
75+
[ 8.0, 4.0 ]
76+
77+
// Using typed array views:
78+
> var x0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 1.0 ] );
79+
> var y0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 1.0 ] );
80+
> A = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
81+
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
82+
> var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*1 );
83+
> {{alias}}( order, trans, 2, 2, 1.0, A, 2, x1, -1, 1.0, y1, -1 )
84+
> y0
85+
[ 0.0, 8.0, 4.0 ]
86+
87+
88+
{{alias}}.ndarray( trans, M, N, α, A, sa1, sa2, oa, x, sx, ox, β, y, sy, oy )
89+
Performs one of the matrix-vector operations `y = α*A*x + β*y` or
90+
`y = α*A^T*x + β*y`, using alternative indexing semantics and where `α` and
91+
`β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix.
92+
93+
While typed array views mandate a view offset based on the underlying
94+
buffer, the offset parameters support indexing semantics based on starting
95+
indices.
96+
97+
Parameters
98+
----------
99+
trans: string
100+
Specifies whether `A` should be transposed, conjugate-transposed, or not
101+
transposed.
102+
103+
M: integer
104+
Number of rows in `A`.
105+
106+
N: integer
107+
Number of columns in `A`.
108+
109+
α: number
110+
Scalar constant.
111+
112+
A: Array<number>|TypedArray
113+
Input matrix.
114+
115+
sa1: integer
116+
Stride of the first dimension of `A`.
117+
118+
sa2: integer
119+
Stride of the second dimension of `A`.
120+
121+
oa: integer
122+
Starting index for `A`.
123+
124+
x: Array<number>|TypedArray
125+
First input vector.
126+
127+
sx: integer
128+
Stride length for `x`.
129+
130+
ox: integer
131+
Starting index for `x`.
132+
133+
β: number
134+
Scalar constant.
135+
136+
y: Array<number>|TypedArray
137+
Second input vector.
138+
139+
sy: integer
140+
Stride length for `y`.
141+
142+
oy: integer
143+
Starting index for `y`.
144+
145+
Returns
146+
-------
147+
y: Array<number>|TypedArray
148+
Second input vector.
149+
150+
Examples
151+
--------
152+
> var x = [ 1.0, 1.0 ];
153+
> var y = [ 1.0, 1.0 ];
154+
> var A = [ 1.0, 2.0, 3.0, 4.0 ];
155+
> var trans = 'no-transpose';
156+
> {{alias}}.ndarray( trans, 2, 2, 1, A, 2, 1, 0, x, 1, 0, 1, y, 1, 0 )
157+
[ 4.0, 8.0 ]
158+
159+
See Also
160+
--------

0 commit comments

Comments
 (0)