Skip to content
145 changes: 145 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dorm2r/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var zeros = require( '@stdlib/array/zeros' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var Float64Array = require( '@stdlib/array/float64' );
var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var dorm2r = require( './../lib/dorm2r.js' );


// VARIABLES //

var LAYOUTS = [
'row-major',
'column-major'
];
var SIDES = [
'left',
'right'
];
var TRANS = [
'no-transpose',
'transpose'
];


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {string} order - storage layout
* @param {string} side - specifies the side of multiplication
* @param {string} trans - specifies the operation to be performed
* @param {PositiveInteger} N - number of rows/columns in matrix C
* @returns {Function} benchmark function
*/
function createBenchmark( order, side, trans, N ) {
var opts;
var work;
var tau;
var A;
var C;

opts = {
'dtype': 'float64'
};

A = zeros( N*N, 'float64' );
C = uniform( N*N, -10.0, 10.0, opts );
tau = uniform( N, 0.0, 2.0, opts );
work = new Float64Array( N );

return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var z;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = dorm2r( order, side, trans, N, N, N, A, N, tau, C, N, work );
if ( isnan( z[ i%z.length ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( z[ i%z.length ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var trans;
var side;
var ord;
var min;
var max;
var N;
var f;
var i;
var j;
var k;

min = 1; // 10^min
max = 3; // 10^max

for ( i = 0; i < LAYOUTS.length; i++ ) {
ord = LAYOUTS[ i ];
for ( j = 0; j < SIDES.length; j++ ) {
side = SIDES[ j ];
for ( k = 0; k < TRANS.length; k++ ) {
trans = TRANS[ k ];
for ( N = min; N <= max; N++ ) {
f = createBenchmark( ord, side, trans, floor( pow( pow( 10, N ), 1.0/2.0 ) ) );
bench( format( '%s:order=%s,side=%s,trans=%s,size=%d', pkg, ord, side, trans, N*N ), f );
}
}
}
}
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var zeros = require( '@stdlib/array/zeros' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var Float64Array = require( '@stdlib/array/float64' );
var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var dorm2r = require( './../lib/ndarray.js' );


// VARIABLES //

var SIDES = [
'left',
'right'
];
var TRANS = [
'no-transpose',
'transpose'
];


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {string} side - specifies the side of multiplication
* @param {string} trans - specifies the operation to be performed
* @param {PositiveInteger} N - number of rows/columns in matrix C
* @returns {Function} benchmark function
*/
function createBenchmark( side, trans, N ) {
var opts;
var work;
var tau;
var A;
var C;

opts = {
'dtype': 'float64'
};

A = zeros( N*N, 'float64' );
C = uniform( N*N, -10.0, 10.0, opts );
tau = uniform( N, 0.0, 2.0, opts );
work = new Float64Array( N );

return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var z;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = dorm2r( side, trans, N, N, N, A, N, 1, 0, tau, 1, 0, C, N, 1, 0, work, 1, 0 ); // eslint-disable-line max-len
if ( isnan( z[ i%z.length ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( z[ i%z.length ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var trans;
var side;
var min;
var max;
var N;
var f;
var i;
var j;

min = 1; // 10^min
max = 3; // 10^max

for ( i = 0; i < SIDES.length; i++ ) {
side = SIDES[ i ];
for ( j = 0; j < TRANS.length; j++ ) {
trans = TRANS[ j ];
for ( N = min; N <= max; N++ ) {
f = createBenchmark( side, trans, floor( pow( pow( 10, N ), 1.0/2.0 ) ) );
bench( format( '%s:ndarray:side=%s,trans=%s,size=%d', pkg, side, trans, N*N ), f );
}
}
}
}

main();
Loading