Skip to content

feat: add lapack/base/dlartg #7612

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
112 changes: 112 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlaqr1/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
* @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 uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var Float64Array = require( '@stdlib/array/float64' );
var pkg = require( './../package.json' ).name;
var dlaqr1 = require( './../lib/dlaqr1.js' );


// VARIABLES //

var LAYOUTS = [
'row-major',
'column-major'
];


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {string} order - storage layout
* @param {PositiveInteger} N - number of elements along each dimension
* @returns {Function} benchmark function
*/
function createBenchmark( order, N ) {
var values;
var H;
var V;

H = uniform( N*N, -10.0, 10.0, {
'dtype': 'float64'
});
values = uniform( N, -10.0, 10.0, {
'dtype': 'float64'
});
V = 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 = dlaqr1( order, N, H, N, values[ i%N ], values[ (i+1)%N ], values[ (i+2)%N ], values[ (i+3)%N ], V ); // 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 ord;
var N;
var f;
var i;

for ( i = 0; i < LAYOUTS.length; i++ ) {
ord = LAYOUTS[ i ];
for ( N = 2; N <= 3; N++ ) {
f = createBenchmark( ord, N );
bench( pkg+'::square_matrix:order='+ord+',size='+(N*N), f );
}
}
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**
* @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 uniform = require( '@stdlib/random/array/uniform' );
var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var Float64Array = require( '@stdlib/array/float64' );
var pkg = require( './../package.json' ).name;
var dlaqr1 = require( './../lib/ndarray.js' );


// VARIABLES //

var LAYOUTS = [
'row-major',
'column-major'
];


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {string} order - storage layout
* @param {PositiveInteger} N - number of elements along each dimension
* @returns {Function} benchmark function
*/
function createBenchmark( order, N ) {
var values;
var sh1;
var sh2;
var H;
var V;

if ( isColumnMajor( order ) ) {
sh1 = 1;
sh2 = N;
} else { // order === 'row-major'
sh1 = N;
sh2 = 1;
}
H = uniform( N*N, -10.0, 10.0, {
'dtype': 'float64'
});
values = uniform( N, -10.0, 10.0, {
'dtype': 'float64'
});
V = 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 = dlaqr1( N, H, sh1, sh2, 0, values[ i%N ], values[ (i+1)%N ], values[ (i+2)%N ], values[ (i+3)%N ], V, 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 ord;
var N;
var f;
var i;

for ( i = 0; i < LAYOUTS.length; i++ ) {
ord = LAYOUTS[ i ];
for ( N = 2; N <= 3; N++ ) {
f = createBenchmark( ord, N );
bench( pkg+'::square_matrix:ndarray:order='+ord+',size='+(N*N), f );
}
}
}

main();
138 changes: 138 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlaqr1/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* @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.
*/

// TypeScript Version: 4.1

/// <reference types="@stdlib/types"/>

import { Layout } from '@stdlib/types/blas';

/**
* Interface describing `dlaqr1`.
*/
interface Routine {
/**
* Given a 2-by-2 or a 3-by-3 matrix, sets `V` to a scalar multiple of the first column of `K` where `K = (H - (sr1 + i*si1)*I)*(H - (sr2 + i*si2)*I)`.
*
* ## Notes
*
* - It is expected that either `sr1 = sr2` and `si1 + si2 = 0` or `si1 = si2 = 0` (i.e., they represent complex conjugate values).
* - This is useful for starting double implicit shift bulges in the QR algorithm.
* - `V` should have at least `N` indexed elements.
*
* @param order - storage layout
* @param N - number of row/columns in `H`
* @param H - input matrix
* @param LDH - stride of the first dimension of `H` (a.k.a., leading dimension of the matrix `H`)
* @param sr1 - real part of the first conjugate complex shift
* @param si1 - imaginary part of the first conjugate complex shift
* @param sr2 - real part of the second conjugate complex shift
* @param si2 - imaginary part of the second conjugate complex shift
* @param V - output array
* @returns `V`
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var H = new Float64Array( [ 1.0, 3.0, 2.0, 2.0, 4.0, 6.0, 0.0, 5.0, 7.0 ] );
* var V = new Float64Array( 3 );
*
* dlaqr1( 'row-major', 3, H, 3, 1.5, 0.0, 2.5, 0.0, V );
* // V => <Float64Array>[ ~1.93, ~0.57, ~2.86 ]
*/
( order: Layout, N: number, H: Float64Array, LDH: number, sr1: number, si1: number, sr2: number, si2: number, V: Float64Array ): Float64Array;

/**
* Given a 2-by-2 or a 3-by-3 matrix, sets `V` to a scalar multiple of the first column of `K` where `K = (H - (sr1 + i*si1)*I)*(H - (sr2 + i*si2)*I)` using alternative indexing semantics.
*
* ## Notes
*
* - It is expected that either `sr1 = sr2` and `si1 + si2 = 0` or `si1 = si2 = 0` (i.e., they represent complex conjugate values).
* - This is useful for starting double implicit shift bulges in the QR algorithm.
* - `V` should have at least `N` indexed elements.
*
* @param N - number of row/columns in `H`
* @param H - input matrix
* @param strideH1 - stride of the first dimension of `H`
* @param strideH2 - stride of the second dimension of `H`
* @param offsetH - index offset for `H`
* @param sr1 - real part of the first conjugate complex shift
* @param si1 - imaginary part of the first conjugate complex shift
* @param sr2 - real part of the second conjugate complex shift
* @param si2 - imaginary part of the second conjugate complex shift
* @param V - output array
* @param strideV - stride length for `V`
* @param offsetV - index offset for `V`
* @returns `V`
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var H = new Float64Array( [ 1.0, 3.0, 2.0, 2.0, 4.0, 6.0, 0.0, 5.0, 7.0 ] );
* var V = new Float64Array( 3 );
*
* dlaqr1.ndarray( 3, H, 3, 1, 0, 1.5, 0.0, 2.5, 0.0, V, 1, 0 );
* // V => <Float64Array>[ ~1.93, ~0.57, ~2.86 ]
*/
ndarray( N: number, H: Float64Array, strideH1: number, strideH2: number, offsetH: number, sr1: number, si1: number, sr2: number, si2: number, V: Float64Array, strideV: number, offsetV: number ): Float64Array;
}

/**
* Given a 2-by-2 or a 3-by-3 matrix, sets `V` to a scalar multiple of the first column of `K` where `K = (H - (sr1 + i*si1)*I)*(H - (sr2 + i*si2)*I)`.
*
* ## Notes
*
* - It is expected that either `sr1 = sr2` and `si1 + si2 = 0` or `si1 = si2 = 0` (i.e., they represent complex conjugate values).
* - This is useful for starting double implicit shift bulges in the QR algorithm.
* - `V` should have at least `N` indexed elements.
*
* @param order - storage layout
* @param N - number of row/columns in `H`
* @param H - input matrix
* @param LDH - stride of the first dimension of `H` (a.k.a., leading dimension of the matrix `H`)
* @param sr1 - real part of the first conjugate complex shift
* @param si1 - imaginary part of the first conjugate complex shift
* @param sr2 - real part of the second conjugate complex shift
* @param si2 - imaginary part of the second conjugate complex shift
* @param V - output array
* @returns `V`
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var H = new Float64Array( [ 1.0, 3.0, 2.0, 2.0, 4.0, 6.0, 0.0, 5.0, 7.0 ] );
* var V = new Float64Array( 3 );
*
* dlaqr1( 'row-major', 3, H, 3, 1.5, 0.0, 2.5, 0.0, V );
* // V => <Float64Array>[ ~1.93, ~0.57, ~2.86 ]
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var H = new Float64Array( [ 1.0, 3.0, 2.0, 2.0, 4.0, 6.0, 0.0, 5.0, 7.0 ] );
* var V = new Float64Array( 3 );
*
* dlaqr1.ndarray( 3, H, 3, 1, 0, 1.5, 0.0, 2.5, 0.0, V, 1, 0 );
* // V => <Float64Array>[ ~1.93, ~0.57, ~2.86 ]
*/
declare var dlaqr1: Routine;


// EXPORTS //

export = dlaqr1;
Loading
Loading