Skip to content

feat: add lapack/base/dlasv2#2819

Open
Pranavchiku wants to merge 17 commits into
stdlib-js:developfrom
Pranavchiku:dlasv2
Open

feat: add lapack/base/dlasv2#2819
Pranavchiku wants to merge 17 commits into
stdlib-js:developfrom
Pranavchiku:dlasv2

Conversation

@Pranavchiku
Copy link
Copy Markdown
Member

Towards #2464.

Description

What is the purpose of this pull request?

This pull request adds JS implementation for lapack/base/dlasv2

Related Issues

Does this pull request have any related issues?

NA

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

@Pranavchiku Pranavchiku added Feature Issue or pull request for adding a new feature. Base Issue or pull requests related to "low-level" functionality oriented toward library consumers. JavaScript Issue involves or relates to JavaScript. LAPACK Issue or pull request related to the Linear Algebra Package (LAPACK). labels Aug 22, 2024
@Pranavchiku Pranavchiku marked this pull request as ready for review August 22, 2024 03:56
Comment thread lib/node_modules/@stdlib/lapack/base/dlasv2/lib/base.js Outdated
@kgryte kgryte added the Needs Changes Pull request which needs changes before being merged. label Sep 17, 2024
@prajjwalbajpai prajjwalbajpai requested a review from a team May 12, 2026 16:28
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label May 12, 2026
@stdlib-bot
Copy link
Copy Markdown
Contributor

stdlib-bot commented May 12, 2026

Coverage Report

Package Statements Branches Functions Lines
lapack/base/dlasv2 $\color{green}464/464$
$\color{green}+0.00%$
$\color{green}30/30$
$\color{green}+0.00%$
$\color{green}3/3$
$\color{green}+0.00%$
$\color{green}464/464$
$\color{green}+0.00%$

The above coverage report was generated for the changes in this PR.

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: passed
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: passed
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: passed
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: passed
  - task: lint_license_headers
    status: passed
---
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: passed
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@prajjwalbajpai
Copy link
Copy Markdown
Contributor

@kgryte I have made some changes and would like to know your thoughts on the same.

@kgryte kgryte removed the Needs Changes Pull request which needs changes before being merged. label May 12, 2026
*
* @private
*/
function main() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prajjwalbajpai This benchmarks needs to be refactored. The min/max iteration is pointless as the benchmark is not parameterized. We should use the unparameterized version of benchmarks.

* @private
* @returns {Function} benchmark function
*/
function createBenchmark( ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prajjwalbajpai Same thing. This benchmark is incorrect.

*
* var out = new Float64Array( 6 );
*
* out = dlasv2( 2.0, 3.0, 4.0, out );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* out = dlasv2( 2.0, 3.0, 4.0, out );
* dlasv2( 2.0, 3.0, 4.0, out );

No need to overwrite out here. Applies here and throughout this PR.

* 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 ]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using approximate values (e.g., ~1.5513), rather than full-precision, in order to guard against implementation drift invalidating all documentation. Applies here and throughout this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prajjwalbajpai This still needs to be updated to use approximate values. E.g.,

// out => <Float64Array>[ ~1.5513, ~4.1569, ... ]

This comment applies here and everywhere else.

Comment thread lib/node_modules/@stdlib/lapack/base/dlasv2/docs/repl.txt
> var out = new {{alias:@stdlib/array/float64}}( 6 );
> {{alias}}( 2.0, 3.0, 4.0, out );
> out[ 0 ]
1.5513263285176897
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing. Use approximate values.

Comment on lines +51 to +52
buffer, the offset parameters support indexing semantics based on starting
indices.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
buffer, the offset parameters support indexing semantics based on starting
indices.
buffer, the offset parameter support indexing semantics based on a starting
index.


dlasv2( data.F, data.G, data.H, out );
expected = data.out;
isApprox( t, out, expected, 1.0 );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isApprox( t, out, expected, 1.0 );
isApprox( t, out, expected, 1 );


dlasv2( data.F, data.G, data.H, out );
expected = data.out;
isApprox( t, out, expected, 1.0 );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isApprox( t, out, expected, 1.0 );
isApprox( t, out, expected, 1 );


dlasv2( data.F, data.G, data.H, out );
expected = data.out;
isApprox( t, out, expected, 1.0 );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isApprox( t, out, expected, 1.0 );
isApprox( t, out, expected, 1 );


dlasv2( data.F, data.G, data.H, out );
expected = data.out;
isApprox( t, out, expected, 1.0 );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isApprox( t, out, expected, 1.0 );
isApprox( t, out, expected, 1 );


dlasv2( data.F, data.G, data.H, out );
expected = data.out;
isApprox( t, out, expected, 1.0 );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isApprox( t, out, expected, 1.0 );
isApprox( t, out, expected, 1 );


dlasv2( data.F, data.G, data.H, out );
expected = data.out;
isApprox( t, out, expected, 1.0 );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isApprox( t, out, expected, 1.0 );
isApprox( t, out, expected, 1 );

expected = new Float64Array( [ 1.0, PINF, 0.0, 1.0, 0.0, 1.0 ] );
out = new Float64Array( 6 );
out = dlasv2( PINF, 2.0, 1.0, out );
isApprox( t, out, expected, 1.0 );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isApprox( t, out, expected, 1.0 );
isApprox( t, out, expected, 1 );


dlasv2( data.F, data.G, data.H, out );
expected = data.out;
isApprox( t, out, expected, 1.0 );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isApprox( t, out, expected, 1.0 );
isApprox( t, out, expected, 1 );

* @param {Object} t - test object
* @param {Collection} actual - actual values
* @param {Collection} expected - expected values
* @param {number} rtol - relative tolerance
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the same changes as proposed for the other test file.

t.end();
});

tape( 'the function computes the singular value decomposition of a triangular matrix with elements in increasing order (Negative Stride)', function test( t ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tape( 'the function computes the singular value decomposition of a triangular matrix with elements in increasing order (Negative Stride)', function test( t ) {
tape( 'the function computes the singular value decomposition of a triangular matrix with elements in increasing order (negative stride)', function test( t ) {

Applies here and below.

t.end();
});

tape( 'the function computes the singular value decomposition of a triangular matrix with elements in increasing order (Offset)', function test( t ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tape( 'the function computes the singular value decomposition of a triangular matrix with elements in increasing order (Offset)', function test( t ) {
tape( 'the function computes the singular value decomposition of a triangular matrix with elements in increasing order (offset)', function test( t ) {

Applies here and below.


<section class="intro">

The singular value decomposition of a 2x2 upper triangular matrix $ \begin{bmatrix} F & G \\ 0 & H \end{bmatrix}$ is given by -
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The singular value decomposition of a 2x2 upper triangular matrix $ \begin{bmatrix} F & G \\ 0 & H \end{bmatrix}$ is given by -
The singular value decomposition of a 2x2 upper triangular matrix $ \begin{bmatrix} F & G \\ 0 & H \end{bmatrix}$ is given by

Copy link
Copy Markdown
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left another round of comments. This is coming along.

@prajjwalbajpai Thank you for improving the tests. They are muuuuuch better. 🙌

@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels May 15, 2026
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: passed
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: passed
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: passed
  - task: lint_license_headers
    status: passed
---
@prajjwalbajpai prajjwalbajpai requested a review from kgryte May 15, 2026 03:43
@prajjwalbajpai
Copy link
Copy Markdown
Contributor

Made the changes.

@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label May 15, 2026
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Comment thread lib/node_modules/@stdlib/lapack/base/dlasv2/test/test.ndarray.js Outdated
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
* @param {Collection} expected - expected values
* @param {number} maxULPs - maximum allowed ULP difference
*/
function isApprox( t, actual, expected, maxULPs ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just recalled that this function is not necessary. You can replace all usage of isApprox below with @stdlib/assert/is-almost-same-float64array. Applies to this and the other test file.

Copy link
Copy Markdown
Contributor

@prajjwalbajpai prajjwalbajpai May 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. One thing I found interesting was:

If I directly create the expected array as

expected = data.out;

The isAlmostSameValueFloat64Array function was returning false. Hence, I had to wrap the array in Float64Array.

expected = new Float64Array( data.out );

This is something that is not done in other routines where fixtures are used.

Copy link
Copy Markdown
Member

@aayush0325 aayush0325 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks fine to me, please check the latex rendering issue!

var Float64Array = require( '@stdlib/array/float64' );
var dlasv2 = require( './../lib/' );

var out = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var out = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
var out = new Float64Array( 6 );

Comment on lines +226 to +232
out[ offsetOut ] = ssmin;
out[ offsetOut + strideOut ] = ssmax;
out[ offsetOut + ( 2 * strideOut ) ] = snr;
out[ offsetOut + ( 3 * strideOut ) ] = csr;
out[ offsetOut + ( 4 * strideOut ) ] = snl;
out[ offsetOut + ( 5 * strideOut ) ] = csl;
return out;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the index calculation can be done in fewer ops here


<section class="intro">

The singular value decomposition of a 2x2 upper triangular matrix $ \begin{bmatrix} F & G \\ 0 & H \end{bmatrix}$ is given by
Copy link
Copy Markdown
Member

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

Image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image looks fine for me

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would make sense to document how you're testing using fortran in a separate repository, like this repo this would help us both in terms of reviews and be a source of truth as more LAPACK PRs get queued for review over the next few weeks. imo its a good starting point, then we can consider keeping the fortran files itself in the repo but im not sure if that would achieve anything

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: passed
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---

<!-- </equation> -->

where `CSL`,`SNL`,`CSR`,`SNR` define orthogonal rotations and $\mathrm{SSMAX}^2, \mathrm{SSMIN}^2$ are the eigenvalues of $A^{T}A$.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is A here? assuming its the 2x2 input matrix you can write that above

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: passed
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Base Issue or pull requests related to "low-level" functionality oriented toward library consumers. Feature Issue or pull request for adding a new feature. JavaScript Issue involves or relates to JavaScript. LAPACK Issue or pull request related to the Linear Algebra Package (LAPACK). Needs Changes Pull request which needs changes before being merged. Needs Review A pull request which needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants