Skip to content

Commit 3e68299

Browse files
committed
fix: update function return value and add docs and 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: passed - 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: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 0e0f694 commit 3e68299

File tree

10 files changed

+1254
-10
lines changed

10 files changed

+1254
-10
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) 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
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 dgtts2 = require( './../lib/ndarray.js' );
31+
32+
33+
// VARIABLES //
34+
35+
var LAYOUTS = [
36+
'row-major',
37+
'column-major'
38+
];
39+
var options = {
40+
'dtype': 'float64'
41+
};
42+
43+
44+
// FUNCTIONS //
45+
46+
/**
47+
* Creates a benchmark function.
48+
*
49+
* @private
50+
* @param {string} order - storage layout
51+
* @param {PositiveInteger} N - number of elements along each dimension
52+
* @param {PositiveInteger} nrhs - number of right hand sides
53+
* @returns {Function} benchmark function
54+
*/
55+
function createBenchmark( order, N, nrhs ) {
56+
var IPIV = discreteUniform( N, 0, N-1, {
57+
'dtype': 'int32'
58+
});
59+
var DU2 = uniform( N-2, 0.0, 100.0, options );
60+
var DL = uniform( N-1, 0.0, 100.0, options );
61+
var DU = uniform( N-1, 0.0, 100.0, options );
62+
var D = uniform( N, 0.0, 100.0, options );
63+
var B = uniform( N*nrhs, -10.0, 10.0, options);
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 X;
75+
var i;
76+
77+
b.tic();
78+
for ( i = 0; i < b.iterations; i++ ) {
79+
X = dgtts2( order, N, 1, nrhs, DL, D, DU, DU2, IPIV, B, N );
80+
if ( isnan( X[ i%X.length ] ) ) {
81+
b.fail( 'should not return NaN' );
82+
}
83+
}
84+
b.toc();
85+
if ( isnan( X[ i%X.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+',nrhs='+j+',size='+(N*N), f );
122+
j *= 2;
123+
}
124+
}
125+
}
126+
}
127+
128+
main();
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
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 dgtts2 = require( './../lib/dgtts2.js' );
31+
32+
33+
// VARIABLES //
34+
35+
var LAYOUTS = [
36+
'row-major',
37+
'column-major'
38+
];
39+
var options = {
40+
'dtype': 'float64'
41+
};
42+
43+
44+
// FUNCTIONS //
45+
46+
/**
47+
* Creates a benchmark function.
48+
*
49+
* @private
50+
* @param {string} order - storage layout
51+
* @param {PositiveInteger} N - number of elements along each dimension
52+
* @param {PositiveInteger} nrhs - number of right hand sides
53+
* @returns {Function} benchmark function
54+
*/
55+
function createBenchmark( order, N, nrhs ) {
56+
var IPIV = discreteUniform( N, 0, N-1, {
57+
'dtype': 'int32'
58+
});
59+
var DU2 = uniform( N-2, 0.0, 100.0, options );
60+
var DL = uniform( N-1, 0.0, 100.0, options );
61+
var DU = uniform( N-1, 0.0, 100.0, options );
62+
var D = uniform( N, 0.0, 100.0, options );
63+
var B = uniform( N*nrhs, -10.0, 10.0, options);
64+
return benchmark;
65+
66+
/**
67+
* Benchmark function.
68+
*
69+
* @private
70+
* @param {Benchmark} b - benchmark instance
71+
*/
72+
function benchmark( b ) {
73+
var X;
74+
var i;
75+
76+
b.tic();
77+
for ( i = 0; i < b.iterations; i++ ) {
78+
X = dgtts2( order, N, 0, nrhs, DL, 1, 0, D, 1, 0, DU, 1, 0, DU2, 1, 0, IPIV, 1, 0, B, N, nrhs, 0 ); // eslint-disable-line max-len
79+
if ( isnan( X[ i%X.length ] ) ) {
80+
b.fail( 'should not return NaN' );
81+
}
82+
}
83+
b.toc();
84+
if ( isnan( X[ i%X.length ] ) ) {
85+
b.fail( 'should not return NaN' );
86+
}
87+
b.pass( 'benchmark finished' );
88+
b.end();
89+
}
90+
}
91+
92+
93+
// MAIN //
94+
95+
/**
96+
* Main execution sequence.
97+
*
98+
* @private
99+
*/
100+
function main() {
101+
var min;
102+
var max;
103+
var ord;
104+
var N;
105+
var f;
106+
var i;
107+
var j;
108+
var k;
109+
110+
min = 1; // 10^min
111+
max = 6; // 10^max
112+
113+
for ( k = 0; k < LAYOUTS.length; k++ ) {
114+
ord = LAYOUTS[ k ];
115+
for ( i = min; i <= max; i++ ) {
116+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
117+
j = 1;
118+
while ( j <= N ) {
119+
f = createBenchmark( ord, N, j );
120+
bench( pkg+'::square_matrix:order='+ord+',nrhs='+j+',size='+(N*N), f );
121+
j *= 2;
122+
}
123+
}
124+
}
125+
}
126+
127+
main();

0 commit comments

Comments
 (0)