Skip to content

Commit 9158c95

Browse files
Shabareesh ShettyShabareesh Shetty
authored andcommitted
feat: add blas/base/zgemv
1 parent 0283804 commit 9158c95

File tree

7 files changed

+1388
-0
lines changed

7 files changed

+1388
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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 Complex128Array = require( '@stdlib/array/complex128' );
28+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
29+
var pkg = require( './../package.json' ).name;
30+
var zgemv = require( './../lib/zgemv.js' );
31+
32+
33+
// VARIABLES //
34+
35+
var options = {
36+
'dtype': 'float64'
37+
};
38+
39+
40+
// FUNCTIONS //
41+
42+
/**
43+
* Creates a benchmark function.
44+
*
45+
* @private
46+
* @param {PositiveInteger} N - array dimension size
47+
* @returns {Function} benchmark function
48+
*/
49+
function createBenchmark( N ) {
50+
var alpha;
51+
var beta;
52+
var xbuf;
53+
var ybuf;
54+
var Abuf;
55+
var x;
56+
var y;
57+
var A;
58+
59+
xbuf = uniform( N*2, -100.0, 100.0, options );
60+
x = new Complex128Array( xbuf.buffer );
61+
ybuf = uniform( N*2, -100.0, 100.0, options );
62+
y = new Complex128Array( ybuf.buffer );
63+
Abuf = uniform( (N*N)*2, -100.0, 100.0, options );
64+
A = new Complex128Array( Abuf.buffer );
65+
66+
alpha = new Complex128( 1.0, 0.0 );
67+
beta = new Complex128( 1.0, 0.0 );
68+
69+
return benchmark;
70+
71+
/**
72+
* Benchmark function.
73+
*
74+
* @private
75+
* @param {Benchmark} b - benchmark instance
76+
*/
77+
function benchmark( b ) {
78+
var i;
79+
80+
b.tic();
81+
for ( i = 0; i < b.iterations; i++ ) {
82+
zgemv( 'row-major', 'no-transpose', N, N, alpha, A, N, x, 1, beta, y, 1 );
83+
if ( isnan( ybuf[ i%N ] ) ) {
84+
b.fail( 'should not return NaN' );
85+
}
86+
}
87+
b.toc();
88+
if ( isnan( ybuf[ i%N ] ) ) {
89+
b.fail( 'should not return NaN' );
90+
}
91+
b.pass( 'benchmark finished' );
92+
b.end();
93+
}
94+
}
95+
96+
97+
// MAIN //
98+
99+
/**
100+
* Main execution sequence.
101+
*
102+
* @private
103+
*/
104+
function main() {
105+
var min;
106+
var max;
107+
var N;
108+
var f;
109+
var i;
110+
111+
min = 1; // 10^min
112+
max = 6; // 10^max
113+
114+
for ( i = min; i <= max; i++ ) {
115+
N = pow( 10, i );
116+
f = createBenchmark( N );
117+
bench( pkg+':size='+N, f );
118+
}
119+
}
120+
121+
main();
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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 Complex128Array = require( '@stdlib/array/complex128' );
28+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
29+
var pkg = require( './../package.json' ).name;
30+
var zgemv = require( './../lib/ndarray.js' );
31+
32+
33+
// VARIABLES //
34+
35+
var options = {
36+
'dtype': 'float64'
37+
};
38+
39+
40+
// FUNCTIONS //
41+
42+
/**
43+
* Creates a benchmark function.
44+
*
45+
* @private
46+
* @param {PositiveInteger} N - array dimension size
47+
* @returns {Function} benchmark function
48+
*/
49+
function createBenchmark( N ) {
50+
var alpha;
51+
var beta;
52+
var xbuf;
53+
var ybuf;
54+
var Abuf;
55+
var x;
56+
var y;
57+
var A;
58+
59+
xbuf = uniform( N*2, -100.0, 100.0, options );
60+
x = new Complex128Array( xbuf.buffer );
61+
ybuf = uniform( N*2, -100.0, 100.0, options );
62+
y = new Complex128Array( ybuf.buffer );
63+
Abuf = uniform( (N*N)*2, -100.0, 100.0, options );
64+
A = new Complex128Array( Abuf.buffer );
65+
66+
alpha = new Complex128( 1.0, 0.0 );
67+
beta = new Complex128( 0.0, 0.0 );
68+
69+
return benchmark;
70+
71+
/**
72+
* Benchmark function.
73+
*
74+
* @private
75+
* @param {Benchmark} b - benchmark instance
76+
*/
77+
function benchmark( b ) {
78+
var i;
79+
80+
b.tic();
81+
for ( i = 0; i < b.iterations; i++ ) {
82+
zgemv( 'row-major', 'no-transpose', N, N, alpha, A, N, 1, 0, x, 1, 0, beta, y, 1, 0 );
83+
if ( isnan( ybuf[ i%N ] ) ) {
84+
b.fail( 'should not return NaN' );
85+
}
86+
}
87+
b.toc();
88+
if ( isnan( ybuf[ i%N ] ) ) {
89+
b.fail( 'should not return NaN' );
90+
}
91+
b.pass( 'benchmark finished' );
92+
b.end();
93+
}
94+
}
95+
96+
97+
// MAIN //
98+
99+
/**
100+
* Main execution sequence.
101+
*
102+
* @private
103+
*/
104+
function main() {
105+
var min;
106+
var max;
107+
var N;
108+
var f;
109+
var i;
110+
111+
min = 1; // 10^min
112+
max = 6; // 10^max
113+
114+
for ( i = min; i <= max; i++ ) {
115+
N = pow( 10, i );
116+
f = createBenchmark( N );
117+
bench( pkg+':ndarray:size='+N, f );
118+
}
119+
}
120+
121+
main();

0 commit comments

Comments
 (0)