Skip to content

feat: add C / Fortran implementation for blas/base/drotg #2264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.assign.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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 Float64Array = require( '@stdlib/array/float64' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var pkg = require( './../package.json' ).name;
var drotg = require( './../lib/assign.js' );


// VARIABLES //

var options = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @returns {Function} benchmark function
*/
function createBenchmark() {
var x = uniform( -10.0, 10.0, options );
var y = uniform( -10.0, 10.0, options );
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++ ) {
out = new Float64Array( 4 );

Check failure on line 65 in lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.assign.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'out' is not defined

Check failure on line 65 in lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.assign.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Mixed spaces and tabs
z = drotg( x, y, out, 1, 0 );

Check failure on line 66 in lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.assign.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'out' is not defined

Check failure on line 66 in lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.assign.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Expected indentation of 3 tabs but found 12 spaces
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() {

Check failure on line 88 in lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.assign.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Variable declarations inside of function are not ordered by length (in decreasing order)
var N;
var min;
var max;
var f;
var i;

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

for ( i = min; i <= max; i++ ) {
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
f = createBenchmark( N );
bench( pkg+':assign:size='+(N*N), f );
}
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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 resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( '@stdlib/blas/base/drotg/package.json' ).name;


// VARIABLES //

var drotg = tryRequire( resolve( __dirname, './../lib/assign.native.js' ) );
var opts = {
'skip': ( drotg instanceof Error )
};
var options = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @returns {Function} benchmark function
*/
function createBenchmark() {
var x = uniform( -10.0, 10.0, options );
var y = uniform( -10.0, 10.0, options );
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++ ) {
out = new Float64Array( 4 );
z = drotg( x, y, out, 1, 0 );
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 min;
var max;
var N;
var f;
var i;

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

for ( i = min; i <= max; i++ ) {
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
f = createBenchmark( N );
bench( pkg+'::native:assign:size='+(N*N), opts, f );
}
}

main();
107 changes: 61 additions & 46 deletions lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2023 The Stdlib Authors.
* Copyright (c) 2025 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.
Expand All @@ -21,68 +21,83 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var uniform = require( '@stdlib/random/base/uniform' );
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 pkg = require( './../package.json' ).name;
var drotg = require( './../lib' );
var drotg = require( './../lib/drotg.js' );


// VARIABLES //

var OPTS = {
var options = {
'dtype': 'float64'
};


// MAIN //
// FUNCTIONS //

bench( pkg, function benchmark( b ) {
var out;
var x;
var y;
var i;
/**
* Creates a benchmark function.
*
* @private
* @returns {Function} benchmark function
*/
function createBenchmark() {
var x = uniform( -10.0, 10.0 );
var y = uniform( -10.0, 10.0 );
return benchmark;

x = discreteUniform( 100, -5, 5, OPTS );
y = discreteUniform( 100, -5, 5, OPTS );
/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var z;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = drotg( x[ i%x.length ], y[ i%y.length ] );
if ( isnan( out[ i%4 ] ) ) {
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = drotg( x, y );
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();
}
b.toc();
if ( isnan( out[ i%4 ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+':assign', function benchmark( b ) {
var out;
var x;
var y;
var z;
}


// MAIN //

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

x = discreteUniform( 100, -5, 5, OPTS );
y = discreteUniform( 100, -5, 5, OPTS );
out = new Float64Array( 4 );
min = 1; // 10^min
max = 6; // 10^max

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = drotg.assign( x[ i%x.length ], y[ i%y.length ], out, 1, 0 );
if ( typeof z !=='object' ) {
b.fail( 'should return an array' );
}
for ( i = min; i <= max; i++ ) {
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
f = createBenchmark( N );
bench( pkg+':size='+(N*N), f );
}
b.toc();
if ( isnan( z[ i%4 ] ) ) {
b.fail( 'should return the output array' );
}
b.pass( 'benchmark finished' );
b.end();
});
}

main();
Loading
Loading