Skip to content

Commit 2ca9245

Browse files
committed
bench: add benchmarks and cleanup
--- 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: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - 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 099194a commit 2ca9245

File tree

8 files changed

+376
-29
lines changed

8 files changed

+376
-29
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 Float64Array = require( '@stdlib/array/float64' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var pow = require( '@stdlib/math/base/special/pow' );
28+
var floor = require( '@stdlib/math/base/special/floor' );
29+
var pkg = require( './../package.json' ).name;
30+
var dgebal = require( './../lib/dgebal.js' );
31+
32+
33+
// VARIABLES //
34+
35+
var LAYOUTS = [
36+
'row-major',
37+
'column-major'
38+
];
39+
var JOBS = [
40+
'permute',
41+
'scale',
42+
'both',
43+
'none'
44+
];
45+
46+
47+
// FUNCTIONS //
48+
49+
/**
50+
* Creates a benchmark function.
51+
*
52+
* @private
53+
* @param {string} order - storage layout
54+
* @param {PositiveInteger} N - number of elements along each dimension
55+
* @param {string} job - indicates the operations to be performed
56+
* @returns {Function} benchmark function
57+
*/
58+
function createBenchmark( order, N, job ) {
59+
var scale;
60+
var out;
61+
var A;
62+
63+
scale = new Float64Array( N );
64+
out = new Float64Array( 2 );
65+
66+
A = uniform( N*N, -10.0, 10.0, {
67+
'dtype': 'float64'
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 z;
79+
var i;
80+
81+
b.tic();
82+
for ( i = 0; i < b.iterations; i++ ) {
83+
z = dgebal( order, job, N, A, N, out, scale );
84+
if ( isnan( z ) ) {
85+
b.fail( 'should not return NaN' );
86+
}
87+
}
88+
b.toc();
89+
if ( isnan( z ) ) {
90+
b.fail( 'should not return NaN' );
91+
}
92+
b.pass( 'benchmark finished' );
93+
b.end();
94+
}
95+
}
96+
97+
98+
// MAIN //
99+
100+
/**
101+
* Main execution sequence.
102+
*
103+
* @private
104+
*/
105+
function main() {
106+
var min;
107+
var max;
108+
var ord;
109+
var job;
110+
var N;
111+
var f;
112+
var i;
113+
var j;
114+
var k;
115+
116+
min = 1; // 10^min
117+
max = 6; // 10^max
118+
119+
for ( k = 0; k < LAYOUTS.length; k++ ) {
120+
ord = LAYOUTS[ k ];
121+
for ( i = min; i <= max; i++ ) {
122+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
123+
for ( j = 0; j < JOBS.length; j++ ) {
124+
job = JOBS[ j ];
125+
f = createBenchmark( ord, N, job );
126+
bench( pkg+'::square_matrix:order='+ord+',job='+job+',size='+(N*N), f );
127+
}
128+
}
129+
}
130+
}
131+
132+
main();
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 Float64Array = require( '@stdlib/array/float64' );
26+
var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' );
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 dgebal = require( './../lib/ndarray.js' );
32+
33+
34+
// VARIABLES //
35+
36+
var LAYOUTS = [
37+
'row-major',
38+
'column-major'
39+
];
40+
var JOBS = [
41+
'permute',
42+
'scale',
43+
'both',
44+
'none'
45+
];
46+
47+
48+
// FUNCTIONS //
49+
50+
/**
51+
* Creates a benchmark function.
52+
*
53+
* @private
54+
* @param {string} order - storage layout
55+
* @param {PositiveInteger} N - number of elements along each dimension
56+
* @param {string} job - indicates the operations to be performed
57+
* @returns {Function} benchmark function
58+
*/
59+
function createBenchmark( order, N, job ) {
60+
var scale;
61+
var out;
62+
var sa1;
63+
var sa2;
64+
var A;
65+
66+
scale = new Float64Array( N );
67+
out = new Float64Array( 2 );
68+
69+
A = uniform( N*N, -10.0, 10.0, {
70+
'dtype': 'float64'
71+
});
72+
73+
if ( isColumnMajor( order ) ) {
74+
sa1 = 1;
75+
sa2 = N;
76+
} else {
77+
sa1 = N;
78+
sa2 = 1;
79+
}
80+
81+
return benchmark;
82+
83+
/**
84+
* Benchmark function.
85+
*
86+
* @private
87+
* @param {Benchmark} b - benchmark instance
88+
*/
89+
function benchmark( b ) {
90+
var z;
91+
var i;
92+
93+
b.tic();
94+
for ( i = 0; i < b.iterations; i++ ) {
95+
z = dgebal( job, N, A, sa1, sa2, 0, out, 1, 0, scale, 1, 0 );
96+
if ( isnan( z ) ) {
97+
b.fail( 'should not return NaN' );
98+
}
99+
}
100+
b.toc();
101+
if ( isnan( z ) ) {
102+
b.fail( 'should not return NaN' );
103+
}
104+
b.pass( 'benchmark finished' );
105+
b.end();
106+
}
107+
}
108+
109+
110+
// MAIN //
111+
112+
/**
113+
* Main execution sequence.
114+
*
115+
* @private
116+
*/
117+
function main() {
118+
var min;
119+
var max;
120+
var ord;
121+
var job;
122+
var N;
123+
var f;
124+
var i;
125+
var j;
126+
var k;
127+
128+
min = 1; // 10^min
129+
max = 6; // 10^max
130+
131+
for ( k = 0; k < LAYOUTS.length; k++ ) {
132+
ord = LAYOUTS[ k ];
133+
for ( i = min; i <= max; i++ ) {
134+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
135+
for ( j = 0; j < JOBS.length; j++ ) {
136+
job = JOBS[ j ];
137+
f = createBenchmark( ord, N, job );
138+
bench( pkg+'::square_matrix:order='+ord+',job='+job+',size='+(N*N), f );
139+
}
140+
}
141+
}
142+
}
143+
144+
main();

lib/node_modules/@stdlib/lapack/base/dgebal/lib/base.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var dscal = require( '@stdlib/blas/base/dscal' ).ndarray;
4343
* The job parameter can be one of the following:
4444
*
4545
* - 'none': none, return immediately
46-
* - 'permutate': permute only
46+
* - 'permute': permute only
4747
* - 'scale': scale only
4848
* - 'both': both permute and scale
4949
*
@@ -193,7 +193,7 @@ function dgebal( job, N, A, strideA1, strideA2, offsetA, out, strideOut, offsetO
193193
is += strideScale;
194194
}
195195

196-
if ( job === 'permutate' ) {
196+
if ( job === 'permute' ) {
197197
out[ offsetOut ] = k; // ilo
198198
out[ offsetOut + strideOut ] = l; // ihi
199199
return 0;

lib/node_modules/@stdlib/lapack/base/dgebal/lib/dgebal.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var base = require( './base.js' );
3636
* The job parameter can be one of the following:
3737
*
3838
* - 'none': none, return immediately
39-
* - 'permutate': permute only
39+
* - 'permute': permute only
4040
* - 'scale': scale only
4141
* - 'both': both permute and scale
4242
* - The matrix `A` is overwritten by the balanced matrix.
@@ -73,8 +73,8 @@ function dgebal( order, job, N, A, LDA, out, scale ) {
7373
if ( !isLayout( order ) ) {
7474
throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) );
7575
}
76-
if ( job !== 'both' && job !== 'scale' && job !== 'permutate' && job !== 'none' ) {
77-
throw new TypeError( format( 'invalid argument. Second argument must be one of the following: `both`, `scale`, `permutate`, or `none`. Value: `%s`.', job ) );
76+
if ( job !== 'both' && job !== 'scale' && job !== 'permute' && job !== 'none' ) {
77+
throw new TypeError( format( 'invalid argument. Second argument must be one of the following: `both`, `scale`, `permute`, or `none`. Value: `%s`.', job ) );
7878
}
7979
if ( isColumnMajor( order ) ) {
8080
sa1 = 1;

lib/node_modules/@stdlib/lapack/base/dgebal/lib/ndarray.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var base = require( './base.js' );
3434
* The job parameter can be one of the following:
3535
*
3636
* - 'none': none, return immediately
37-
* - 'permutate': permute only
37+
* - 'permute': permute only
3838
* - 'scale': scale only
3939
* - 'both': both permute and scale
4040
* - The matrix `A` is overwritten by the balanced matrix.
@@ -68,8 +68,8 @@ var base = require( './base.js' );
6868
* // scale => <Float64Array>[ 8, 1, 2 ]
6969
*/
7070
function dgebal( job, N, A, strideA1, strideA2, offsetA, out, strideOut, offsetOut, scale, strideScale, offsetScale ) { // eslint-disable-line max-len, max-params
71-
if ( job !== 'both' && job !== 'scale' && job !== 'permutate' && job !== 'none' ) {
72-
throw new TypeError( format( 'invalid argument. Second argument must be one of the following: `both`, `scale`, `permutate`, or `none`. Value: `%s`.', job ) );
71+
if ( job !== 'both' && job !== 'scale' && job !== 'permute' && job !== 'none' ) {
72+
throw new TypeError( format( 'invalid argument. Second argument must be one of the following: `both`, `scale`, `permute`, or `none`. Value: `%s`.', job ) );
7373
}
7474
return base( job, N, A, strideA1, strideA2, offsetA, out, strideOut, offsetOut, scale, strideScale, offsetScale ); // eslint-disable-line max-len
7575
}

0 commit comments

Comments
 (0)