Skip to content

Commit 08aa12a

Browse files
committed
bench: add benchmarks
--- 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: passed - 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 a870958 commit 08aa12a

File tree

4 files changed

+345
-0
lines changed

4 files changed

+345
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
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 iladlc = require( './../lib/iladlc.js' );
30+
31+
32+
// VARIABLES //
33+
34+
var LAYOUTS = [
35+
'row-major',
36+
'column-major'
37+
];
38+
39+
40+
// FUNCTIONS //
41+
42+
/**
43+
* Creates a benchmark function.
44+
*
45+
* @private
46+
* @param {string} order - storage layout
47+
* @param {PositiveInteger} N - number of elements along each dimension
48+
* @returns {Function} benchmark function
49+
*/
50+
function createBenchmark( order, N ) {
51+
var A;
52+
53+
A = discreteUniform( N*N, 0.0, 1.0, {
54+
'dtype': 'float64'
55+
});
56+
return benchmark;
57+
58+
/**
59+
* Benchmark function.
60+
*
61+
* @private
62+
* @param {Benchmark} b - benchmark instance
63+
*/
64+
function benchmark( b ) {
65+
var z;
66+
var i;
67+
68+
b.tic();
69+
for ( i = 0; i < b.iterations; i++ ) {
70+
z = iladlc( order, N, N, A, N );
71+
if ( isnan( z ) ) {
72+
b.fail( 'should not return NaN' );
73+
}
74+
}
75+
b.toc();
76+
if ( isnan( z ) ) {
77+
b.fail( 'should not return NaN' );
78+
}
79+
b.pass( 'benchmark finished' );
80+
b.end();
81+
}
82+
}
83+
84+
85+
// MAIN //
86+
87+
/**
88+
* Main execution sequence.
89+
*
90+
* @private
91+
*/
92+
function main() {
93+
var min;
94+
var max;
95+
var ord;
96+
var N;
97+
var f;
98+
var i;
99+
var k;
100+
101+
min = 1; // 10^min
102+
max = 6; // 10^max
103+
104+
for ( k = 0; k < LAYOUTS.length; k++ ) {
105+
ord = LAYOUTS[ k ];
106+
for ( i = min; i <= max; i++ ) {
107+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
108+
f = createBenchmark( ord, N );
109+
bench( pkg+'::square_matrix:order='+ord+',size='+(N*N), f );
110+
}
111+
}
112+
}
113+
114+
main();
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var pow = require( '@stdlib/math/base/special/pow' );
26+
var floor = require( '@stdlib/math/base/special/floor' );
27+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
28+
var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' );
29+
var pkg = require( './../package.json' ).name;
30+
var iladlc = require( './../lib/iladlc.js' );
31+
32+
33+
// VARIABLES //
34+
35+
var LAYOUTS = [
36+
'row-major',
37+
'column-major'
38+
];
39+
40+
41+
// FUNCTIONS //
42+
43+
/**
44+
* Creates a benchmark function.
45+
*
46+
* @private
47+
* @param {string} order - storage layout
48+
* @param {PositiveInteger} N - number of elements along each dimension
49+
* @returns {Function} benchmark function
50+
*/
51+
function createBenchmark( order, N ) {
52+
var A;
53+
54+
A = discreteUniform( N*N, 0.0, 1.0, {
55+
'dtype': 'float64'
56+
});
57+
return benchmark;
58+
59+
/**
60+
* Benchmark function.
61+
*
62+
* @private
63+
* @param {Benchmark} b - benchmark instance
64+
*/
65+
function benchmark( b ) {
66+
var sa1;
67+
var sa2;
68+
var z;
69+
var i;
70+
71+
if ( isColumnMajor( order ) ) {
72+
sa1 = 1;
73+
sa2 = N;
74+
} else { // order === 'row-major'
75+
sa1 = N;
76+
sa2 = 1;
77+
}
78+
79+
b.tic();
80+
for ( i = 0; i < b.iterations; i++ ) {
81+
z = iladlc( order, N, N, A, sa1, sa2, 0 );
82+
if ( isnan( z ) ) {
83+
b.fail( 'should not return NaN' );
84+
}
85+
}
86+
b.toc();
87+
if ( isnan( z ) ) {
88+
b.fail( 'should not return NaN' );
89+
}
90+
b.pass( 'benchmark finished' );
91+
b.end();
92+
}
93+
}
94+
95+
96+
// MAIN //
97+
98+
/**
99+
* Main execution sequence.
100+
*
101+
* @private
102+
*/
103+
function main() {
104+
var min;
105+
var max;
106+
var ord;
107+
var N;
108+
var f;
109+
var i;
110+
var k;
111+
112+
min = 1; // 10^min
113+
max = 6; // 10^max
114+
115+
for ( k = 0; k < LAYOUTS.length; k++ ) {
116+
ord = LAYOUTS[ k ];
117+
for ( i = min; i <= max; i++ ) {
118+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
119+
f = createBenchmark( ord, N );
120+
bench( pkg+'::square_matrix:order='+ord+',size='+(N*N), f );
121+
}
122+
}
123+
}
124+
125+
main();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
22+
var Float64Array = require( '@stdlib/array/float64' );
23+
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
24+
var iladlc = require( './../lib' );
25+
26+
var shape = [ 3, 3 ];
27+
var order = 'row-major';
28+
var strides = shape2strides( shape, order );
29+
30+
var A = new Float64Array( [ 1.0, 2.0, 0.0, 3.0, 4.0, 0.0, 5.0, 6.0, 0.0 ] );
31+
console.log( ndarray2array( A, shape, strides, 0, order ) );
32+
33+
var out = iladlc( order, shape[ 0 ], shape[ 1 ], A, strides[ 0 ] );
34+
console.log( out );
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"name": "@stdlib/lapack/base/iladlc",
3+
"version": "0.0.0",
4+
"description": "LAPACK routine to find the index of the last non zero column in a 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+
"iladlc",
58+
"last",
59+
"column",
60+
"index",
61+
"matrix",
62+
"auxilary",
63+
"linear",
64+
"algebra",
65+
"subroutines",
66+
"array",
67+
"ndarray",
68+
"float64",
69+
"double",
70+
"float64array"
71+
]
72+
}

0 commit comments

Comments
 (0)