Skip to content

Commit 8e261b4

Browse files
committed
bench: add benchmarks for zlaswp
--- 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: na - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - 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 97058f9 commit 8e261b4

File tree

3 files changed

+337
-0
lines changed

3 files changed

+337
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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 Complex128Array = require( '@stdlib/array/complex128' );
26+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
27+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
28+
var pow = require( '@stdlib/math/base/special/pow' );
29+
var floor = require( '@stdlib/math/base/special/floor' );
30+
var pkg = require( './../package.json' ).name;
31+
var zlaswp = require( './../lib/zlaswp.js' );
32+
33+
34+
// VARIABLES //
35+
36+
var LAYOUTS = [
37+
'row-major',
38+
'column-major'
39+
];
40+
var opts = {
41+
'dtype': 'float64'
42+
};
43+
44+
45+
// FUNCTIONS //
46+
47+
/**
48+
* Creates a benchmark function.
49+
*
50+
* @private
51+
* @param {string} order - storage layout
52+
* @param {PositiveInteger} N - number of elements along each dimension
53+
* @param {PositiveInteger} nrows - number of rows to interchange
54+
* @returns {Function} benchmark function
55+
*/
56+
function createBenchmark( order, N, nrows ) {
57+
var IPIV;
58+
var A;
59+
60+
IPIV = discreteUniform( nrows, 0, N-1, {
61+
'dtype': 'int32'
62+
});
63+
A = new Complex128Array( uniform( 2*N*N, -10.0, 10.0, opts ) );
64+
65+
return benchmark;
66+
67+
/**
68+
* Benchmark function.
69+
*
70+
* @private
71+
* @param {Benchmark} b - benchmark instance
72+
*/
73+
function benchmark( b ) {
74+
var z;
75+
var i;
76+
77+
b.tic();
78+
for ( i = 0; i < b.iterations; i++ ) {
79+
z = zlaswp( order, N, A, N, 0, nrows-1, IPIV, 1 );
80+
if ( isnan( z[ i%z.length ] ) ) {
81+
b.fail( 'should not return NaN' );
82+
}
83+
}
84+
b.toc();
85+
if ( isnan( z[ i%z.length ] ) ) {
86+
b.fail( 'should not return NaN' );
87+
}
88+
b.pass( 'benchmark finished' );
89+
b.end();
90+
}
91+
}
92+
93+
94+
// MAIN //
95+
96+
/**
97+
* Main execution sequence.
98+
*
99+
* @private
100+
*/
101+
function main() {
102+
var min;
103+
var max;
104+
var ord;
105+
var N;
106+
var f;
107+
var i;
108+
var j;
109+
var k;
110+
111+
min = 1; // 10^min
112+
max = 6; // 10^max
113+
114+
for ( k = 0; k < LAYOUTS.length; k++ ) {
115+
ord = LAYOUTS[ k ];
116+
for ( i = min; i <= max; i++ ) {
117+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
118+
j = 1;
119+
while ( j <= N ) {
120+
f = createBenchmark( ord, N, j );
121+
bench( pkg+'::square_matrix:order='+ord+',nrows='+j+',size='+(N*N), f );
122+
j *= 2;
123+
}
124+
}
125+
}
126+
}
127+
128+
main();
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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 Complex128Array = require( '@stdlib/array/complex128' );
26+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
27+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
28+
var pow = require( '@stdlib/math/base/special/pow' );
29+
var floor = require( '@stdlib/math/base/special/floor' );
30+
var pkg = require( './../package.json' ).name;
31+
var dlaswp = require( './../lib/ndarray.js' );
32+
33+
34+
// VARIABLES //
35+
36+
var LAYOUTS = [
37+
'row-major',
38+
'column-major'
39+
];
40+
var opts = {
41+
'dtype': 'float64'
42+
};
43+
44+
45+
// FUNCTIONS //
46+
47+
/**
48+
* Creates a benchmark function.
49+
*
50+
* @private
51+
* @param {string} order - storage layout
52+
* @param {PositiveInteger} N - number of elements along each dimension
53+
* @param {PositiveInteger} nrows - number of rows to interchange
54+
* @returns {Function} benchmark function
55+
*/
56+
function createBenchmark( order, N, nrows ) {
57+
var IPIV;
58+
var sa1;
59+
var sa2;
60+
var A;
61+
62+
if ( order === 'column-major' ) {
63+
sa1 = 1;
64+
sa2 = N;
65+
} else { // order === 'row-major'
66+
sa1 = N;
67+
sa2 = 1;
68+
}
69+
IPIV = discreteUniform( nrows, 0, N-1, {
70+
'dtype': 'int32'
71+
});
72+
A = new Complex128Array( uniform( 2*N*N, -10.0, 10.0, opts ) );
73+
74+
return benchmark;
75+
76+
/**
77+
* Benchmark function.
78+
*
79+
* @private
80+
* @param {Benchmark} b - benchmark instance
81+
*/
82+
function benchmark( b ) {
83+
var z;
84+
var i;
85+
86+
b.tic();
87+
for ( i = 0; i < b.iterations; i++ ) {
88+
z = dlaswp( N, A, sa1, sa2, 0, 0, nrows-1, 1, IPIV, 1, 0 );
89+
if ( isnan( z[ i%z.length ] ) ) {
90+
b.fail( 'should not return NaN' );
91+
}
92+
}
93+
b.toc();
94+
if ( isnan( z[ i%z.length ] ) ) {
95+
b.fail( 'should not return NaN' );
96+
}
97+
b.pass( 'benchmark finished' );
98+
b.end();
99+
}
100+
}
101+
102+
103+
// MAIN //
104+
105+
/**
106+
* Main execution sequence.
107+
*
108+
* @private
109+
*/
110+
function main() {
111+
var min;
112+
var max;
113+
var ord;
114+
var N;
115+
var f;
116+
var i;
117+
var j;
118+
var k;
119+
120+
min = 1; // 10^min
121+
max = 6; // 10^max
122+
123+
for ( k = 0; k < LAYOUTS.length; k++ ) {
124+
ord = LAYOUTS[ k ];
125+
for ( i = min; i <= max; i++ ) {
126+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
127+
j = 1;
128+
while ( j <= N ) {
129+
f = createBenchmark( ord, N, j );
130+
bench( pkg+'::square_matrix:ndarray:order='+ord+',nrows='+j+',size='+(N*N), f );
131+
j *= 2;
132+
}
133+
}
134+
}
135+
}
136+
137+
main();
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"name": "@stdlib/lapack/base/zlaswp",
3+
"version": "0.0.0",
4+
"description": "Perform a series of row interchanges on an input matrix.",
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+
"lapack",
57+
"dlaswp",
58+
"interchange",
59+
"swap",
60+
"exchange",
61+
"permute",
62+
"permutedims",
63+
"linear",
64+
"algebra",
65+
"subroutines",
66+
"array",
67+
"ndarray",
68+
"float64",
69+
"double",
70+
"float64array"
71+
]
72+
}

0 commit comments

Comments
 (0)