-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add lapack/base/dlasv2
#2819
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 10 commits
847c6a1
1b54010
14c0f38
07aa24b
8bf7474
ec39c56
2fd0866
bd33456
d407c46
691c1a9
f12a2af
53d229f
ad5abee
06d4091
6eb6d6a
612611c
9262677
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,224 @@ | ||||||||||||||||
| <!-- | ||||||||||||||||
|
|
||||||||||||||||
| @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. | ||||||||||||||||
|
|
||||||||||||||||
| --> | ||||||||||||||||
|
|
||||||||||||||||
| # dlasv2 | ||||||||||||||||
|
|
||||||||||||||||
| > Compute singular value decomposition of a 2x2 triangular matrix. | ||||||||||||||||
|
|
||||||||||||||||
| <section class="usage"> | ||||||||||||||||
|
|
||||||||||||||||
| ## Usage | ||||||||||||||||
|
|
||||||||||||||||
| ```javascript | ||||||||||||||||
| var dlasv2 = require( '@stdlib/lapack/base/dlasv2' ); | ||||||||||||||||
| ``` | ||||||||||||||||
|
|
||||||||||||||||
| #### dlasv2( F, G, H, out ) | ||||||||||||||||
|
|
||||||||||||||||
| Computes singular value decomposition of a 2x2 triangular matrix. | ||||||||||||||||
|
|
||||||||||||||||
| ```javascript | ||||||||||||||||
| var Float64Array = require( '@stdlib/array/float64' ); | ||||||||||||||||
| var out = new Float64Array( 6 ); | ||||||||||||||||
|
|
||||||||||||||||
| out = dlasv2( 2.0, 3.0, 4.0, out ); | ||||||||||||||||
| // out => <Float64Array>[ 1.5513263285176897, 5.1568776039816795, 0.9664996487646696, 0.25666793515702424, 0.7496781758158659, 0.6618025632357402 ] | ||||||||||||||||
|
Member
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
If we want to communicate that the output array is returned, the return value should be assigned to a different variable name. |
||||||||||||||||
| ``` | ||||||||||||||||
|
|
||||||||||||||||
| The function has the following parameters: | ||||||||||||||||
|
|
||||||||||||||||
| - **F**: the (0,0) element of matrix. | ||||||||||||||||
| - **G**: the (0,1) element of matrix. | ||||||||||||||||
| - **H**: the (1,1) element of matrix. | ||||||||||||||||
| - **out**: [`Float64Array`][mdn-float64array] output array containing `SSMIN`, `SSMAX`, `SNR`, `CSR`, `SNL`, and `CSL` respectively. | ||||||||||||||||
|
Member
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
Prefer linking to the stdlib package.
Member
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. Additionally, nowhere in the documentation do we describe what |
||||||||||||||||
|
|
||||||||||||||||
| 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( [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); | ||||||||||||||||
|
|
||||||||||||||||
| // Create offset views... | ||||||||||||||||
| var OUT1 = new Float64Array( OUT0.buffer, OUT0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | ||||||||||||||||
|
|
||||||||||||||||
| dlasv2( 2.0, 3.0, 4.0, OUT1 ); | ||||||||||||||||
| // OUT0 => <Float64Array>[ 0.0, 1.5513263285176897, 5.1568776039816795, 0.9664996487646696, 0.25666793515702424, 0.7496781758158659, 0.6618025632357402 ] | ||||||||||||||||
| ``` | ||||||||||||||||
|
|
||||||||||||||||
| #### dlasv2.ndarray( F, G, H, out, strideOut, offsetOut ) | ||||||||||||||||
|
|
||||||||||||||||
| Computes singular value decomposition of a 2x2 triangular matrix using alternative indexing semantics. | ||||||||||||||||
|
|
||||||||||||||||
| ```javascript | ||||||||||||||||
| var Float64Array = require( '@stdlib/array/float64' ); | ||||||||||||||||
| var out = new Float64Array( 6 ); | ||||||||||||||||
|
|
||||||||||||||||
| out = dlasv2.ndarray( 2.0, 3.0, 4.0, out, 1, 0 ); | ||||||||||||||||
| // out => <Float64Array>[ 1.5513263285176897, 5.1568776039816795, 0.9664996487646696, 0.25666793515702424, 0.7496781758158659, 0.6618025632357402 ] | ||||||||||||||||
| ``` | ||||||||||||||||
|
|
||||||||||||||||
| The function has the following additional parameters: | ||||||||||||||||
|
|
||||||||||||||||
| - **strideOut**: stride length for `Out`. | ||||||||||||||||
| - **offsetOut**: starting index for `Out`. | ||||||||||||||||
|
|
||||||||||||||||
| 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, | ||||||||||||||||
|
|
||||||||||||||||
| <!-- eslint-disable max-len --> | ||||||||||||||||
|
|
||||||||||||||||
| ```javascript | ||||||||||||||||
| var Float64Array = require( '@stdlib/array/float64' ); | ||||||||||||||||
| var out = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] ); | ||||||||||||||||
|
|
||||||||||||||||
| out = dlasv2.ndarray( 2.0, 3.0, 4.0, out, 1, 1 ); | ||||||||||||||||
| // out => <Float64Array>[ 0.0, 1.5513263285176897, 5.1568776039816795, 0.9664996487646696, 0.25666793515702424, 0.7496781758158659, 0.6618025632357402 ] | ||||||||||||||||
| ``` | ||||||||||||||||
|
|
||||||||||||||||
| </section> | ||||||||||||||||
|
|
||||||||||||||||
| <!-- /.usage --> | ||||||||||||||||
|
|
||||||||||||||||
| <section class="notes"> | ||||||||||||||||
|
|
||||||||||||||||
| ## Notes | ||||||||||||||||
|
|
||||||||||||||||
| - `dlasv2()` corresponds to the [LAPACK][LAPACK] routine [`dlasv2`][lapack-dlasv2]. | ||||||||||||||||
|
|
||||||||||||||||
| </section> | ||||||||||||||||
|
|
||||||||||||||||
| <!-- /.notes --> | ||||||||||||||||
|
|
||||||||||||||||
| <section class="examples"> | ||||||||||||||||
|
|
||||||||||||||||
| ## Examples | ||||||||||||||||
|
|
||||||||||||||||
| <!-- eslint no-undef: "error" --> | ||||||||||||||||
|
|
||||||||||||||||
| ```javascript | ||||||||||||||||
| var Float64Array = require( '@stdlib/array/float64' ); | ||||||||||||||||
| var dlasv2 = require( '@stdlib/lapack/base/dlasv2' ); | ||||||||||||||||
|
|
||||||||||||||||
| var out = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); | ||||||||||||||||
|
|
||||||||||||||||
| out = dlasv2( 2.0, 3.0, 4.0, out ); | ||||||||||||||||
|
Member
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. We need a different example. This just repeats the above. |
||||||||||||||||
| console.log( out ); | ||||||||||||||||
| ``` | ||||||||||||||||
|
|
||||||||||||||||
| </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-dlasv2]: https://www.netlib.org/lapack/explore-html/d8/da7/group__lasv2_ga96f9f244300d82921950e2c393b4b20f.html#ga96f9f244300d82921950e2c393b4b20f | ||||||||||||||||
|
|
||||||||||||||||
| [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,92 @@ | ||
| /** | ||
| * @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
| var pkg = require( './../package.json' ).name; | ||
| var dlasv2 = require( './../lib/dlasv2.js' ); | ||
|
|
||
|
|
||
| // VARIABLES // | ||
|
|
||
| var options = { | ||
| 'dtype': 'float64' | ||
| }; | ||
|
|
||
|
|
||
| // FUNCTIONS // | ||
|
|
||
| /** | ||
| * Creates a benchmark function. | ||
| * | ||
| * @private | ||
| * @returns {Function} benchmark function | ||
| */ | ||
| function createBenchmark( ) { | ||
| var out = uniform( 6, 0.0, 100.0, options ); | ||
| return benchmark; | ||
|
|
||
| function benchmark( b ) { | ||
| var d; | ||
| var i; | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| d = dlasv2( out[ 0 ], out[ 2 ], out[ 1 ], out ); | ||
| if ( isnan( d[ i%out.length ] ) ) { | ||
| b.fail( 'should not return NaN' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( isnan( d[ i%out.length ] ) ) { | ||
| b.fail( 'should not return NaN' ); | ||
| } | ||
| b.pass( 'benchmark finished' ); | ||
| b.end(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // MAIN // | ||
|
|
||
| /** | ||
| * Main execution sequence. | ||
| * | ||
| * @private | ||
| */ | ||
| function main() { | ||
|
Member
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. @prajjwalbajpai This benchmarks needs to be refactored. The |
||
| var min; | ||
| var max; | ||
| var f; | ||
| var i; | ||
|
|
||
| min = 1; // 10^min | ||
| max = 6; // 10^max | ||
|
|
||
| for ( i = min; i <= max; i++ ) { | ||
| f = createBenchmark(); | ||
| bench( pkg, f ); | ||
| } | ||
| } | ||
|
|
||
| main(); | ||
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.
Same thing. Applies here and everywhere.