-
-
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
Open
Pranavchiku
wants to merge
17
commits into
stdlib-js:develop
Choose a base branch
from
Pranavchiku:dlasv2
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
847c6a1
feat: init base implementation
Pranavchiku 1b54010
feat: init public apis in lib
Pranavchiku 14c0f38
docs: add README
Pranavchiku 07aa24b
docs: add repl
Pranavchiku 8bf7474
feat: add other files
Pranavchiku ec39c56
chore: add type notation in jsdoc of ndarray
Pranavchiku 2fd0866
Merge branch 'develop' into dlasv2
prajjwalbajpai bd33456
chore: update the `signum` implementation and improve test coverage
prajjwalbajpai d407c46
fix: lint errors
prajjwalbajpai 691c1a9
fix: module name in package.json
prajjwalbajpai f12a2af
refactor: major updates to tests, benchmarks and README file
prajjwalbajpai 53d229f
fix: improve benchmarks and other minor changes
prajjwalbajpai ad5abee
Apply suggestions from code review
kgryte 06d4091
Apply suggestions from code review
kgryte 6eb6d6a
test: replace `isApprox` with `is-almost-same-value-float64array`
prajjwalbajpai 612611c
fix: minor changes
prajjwalbajpai 9262677
docs: define matrix `A` clearly
prajjwalbajpai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,262 @@ | ||
| <!-- | ||
|
|
||
| @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 the singular value decomposition of a 2x2 upper triangular matrix. | ||
|
|
||
| <section class="intro"> | ||
|
|
||
| The singular value decomposition of a 2x2 upper triangular matrix $ \begin{bmatrix} F & G \\ 0 & H \end{bmatrix}$ is given by | ||
|
|
||
| <!-- <equation class="equation" label="eq:dlasv2_svd" align="center" raw="\left[\begin{array}{rr} \mathrm{CSL} & \mathrm{SNL} \\ -\mathrm{SNL} & \mathrm{CSL} \end{array}\right] \left[\begin{array}{rr} F & G \\ 0 & H \end{array}\right] \left[\begin{array}{rr} \mathrm{CSR} & -\mathrm{SNR} \\ \mathrm{SNR} & \mathrm{CSR} \end{array}\right] = \left[\begin{array}{rr} \mathrm{SSMAX} & 0 \\ 0 & \mathrm{SSMIN} \end{array}\right]" alt="Singular value decomposition of a 2x2 upper triangular matrix."> --> | ||
|
|
||
| ```math | ||
| \left[\begin{array}{rr}\mathrm{CSL} & \mathrm{SNL} \\ | ||
| -\mathrm{SNL} & \mathrm{CSL}\end{array}\right] | ||
|
|
||
| \left[\begin{array}{rr}F & G \\ | ||
| 0 & H\end{array}\right] | ||
|
|
||
| \left[\begin{array}{rr}\mathrm{CSR} & -\mathrm{SNR} \\ | ||
| \mathrm{SNR} & \mathrm{CSR}\end{array}\right] | ||
|
|
||
| = | ||
|
|
||
| \left[\begin{array}{rr}\mathrm{SSMAX} & 0 \\ | ||
| 0 & \mathrm{SSMIN}\end{array}\right] | ||
| ``` | ||
|
|
||
| <!-- </equation> --> | ||
|
|
||
| where `CSL`,`SNL`,`CSR`,`SNR` define orthogonal rotations and $\mathrm{SSMAX}^2, \mathrm{SSMIN}^2$ are the eigenvalues of $A^{T}A$. | ||
|
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. what is |
||
|
|
||
| </section> | ||
|
|
||
| <!-- /.intro --> | ||
|
|
||
| <section class="usage"> | ||
|
|
||
| ## Usage | ||
|
|
||
| ```javascript | ||
| var dlasv2 = require( '@stdlib/lapack/base/dlasv2' ); | ||
| ``` | ||
|
|
||
| #### dlasv2( F, G, H, out ) | ||
|
|
||
| Computes the singular value decomposition of a 2x2 upper triangular matrix. | ||
|
|
||
| ```javascript | ||
| var Float64Array = require( '@stdlib/array/float64' ); | ||
| var out = new Float64Array( 6 ); | ||
|
|
||
| var v = dlasv2( 2.0, 3.0, 4.0, out ); | ||
| // returns <Float64Array>[ ~1.5513, ~5.1569, ~0.9665, ~0.2567, ~0.7497, ~0.6618 ] | ||
|
|
||
| var bool = ( v === out ); | ||
| // returns true | ||
| ``` | ||
|
|
||
| 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`][@stdlib/array/float64] output array containing `SSMIN`, `SSMAX`, `SNR`, `CSR`, `SNL`, and `CSL` respectively. | ||
|
|
||
| On return, `abs(SSMAX)` is the larger singular value, `abs(SSMIN)` is the smaller singular value, and (`CSL`,`SNL`) and (`CSR`,`SNR`) are the left and right singular vectors for `abs(SSMAX)` as described in 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( [ 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.5513, ~5.1569, ~0.9665, ~0.2567, ~0.7497, ~0.6618 ] | ||
| ``` | ||
|
|
||
| #### dlasv2.ndarray( F, G, H, out, strideOut, offsetOut ) | ||
|
|
||
| Computes the singular value decomposition of a 2x2 upper triangular matrix using alternative indexing semantics. | ||
|
|
||
| ```javascript | ||
| var Float64Array = require( '@stdlib/array/float64' ); | ||
| var out = new Float64Array( 6 ); | ||
|
|
||
| dlasv2.ndarray( 2.0, 3.0, 4.0, out, 1, 0 ); | ||
| // out => <Float64Array>[ ~1.5513, ~5.1569, ~0.9665, ~0.2567, ~0.7497, ~0.6618 ] | ||
| ``` | ||
|
|
||
| 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 ] ); | ||
|
|
||
| dlasv2.ndarray( 2.0, 3.0, 4.0, out, 1, 1 ); | ||
| // out => <Float64Array>[ 0.0, ~1.5513, ~5.1569, ~0.9665, ~0.2567, ~0.7497, ~0.6618 ] | ||
| ``` | ||
|
|
||
| </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 ] ); | ||
|
|
||
| dlasv2( 1.0, 1e6, 2.0, out ); | ||
| console.log( out ); | ||
|
|
||
| dlasv2.ndarray( 1.0, 1e6, 2.0, out, 1, 0 ); | ||
| 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 | ||
|
|
||
| [@stdlib/array/float64]: https://stdlib.io/docs/api/latest/@stdlib/array/float64 | ||
|
|
||
| [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.links --> | ||
69 changes: 69 additions & 0 deletions
69
lib/node_modules/@stdlib/lapack/base/dlasv2/benchmark/benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /** | ||
| * @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 Float64Array = require( '@stdlib/array/float64' ); | ||
| var format = require( '@stdlib/string/format' ); | ||
| 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' | ||
| }; | ||
|
|
||
|
|
||
| // MAIN // | ||
|
|
||
| bench( format( '%s', pkg ), function benchmark( b ) { | ||
| var out; | ||
| var N; | ||
| var f; | ||
| var g; | ||
| var h; | ||
| var i; | ||
|
|
||
| N = 100; | ||
| f = uniform( N, -500.0, 500.0, options ); | ||
| g = uniform( N, -500.0, 500.0, options ); | ||
| h = uniform( N, -500.0, 500.0, options ); | ||
|
|
||
| out = new Float64Array( 6 ); | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| dlasv2( f[ i%f.length ], g[ i%g.length ], h[ i%h.length ], out ); | ||
| if ( isnan( out[ i%out.length ] ) ) { | ||
| b.fail( 'should not return NaN' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( isnan( out[ i%out.length ] ) ) { | ||
| b.fail( 'should not return NaN' ); | ||
| } | ||
| b.pass( 'benchmark finished' ); | ||
| b.end(); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is it just me or is the latex rendering messed up for you guys as well @kgryte @prajjwalbajpai
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.