-
-
Notifications
You must be signed in to change notification settings - Fork 870
feat: add lapack/base/dlanv2
#7492
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
base: develop
Are you sure you want to change the base?
Changes from all commits
90c0491
f072be6
8fbcb55
2e13486
0ef0464
222a922
f16759d
03a8196
aabd565
ecaad2a
d58f9f2
273099d
47b35fd
ae65ee9
cebf9eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
var pkg = require( './../package.json' ).name; | ||
var dlanv2 = require( './../lib/dlanv2.js' ); | ||
|
||
|
||
// VARIABLES // | ||
|
||
var opts = { | ||
'dtype': 'float64' | ||
}; | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg, function benchmark( b ) { | ||
var RT1R; | ||
var RT1I; | ||
var RT2R; | ||
var RT2I; | ||
var CS; | ||
var SN; | ||
var A; | ||
var B; | ||
var C; | ||
var D; | ||
var i; | ||
|
||
A = discreteUniform( 1, -50, 50, opts ); | ||
B = discreteUniform( 1, -50, 50, opts ); | ||
C = discreteUniform( 1, -50, 50, opts ); | ||
D = discreteUniform( 1, -50, 50, opts ); | ||
RT1R = new Float64Array( 1 ); | ||
RT1I = new Float64Array( 1 ); | ||
RT2R = new Float64Array( 1 ); | ||
RT2I = new Float64Array( 1 ); | ||
CS = new Float64Array( 1 ); | ||
SN = new Float64Array( 1 ); | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
dlanv2( A, B, C, D, RT1R, RT1I, RT2R, RT2I, CS, SN ); | ||
if ( isnan( A[ 0 ] ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnan( B[ 0 ] ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
var pkg = require( './../package.json' ).name; | ||
var dlanv2 = require( './../lib/ndarray.js' ); | ||
|
||
|
||
// VARIABLES // | ||
|
||
var opts = { | ||
'dtype': 'float64' | ||
}; | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg, function benchmark( b ) { | ||
var RT1R; | ||
var RT1I; | ||
var RT2R; | ||
var RT2I; | ||
var CS; | ||
var SN; | ||
var A; | ||
var B; | ||
var C; | ||
var D; | ||
var i; | ||
|
||
A = discreteUniform( 1, -50, 50, opts ); | ||
B = discreteUniform( 1, -50, 50, opts ); | ||
C = discreteUniform( 1, -50, 50, opts ); | ||
D = discreteUniform( 1, -50, 50, opts ); | ||
RT1R = new Float64Array( 1 ); | ||
RT1I = new Float64Array( 1 ); | ||
RT2R = new Float64Array( 1 ); | ||
RT2I = new Float64Array( 1 ); | ||
CS = new Float64Array( 1 ); | ||
SN = new Float64Array( 1 ); | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
dlanv2( A, 0, B, 0, C, 0, D, 0, RT1R, 0, RT1I, 0, RT2R, 0, RT2I, 0, CS, 0, SN, 0 ); // eslint-disable-line max-len | ||
if ( isnan( A[ 0 ] ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnan( B[ 0 ] ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,216 @@ | ||||||
{{alias}}( A, B, C, D, RT1R, RT1I, RT2R, RT2I, CS, SN ) | ||||||
Computes the real Schur factorization of a 2-by-2 real nonsymmetric | ||||||
matrix using an orthogonal similarity transformation. | ||||||
|
||||||
Given matrix: | ||||||
|
||||||
[ A B ] | ||||||
[ C D ] | ||||||
|
||||||
The routine computes an orthogonal rotation (cosine CS, sine SN) such | ||||||
that: | ||||||
|
||||||
Q^T * [ A B ] * Q = [ AA BB ] | ||||||
[ C D ] [ CC DD ] | ||||||
|
||||||
where Q is a 2x2 rotation matrix: | ||||||
|
||||||
Q = [ CS SN ] | ||||||
[ -SN CS ] | ||||||
|
||||||
and the result is either real upper triangular (real eigenvalues) or | ||||||
2x2 block diagonal (complex conjugate eigenvalues). | ||||||
|
||||||
Indexing is relative to the first index. To introduce an offset, use | ||||||
typed array views. | ||||||
|
||||||
Parameters | ||||||
---------- | ||||||
A: Float64Array | ||||||
Input element A(1,1). | ||||||
|
||||||
B: Float64Array | ||||||
Input element A(1,2). | ||||||
|
||||||
C: Float64Array | ||||||
Input element A(2,1). | ||||||
|
||||||
D: Float64Array | ||||||
Input element A(2,2). | ||||||
|
||||||
RT1R: Float64Array | ||||||
Output: real part of the first eigenvalue. | ||||||
|
||||||
RT1I: Float64Array | ||||||
Output: imaginary part of the first eigenvalue. | ||||||
|
||||||
RT2R: Float64Array | ||||||
Output: real part of the second eigenvalue. | ||||||
|
||||||
RT2I: Float64Array | ||||||
Output: imaginary part of the second eigenvalue. | ||||||
|
||||||
CS: Float64Array | ||||||
Output: cosine of the rotation. | ||||||
|
||||||
SN: Float64Array | ||||||
Output: sine of the rotation. | ||||||
|
||||||
Returns | ||||||
------- | ||||||
undefined | ||||||
|
||||||
Examples | ||||||
-------- | ||||||
> var Float64Array = require( '@stdlib/array/float64' ); | ||||||
> var dlanv2 = require( '@stdlib/lapack/base/dlanv2' ); | ||||||
|
||||||
> var A = new Float64Array( [ 4.0 ] ); | ||||||
> var B = new Float64Array( [ -5.0 ] ); | ||||||
> var C = new Float64Array( [ 2.0 ] ); | ||||||
> var D = new Float64Array( [ -3.0 ] ); | ||||||
> var RT1R = new Float64Array( 1 ); | ||||||
> var RT1I = new Float64Array( 1 ); | ||||||
> var RT2R = new Float64Array( 1 ); | ||||||
> var RT2I = new Float64Array( 1 ); | ||||||
> var CS = new Float64Array( 1 ); | ||||||
> var SN = new Float64Array( 1 ); | ||||||
|
||||||
> dlanv2( A, B, C, D, RT1R, RT1I, RT2R, RT2I, CS, SN ); | ||||||
|
||||||
> A | ||||||
<Float64Array>[ 2.0 ] | ||||||
> B | ||||||
<Float64Array>[ -7.0 ] | ||||||
> C | ||||||
<Float64Array>[ 0.0 ] | ||||||
> D | ||||||
<Float64Array>[ -1.0 ] | ||||||
> RT1R | ||||||
<Float64Array>[ 2.0 ] | ||||||
> RT1I | ||||||
<Float64Array>[ 0.0 ] | ||||||
> RT2R | ||||||
<Float64Array>[ -1.0 ] | ||||||
> RT2I | ||||||
<Float64Array>[ 0.0 ] | ||||||
> CS | ||||||
<Float64Array>[ ~0.93 ] | ||||||
> SN | ||||||
<Float64Array>[ ~0.34 ] | ||||||
|
||||||
{{alias}}.ndarray( A,oa,B,ob,C,oc,D,od,R1,or1,I1,oi1,R2,or2,I2,oi2,CS,ocs,SN,osn ) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need help with the heading here, failing at 80+ characters There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this has been resolved based on the suggestion below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Computes the Schur factorization of a 2-by-2 real nonsymmetric matrix | ||||||
using alternative indexing semantics. | ||||||
|
||||||
Given matrix: | ||||||
|
||||||
[ A B ] | ||||||
[ C D ] | ||||||
|
||||||
The routine computes an orthogonal rotation (cosine CS, sine SN) such | ||||||
that: | ||||||
|
||||||
Q^T * [ A B ] * Q = [ AA BB ] | ||||||
[ C D ] [ CC DD ] | ||||||
|
||||||
where Q is a 2x2 rotation matrix: | ||||||
|
||||||
Q = [ CS SN ] | ||||||
[ -SN CS ] | ||||||
|
||||||
and the result is either real upper triangular (real eigenvalues) or | ||||||
2x2 block diagonal (complex conjugate eigenvalues). | ||||||
|
||||||
While typed array views mandate a view offset based on the underlying | ||||||
buffer, the offset parameters support indexing semantics based on starting | ||||||
indices. | ||||||
|
||||||
Parameters | ||||||
---------- | ||||||
A: Float64Array | ||||||
Input element A(1,1). | ||||||
|
||||||
oa: integer | ||||||
Starting index for `A`. | ||||||
|
||||||
B: Float64Array | ||||||
Input element A(1,2). | ||||||
|
||||||
ob: integer | ||||||
Starting index for `B`. | ||||||
|
||||||
C: Float64Array | ||||||
Input element A(2,1). | ||||||
|
||||||
oc: integer | ||||||
Starting index for `C`. | ||||||
|
||||||
D: Float64Array | ||||||
Input element A(2,2). | ||||||
|
||||||
od: integer | ||||||
Starting index for `D`. | ||||||
|
||||||
R1: Float64Array | ||||||
Output: real part of the first eigenvalue. | ||||||
|
||||||
or1: integer | ||||||
Starting index for `R1`. | ||||||
|
||||||
I1: Float64Array | ||||||
Output: imaginary part of the first eigenvalue. | ||||||
|
||||||
oi1: integer | ||||||
Starting index for `I1`. | ||||||
|
||||||
R2: Float64Array | ||||||
Output: real part of the second eigenvalue. | ||||||
|
||||||
or2: integer | ||||||
Starting index for `R2`. | ||||||
|
||||||
I2: Float64Array | ||||||
Output: imaginary part of the second eigenvalue. | ||||||
|
||||||
oi2: integer | ||||||
Starting index for `I2`. | ||||||
|
||||||
CS: Float64Array | ||||||
Output: cosine of the rotation. | ||||||
|
||||||
ocs: integer | ||||||
Starting index for `CS`. | ||||||
|
||||||
SN: Float64Array | ||||||
Output: sine of the rotation. | ||||||
|
||||||
osn: integer | ||||||
Starting index for `SN`. | ||||||
|
||||||
Examples | ||||||
-------- | ||||||
> var Float64Array = require( '@stdlib/array/float64' ); | ||||||
> var A = new Float64Array( [ 0.0, 4.0 ] ); | ||||||
> var B = new Float64Array( [ 0.0, -5.0 ] ); | ||||||
> var C = new Float64Array( [ 0.0, 2.0 ] ); | ||||||
> var D = new Float64Array( [ 0.0, -3.0 ] ); | ||||||
> var RT1R = new Float64Array( 2 ); | ||||||
> var RT1I = new Float64Array( 2 ); | ||||||
> var RT2R = new Float64Array( 2 ); | ||||||
> var RT2I = new Float64Array( 2 ); | ||||||
> var CS = new Float64Array( 2 ); | ||||||
> var SN = new Float64Array( 2 ); | ||||||
|
||||||
> dlanv2.ndarray( A, 1, B, 1, C, 1, D, 1, | ||||||
RT1R, 1, RT1I, 1, RT2R, 1, RT2I, 1, CS, 1, SN, 1 ); | ||||||
|
||||||
> A | ||||||
<Float64Array>[ 0.0, 2.0 ] | ||||||
> C | ||||||
<Float64Array>[ 0.0, 0.0 ] | ||||||
> RT1R | ||||||
<Float64Array>[ 0.0, 2.0 ] | ||||||
> RT2R | ||||||
<Float64Array>[ 0.0, -1.0 ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.