-
-
Notifications
You must be signed in to change notification settings - Fork 567
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
feat: add lapack/base/dlaev2
#2828
base: develop
Are you sure you want to change the base?
Changes from all commits
6854419
1a66eff
f86ea9c
ba2389f
06b1182
8d73617
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,235 @@ | ||
<!-- | ||
|
||
@license Apache-2.0 | ||
|
||
Copyright (c) 2024 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. | ||
|
||
--> | ||
|
||
# dlaev2 | ||
|
||
> Compute the eigendecomposition of a 2x2 symmetric matrix. | ||
|
||
<section class = "usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var dlaev2 = require( '@stdlib/lapack/base/dlaev2' ); | ||
``` | ||
|
||
#### dlaev2( A, B, C, out, ev ) | ||
|
||
Computes the eigendecomposition of a 2x2 symmetric matrix. | ||
|
||
```javascript | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
|
||
var ev = new Float64Array( 2 ); | ||
var out = new Float64Array( 2 ); | ||
out = dlaev2( 2.0, 3.0, 4.0, out, ev ); | ||
// out => <Float64Array>[ ~6.162, ~-0.162 ] | ||
// ev => <Float64Array>[ ~0.585, ~0.811 ] | ||
``` | ||
|
||
The function has the following parameters: | ||
|
||
- **A**: the (0,0) element of a 2x2 symmetric matrix. | ||
- **B**: the (0,1) and the conjugate of (1,0) element of a 2x2 symmetric matrix. | ||
- **C**: the (1,1) element of a 2x2 symmetric matrix. | ||
- **out**: output [`Float64Array`][mdn-float64array] containing the eigenvalues of larger and smaller absolute values respectively. | ||
- **ev**: output [`Float64Array`][mdn-float64array] containing `CS1` and `SN1` which is unit right eigenvector for `RT1` giving the decomposition. | ||
|
||
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. | ||
|
||
<!-- eslint-disable stdlib/capitalized-comments --> | ||
|
||
```javascript | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
|
||
// Initial arrays... | ||
var out0 = new Float64Array( [ 1.0, 2.0, 3.0 ] ); | ||
var ev0 = new Float64Array( [ 1.0, 2.0, 3.0 ] ); | ||
|
||
// Create offset views... | ||
var out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | ||
var ev1 = new Float64Array( ev0.buffer, ev0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | ||
|
||
dlaev2( 2.0, 3.0, 4.0, out1, ev1 ); | ||
// out0 => <Float64Array>[ 1.0, ~6.162, ~-0.162 ] | ||
// ev0 => <Float64Array>[ 1.0, ~0.585, ~0.811 ] | ||
``` | ||
|
||
#### dlaev2.ndarray( A, B, C, out, sout, oout, ev, sev, oev ) | ||
|
||
Computes the eigendecomposition of a 2x2 symmetric matrix using alternative indexing semantics. | ||
|
||
```javascript | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
|
||
var ev = new Float64Array( 2 ); | ||
var out = new Float64Array( 2 ); | ||
out = dlaev2.ndarray( 2.0, 3.0, 4.0, out, 1, 0, ev, 1, 0 ); | ||
// out => <Float64Array>[ ~6.162, ~-0.162 ] | ||
// ev => <Float64Array>[ ~0.585, ~0.811 ] | ||
``` | ||
|
||
The function has the following additional parameters: | ||
|
||
- **sout**: stride length for `out`. | ||
- **oout**: starting index of `out`. | ||
- **sev**: stride length for `ev`. | ||
- **oev**: starting index of `ev`. | ||
|
||
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, | ||
|
||
```javascript | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
|
||
var ev = new Float64Array( [ 999.9, 0.0, 999.9, 0.0 ] ); | ||
var out = new Float64Array( [ 0.0, 999.9, 0.0 ] ); | ||
out = dlaev2.ndarray( 2.0, 3.0, 4.0, out, -2, 2, ev, 2, 1 ); | ||
// out => <Float64Array>[ ~-0.162, 999.9, ~6.162 ] | ||
// ev => <Float64Array>[ 999.9, ~0.585, 999.9, ~0.811 ] | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<section class="notes"> | ||
|
||
## Notes | ||
|
||
- `dlaev2()` corresponds to the [LAPACK][lapack] routine [`dlaev2`][lapack-dlaev2]. | ||
|
||
</section> | ||
|
||
<!-- /.notes --> | ||
|
||
<section class="examples"> | ||
|
||
## Examples | ||
|
||
<!-- eslint no-undef: "error" --> | ||
|
||
```javascript | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
var dlaev2 = require( '@stdlib/lapack/base/dlaev2' ); | ||
|
||
var ev = new Float64Array( 2 ); | ||
var out = new Float64Array( 2 ); | ||
out = dlaev2( 2.0, 3.0, 4.0, out, ev ); | ||
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. Do something different; otherwise, what is the point of having this code block? |
||
console.log( 'out: ', out ); | ||
console.log( 'ev: ', ev ); | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> | ||
|
||
<!-- C interface documentation. --> | ||
|
||
* * * | ||
|
||
<section class="c"> | ||
|
||
## C APIs | ||
|
||
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> | ||
|
||
<section class="intro"> | ||
|
||
</section> | ||
|
||
<!-- /.intro --> | ||
|
||
<!-- C usage documentation. --> | ||
|
||
<section class="usage"> | ||
|
||
### Usage | ||
|
||
```c | ||
TODO | ||
``` | ||
|
||
#### TODO | ||
|
||
TODO. | ||
|
||
```c | ||
TODO | ||
``` | ||
|
||
TODO | ||
|
||
```c | ||
TODO | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="notes"> | ||
|
||
</section> | ||
|
||
<!-- /.notes --> | ||
|
||
<!-- C API usage examples. --> | ||
|
||
<section class="examples"> | ||
|
||
### Examples | ||
|
||
```c | ||
TODO | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> | ||
|
||
</section> | ||
|
||
<!-- /.c --> | ||
|
||
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
||
<section class="related"> | ||
|
||
</section> | ||
|
||
<!-- /.related --> | ||
|
||
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="links"> | ||
|
||
[lapack]: https://www.netlib.org/lapack/explore-html/ | ||
|
||
[lapack-dlaev2]: https://www.netlib.org/lapack/explore-html/db/d54/group__laev2_gacd10150d9e7ed9fc85ba274c3dcc9849.html#gacd10150d9e7ed9fc85ba274c3dcc9849 | ||
|
||
[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array | ||
|
||
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2018 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 randu = require( '@stdlib/random/base/randu' ); | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
var pkg = require( './../package.json' ).name; | ||
var dlaev2 = require( './../lib/dlaev2.js' ); | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg, function benchmark( b ) { | ||
var out; | ||
var ev; | ||
var A; | ||
var B; | ||
var C; | ||
var i; | ||
|
||
out = new Float64Array( 2 ); | ||
ev = new Float64Array( 2 ); | ||
A = ( randu()*1000.0 ) - 500.0; | ||
B = ( randu()*1000.0 ) - 500.0; | ||
C = ( randu()*1000.0 ) - 500.0; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
out = dlaev2( A, B, C, out, ev ); | ||
A = out[ i%out.length ]; | ||
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. Why are we recycling |
||
B = out[ i%out.length ]; | ||
C = ev[ i%ev.length ]; | ||
if ( isnan( out[ i%out.length ] || isnan( ev[ i%ev.length ] ) ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnan( out[ i%out.length ] || isnan( ev[ i%ev.length ] ) ) ) { | ||
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,63 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2018 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 randu = require( '@stdlib/random/base/randu' ); | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
var pkg = require( './../package.json' ).name; | ||
var dlaev2 = require( './../lib/ndarray.js' ); | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg+':ndarray', function benchmark( b ) { | ||
var out; | ||
var ev; | ||
var A; | ||
var B; | ||
var C; | ||
var i; | ||
|
||
out = new Float64Array( 2 ); | ||
ev = new Float64Array( 2 ); | ||
A = ( randu()*1000.0 ) - 500.0; | ||
B = ( randu()*1000.0 ) - 500.0; | ||
C = ( randu()*1000.0 ) - 500.0; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
out = dlaev2( A, B, C, out, 1, 0, ev, 1, 0 ); | ||
A = out[ i%out.length ]; | ||
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. Same comment. |
||
B = out[ i%out.length ]; | ||
C = ev[ i%ev.length ]; | ||
if ( isnan( out[ i%out.length ] || isnan( ev[ i%ev.length ] ) ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnan( out[ i%out.length ] || isnan( ev[ i%ev.length ] ) ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); |
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.
You're going to need to explain
CS1
andSN1
andRT1
. This description doesn't tell me a whole lot. Either add prose or show equations.