Skip to content

feat: add lapack/base/dlaisnan#12183

Open
iampratik13 wants to merge 2 commits into
stdlib-js:developfrom
iampratik13:lapack/dlaisnan
Open

feat: add lapack/base/dlaisnan#12183
iampratik13 wants to merge 2 commits into
stdlib-js:developfrom
iampratik13:lapack/dlaisnan

Conversation

@iampratik13
Copy link
Copy Markdown
Member


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: passed
  • 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 ---

Resolves none.

Description

What is the purpose of this pull request?

This pull request:

  • feat: add lapack/base/dlaisnan

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

  • None

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.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

{{TODO: add disclosure if applicable}}


@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: passed
  - task: lint_package_json
    status: passed
  - task: lint_repl_help
    status: passed
  - 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
---
@iampratik13 iampratik13 requested a review from a team May 17, 2026 19:03
@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. labels May 17, 2026
@stdlib-bot
Copy link
Copy Markdown
Contributor

stdlib-bot commented May 17, 2026

Coverage Report

Package Statements Branches Functions Lines
lapack/base/dlaisnan $\color{green}96/96$
$\color{green}+0.00%$
$\color{green}3/3$
$\color{green}+0.00%$
$\color{green}1/1$
$\color{green}+0.00%$
$\color{green}96/96$
$\color{green}+0.00%$

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

@iampratik13
Copy link
Copy Markdown
Member Author

/stdlib update-copyright-years

@stdlib-bot stdlib-bot added the bot: In Progress Pull request is currently awaiting automation. label May 17, 2026
@stdlib-bot stdlib-bot removed the bot: In Progress Pull request is currently awaiting automation. label May 17, 2026
@iampratik13 iampratik13 added bot: In Progress Pull request is currently awaiting automation. GSoC Google Summer of Code. gsoc: 2026 Google Summer of Code (2026). labels May 17, 2026
@iampratik13 iampratik13 requested a review from anandkaranubc May 17, 2026 19:13
@iampratik13 iampratik13 removed the bot: In Progress Pull request is currently awaiting automation. label May 17, 2026
if ( typeof out !== 'number' ) {
b.fail( 'should return a number' );
z = dlaisnan( x[ i % len ], y[ i % len ] );
if ( isnan( z ) ) {
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.

dlaisnan returns a boolean, but this benchmark uses @stdlib/math/base/assert/is-nan on the result. isnan(true) / isnan(false) are always false, so this guard never fails and doesn’t validate the return type.

Copy link
Copy Markdown
Contributor

@anandkaranubc anandkaranubc May 17, 2026

Choose a reason for hiding this comment

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

Please follow the pattern in @stdlib/math/base/assert/is-nan/benchmark/benchmark.js

/**
* Reinterpret a `Float16Array` as a `Uint16Array`.
* Tests whether two double-precision floating-point arguments are unequal and thus at least one is NaN.
Copy link
Copy Markdown
Contributor

@anandkaranubc anandkaranubc May 17, 2026

Choose a reason for hiding this comment

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

The summary says the function tests inequality “and thus at least one is NaN.” That’s only true when both arguments are the same value

For dlaisnan(1.0, 2.0) the result is true with no NaN involved.

/**
* Reinterpret a `Float16Array` as a `Uint16Array`.
* Tests whether two double-precision floating-point arguments are unequal and thus at least one is NaN.
Copy link
Copy Markdown
Contributor

@anandkaranubc anandkaranubc May 17, 2026

Choose a reason for hiding this comment

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

Suggested change
* Tests whether two double-precision floating-point arguments are unequal and thus at least one is NaN.
* Tests input for NaN by comparing two double-precision floating-point arguments for inequality.

I think leaving it as this, is better. Thoughts?

Copy link
Copy Markdown
Contributor

@anandkaranubc anandkaranubc May 17, 2026

Choose a reason for hiding this comment

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

+This change applies throughout the PR

* @example
* var Float16Array = require( '@stdlib/array/float16' );
* var reinterpret = require( '@stdlib/strided/base/reinterpret-float16' );
* - This routine exists solely to avoid over-optimization in DISNAN.
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.

Suggested change
* - This routine exists solely to avoid over-optimization in DISNAN.
* - This routine exists solely to avoid over-optimization in `disnan`.

## Notes

- `dlaisnan()` corresponds to the [LAPACK][LAPACK] auxiliary routine [`dlaisnan`][lapack-dlaisnan].
- This routine is not for general use. It exists solely to avoid over-optimization in `disnan`.
Copy link
Copy Markdown
Contributor

@anandkaranubc anandkaranubc May 17, 2026

Choose a reason for hiding this comment

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

Let's add a link to lapack isnan too

[lapack-disnan]: https://www.netlib.org/lapack/explore-html/d0/d4c/group__isnan_ga7aa3164d5df8d883754b0a70e9c7209c.html

<section class="notes">

## Notes

- `dlaisnan()` corresponds to the [LAPACK][LAPACK] auxiliary routine [`dlaisnan`][lapack-dlaisnan].
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.

Suggested change
- `dlaisnan()` corresponds to the [LAPACK][LAPACK] auxiliary routine [`dlaisnan`][lapack-dlaisnan].
- `dlaisnan()` corresponds to the [LAPACK][lapack] auxiliary routine [`dlaisnan`][lapack-dlaisnan].


- `dlaisnan()` corresponds to the [LAPACK][LAPACK] auxiliary routine [`dlaisnan`][lapack-dlaisnan].
- This routine is not for general use. It exists solely to avoid over-optimization in `disnan`.
- `dlaisnan` checks for NaNs by comparing its two arguments for inequality. `NaN` is the only floating-point value where `NaN != NaN` returns `true`. To check for NaNs, pass the same variable as both arguments (i.e., `dlaisnan( x, x )`).
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.

Suggested change
- `dlaisnan` checks for NaNs by comparing its two arguments for inequality. `NaN` is the only floating-point value where `NaN != NaN` returns `true`. To check for NaNs, pass the same variable as both arguments (i.e., `dlaisnan( x, x )`).
- `dlaisnan` checks for NaNs by comparing its two arguments for inequality. `NaN` is the only floating-point value where `NaN !== NaN` returns `true`. To check for NaNs, pass the same variable as both arguments (i.e., `dlaisnan( x, x )`).

- `dlaisnan()` corresponds to the [LAPACK][LAPACK] auxiliary routine [`dlaisnan`][lapack-dlaisnan].
- This routine is not for general use. It exists solely to avoid over-optimization in `disnan`.
- `dlaisnan` checks for NaNs by comparing its two arguments for inequality. `NaN` is the only floating-point value where `NaN != NaN` returns `true`. To check for NaNs, pass the same variable as both arguments (i.e., `dlaisnan( x, x )`).
- The function returns `true` whenever the two arguments are unequal, not only when one is NaN. This matches the Fortran reference implementation which simply returns `DIN1.NE.DIN2`.
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.

Suggested change
- The function returns `true` whenever the two arguments are unequal, not only when one is NaN. This matches the Fortran reference implementation which simply returns `DIN1.NE.DIN2`.
- The function returns `true` whenever the two arguments are unequal, not only when one is `NaN`. This matches the Fortran reference implementation which simply returns `DIN1.NE.DIN2`.

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.

I think we can also include

tape( 'the function returns expected values when passed the same variable as both arguments', function test( t ) {
	var x;
	var bool;

	x = NaN;
	bool = dlaisnan( x, x );
	t.strictEqual( bool, true, 'returns expected value' );

	x = 5.0;
	bool = dlaisnan( x, x );
	t.strictEqual( bool, false, 'returns expected value' );

	x = 0.0;
	bool = dlaisnan( x, x );
	t.strictEqual( bool, false, 'returns expected value' );

	x = -0.0;
	bool = dlaisnan( x, x );
	t.strictEqual( bool, false, 'returns expected value' );

	x = PINF;
	bool = dlaisnan( x, x );
	t.strictEqual( bool, false, 'returns expected value' );

	t.end();
});

LAPACK documents NaN detection as passing the same variable twice: dlaisnan(x, x). The current tests use literals (e.g. dlaisnan(NaN, NaN) and dlaisnan(5.0, 5.0)), which don’t exercise that pattern or guard against an engine folding x === x.

Comment on lines +30 to +31
* @param {number} DIN1 - first number to compare
* @param {number} DIN2 - second number to compare
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.

Suggested change
* @param {number} DIN1 - first number to compare
* @param {number} DIN2 - second number to compare
* @param {number} DIN1 - first input number
* @param {number} DIN2 - second input number

Applies to other related files too.

@anandkaranubc anandkaranubc added Needs Changes Pull request which needs changes before being merged. JavaScript Issue involves or relates to JavaScript. and removed Needs Review A pull request which needs code review. labels May 17, 2026
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: 2026 Google Summer of Code (2026). 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants