Skip to content

feat: add lapack/base/dlartg #7596

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
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

aayush0325
Copy link
Member

Description

What is the purpose of this pull request?

This pull request:

  • adds lapack/base/dlartg

Related Issues

Does this pull request have any related issues?

No.

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

---
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: 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: na
  - 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: 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: na
  - 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: 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: 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: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - 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: na
  - 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: passed
  - 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: 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: 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: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@aayush0325 aayush0325 marked this pull request as draft July 9, 2025 13:28
@stdlib-bot stdlib-bot added LAPACK Issue or pull request related to the Linear Algebra Package (LAPACK). Needs Review A pull request which needs code review. and removed Needs Review A pull request which needs code review. labels Jul 9, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Jul 9, 2025

Coverage Report

Package Statements Branches Functions Lines
lapack/base/dlartg $\color{green}355/355$
$\color{green}+100.00\%$
$\color{green}17/17$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}355/355$
$\color{green}+100.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: passed
  - task: lint_package_json
    status: passed
  - 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: 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
---
---
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: passed
  - 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: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@aayush0325 aayush0325 marked this pull request as ready for review July 10, 2025 08:58
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jul 10, 2025
@aayush0325 aayush0325 added GSoC Google Summer of Code. gsoc: 2025 Google Summer of Code (2025). labels Jul 10, 2025
Comment on lines +27 to +28
`dlartg` constructs a Givens rotation for a two-dimensional vector such that the following equation is satisfied:

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`dlartg` constructs a Givens rotation for a two-dimensional vector such that the following equation is satisfied:
This routine constructs a Givens rotation for a two-dimensional vector such that the following equation is satisfied:


# dlartg

> LAPACK routine to construct a Givens rotation of a two-dimensional vector that zeros out the second component.
Copy link
Member

Choose a reason for hiding this comment

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

@aayush0325 I'm a little confused. What is meant by a "two-dimensional" vector? Vectors are, by definition, one dimensional. Are you meaning a column matrix?

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe you are intending a two-element vector?

Comment on lines +74 to +78
- **F**: single element array representing the first component of the vector to be rotated as a [`Float64Array`][mdn-float64array].
- **G**: single element array representing the second component of the vector to be rotated as a [`Float64Array`][mdn-float64array].
- **C**: single element array overwritten by the cosine of the rotation as a [`Float64Array`][mdn-float64array].
- **S**: single element array overwritten by the sine of the rotation as a [`Float64Array`][mdn-float64array].
- **R**: single element array overwritten by the length of the rotated vector as a [`Float64Array`][mdn-float64array].
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- **F**: single element array representing the first component of the vector to be rotated as a [`Float64Array`][mdn-float64array].
- **G**: single element array representing the second component of the vector to be rotated as a [`Float64Array`][mdn-float64array].
- **C**: single element array overwritten by the cosine of the rotation as a [`Float64Array`][mdn-float64array].
- **S**: single element array overwritten by the sine of the rotation as a [`Float64Array`][mdn-float64array].
- **R**: single element array overwritten by the length of the rotated vector as a [`Float64Array`][mdn-float64array].
- **F**: [`Float64Array`][mdn-float64array] containing a single element representing the first component of the vector to be rotated.
- **G**: [`Float64Array`][mdn-float64array] containing a single element representing the second component of the vector to be rotated
- **C**: [`Float64Array`][mdn-float64array] containing a single element which is overwritten by the cosine of the rotation.
- **S**: [`Float64Array`][mdn-float64array] containing a single element which is overwritten by the sine of the rotation.
- **R**: [`Float64Array`][mdn-float64array] containing a single element which is overwritten by the length of the rotated vector.


The function has the following parameters:

- **F**: single element array representing the first component of the vector to be rotated as a [`Float64Array`][mdn-float64array].
Copy link
Member

Choose a reason for hiding this comment

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

Same comments as above.

The function has the following parameters:

- **F**: single element array representing the first component of the vector to be rotated as a [`Float64Array`][mdn-float64array].
- **offsetF**: starting index for `F`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- **offsetF**: starting index for `F`.
- **offsetF**: index of the element in `F`.

It is somewhat awkward to say "starting index" when we are talking about only a single element. We can be more precise, IMO.

Applies here and below and likely elsewhere throughout this PR.

* ```
*
* @private
* @param {Float64Array} F - single element array representing the first component of the vector to be rotated
Copy link
Member

Choose a reason for hiding this comment

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

For the descriptions, all the same comments.

var dlamch = require( '@stdlib/lapack/base/dlamch' );
var sqrt = require( '@stdlib/math/base/special/sqrt' );
var abs = require( '@stdlib/math/base/special/fast/abs' );
var sign = require( '@stdlib/math/base/special/copysign' );
Copy link
Member

Choose a reason for hiding this comment

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

Prefer the alias copysign. sign means something else in other contexts.

R[ offsetR ] = sign( d, F[ offsetF ] );
S[ offsetS ] = G[ offsetG ] / R[ offsetR ];
} else {
u = min( safmax, max( safmin, f1, g1 ) );
Copy link
Member

Choose a reason for hiding this comment

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

Prefer two calls to fast max, rather than using maxn; e.g., max( max( safmin, f1 ), g1 ). Variadic functions are likely to end up in de-optimization hell. Here, we want to encourage compiler inlining.

u = min( safmax, max( safmin, f1, g1 ) );
fs = F[ offsetF ] / u;
gs = G[ offsetG ] / u;
d = sqrt( (fs*fs) + (gs*gs) );
Copy link
Member

Choose a reason for hiding this comment

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

This looks like hypot. Prefer that to avoid unnecessary underflow/overflow. I am surprised that LAPACK does not use hypot and/or the LAPACK equivalent routine.

S[ offsetS ] = sign( 1.0, G[ offsetG ] );
R[ offsetR ] = g1;
} else if ( f1 > rtmin && f1 < rtmax && g1 > rtmin && g1 < rtmax ) {
d = sqrt( (F[ offsetF ]*F[ offsetF ]) + (G[ offsetG ]*G[ offsetG ]) );
Copy link
Member

Choose a reason for hiding this comment

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

Same thing. This is hypot.

@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 Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GSoC Google Summer of Code. gsoc: 2025 Google Summer of Code (2025). LAPACK Issue or pull request related to the Linear Algebra Package (LAPACK). Needs Changes Pull request which needs changes before being merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants