Skip to content

feat: add lapack/base/dlabad#12264

Closed
iampratik13 wants to merge 3 commits into
stdlib-js:developfrom
iampratik13:lapack/dlabad
Closed

feat: add lapack/base/dlabad#12264
iampratik13 wants to merge 3 commits into
stdlib-js:developfrom
iampratik13:lapack/dlabad

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_pkg_readmes status: passed
  • task: lint_markdown_docs status: na
  • task: lint_markdown status: na
  • 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/dlabad

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_pkg_readmes
    status: passed
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - 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 24, 2026 11:36
@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 24, 2026
@iampratik13 iampratik13 marked this pull request as draft May 24, 2026 11:37
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label May 24, 2026
@stdlib-bot

stdlib-bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
lapack/base/dlabad $\color{red}269/272$
$\color{green}+0.00%$
$\color{red}10/11$
$\color{green}+0.00%$
$\color{green}3/3$
$\color{green}+0.00%$
$\color{red}269/272$
$\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_pkg_readmes
    status: passed
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - 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
---
---
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_pkg_readmes
    status: na
  - task: lint_markdown_docs
    status: na
  - 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
---
@iampratik13 iampratik13 marked this pull request as ready for review May 24, 2026 14:22
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label May 24, 2026
@iampratik13 iampratik13 added Feature Issue or pull request for adding a new feature. JavaScript Issue involves or relates to JavaScript. GSoC Google Summer of Code. gsoc: 2026 Google Summer of Code (2026). labels May 24, 2026
@iampratik13 iampratik13 requested a review from anandkaranubc May 24, 2026 14:23

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.

/**
* @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 Float64Array = require( '@stdlib/array/float64' );
var FLOAT64_MAX = require( '@stdlib/constants/float64/max' );
var FLOAT64_SMALLEST_NORMAL = require( '@stdlib/constants/float64/smallest-normal' );
var pkg = require( './../package.json' ).name;
var dlabad = require( './../lib' );


// VARIABLES //

var options = {
	'dtype': 'float64'
};


// MAIN //

bench( pkg, function benchmark( b ) {
	var LARGE;
	var SMALL;
	var large;
	var small;
	var N;
	var i;
	var j;
	var k;

	N = 100;
	small = uniform( N, FLOAT64_SMALLEST_NORMAL, 1.0e-200, options );
	large = uniform( N, 1.0e+200, FLOAT64_MAX, options );

	SMALL = new Float64Array( 1 );
	LARGE = new Float64Array( 1 );

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		j = i % N;
		k = ( i+1 ) % N;
		SMALL[ 0 ] = small[ j ];
		LARGE[ 0 ] = large[ k ];
		dlabad( SMALL, LARGE );
		if ( isnan( SMALL[ 0 ] ) || isnan( LARGE[ 0 ] ) ) {
			b.fail( 'should not return NaN' );
		}
	}
	b.toc();
	if ( isnan( SMALL[ 0 ] ) || isnan( LARGE[ 0 ] ) ) {
		b.fail( 'should not return NaN' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

I think this approach seems more consistent. Reference: stdlib/lapack/base/dladiv

@anandkaranubc anandkaranubc May 26, 2026

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.

Thoughts, @iampratik13?

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.

Agreed. Providing different values is desirable.

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.

/**
* @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 FLOAT64_MAX = require( '@stdlib/constants/float64/max' );
var FLOAT64_SMALLEST_NORMAL = require( '@stdlib/constants/float64/smallest-normal' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var dlabad = require( './../lib/ndarray.js' );


// VARIABLES //

var options = {
	'dtype': 'float64'
};


// MAIN //

bench( format( '%s:ndarray', pkg ), function benchmark( b ) {
	var SMALL;
	var LARGE;
	var N;
	var i;
	var j;
	var k;

	N = 100;
	SMALL = uniform( N, FLOAT64_SMALLEST_NORMAL, 1.0e-200, options );
	LARGE = uniform( N, 1.0e+200, FLOAT64_MAX, options );

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		j = i % N;
		k = ( i+1 ) % N;
		dlabad( SMALL, j, LARGE, k );
		if ( isnan( SMALL[ j ] ) || isnan( LARGE[ k ] ) ) {
			b.fail( 'should not return NaN' );
		}
	}
	b.toc();
	if ( isnan( SMALL[ j ] ) || isnan( LARGE[ k ] ) ) {
		b.fail( 'should not return NaN' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

Similar version.

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.

Agreed.

Comment on lines +49 to +54
function dlabad( SMALL, offsetSMALL, LARGE, offsetLARGE ) {
if ( log10( LARGE[ offsetLARGE ] ) > 2000.0 ) {
SMALL[ offsetSMALL ] = sqrt( SMALL[ offsetSMALL ] );
LARGE[ offsetLARGE ] = sqrt( LARGE[ offsetLARGE ] );
}
}

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'm unsure how useful this is in JS. We only have IEEE-754 doubles, so log10( LARGE ) never exceeds 2000 and the sqrt adjustment never runs. It’s a no-op in practice, like modern LAPACK describes. Fine for LAPACK compatibility, but probably not something JS apps would call directly.

Suggestions, @kgryte... Thanks!

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.

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 am in agreement. We should NOT be calling this from JS implementations. This is really only useful as a Fortran implementation for backward compat reasons.

It is fine to add, but the package should be unused in our implementations, as it is highly unlikely for a JavaScript runtime to not be IEEE 754 compliant. Once we add the C/Fortran implementations, we can use the Fortran implementation to ensure 1:1 behavior with reference LAPACK.

This package should not be considered a prerequisite for JS implementations.

Also, @iampratik13 all of the ALLCAPS variable names need to go away. That does not follow stdlib conventions.

*/
interface Routine {
/**
* Adjust the underflow and overflow thresholds if the exponent range is very large.

@anandkaranubc anandkaranubc May 26, 2026

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
* Adjust the underflow and overflow thresholds if the exponent range is very large.
* Adjusts the double-precision underflow and overflow thresholds when the exponent range is very large.

* // LARGE => <Float64Array>[ 1.7976931348623157e+308 ]
*/
function dlabad( SMALL, offsetSMALL, LARGE, offsetLARGE ) {
return base( SMALL, offsetSMALL, LARGE, offsetLARGE );

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.

For this package, it is not necessary to have a "base" implementation. We have "base" implementations whenever both the main and ndarray exports need to do input argument validation and need to leverage a single common implementation in order to avoid duplicate argument validation. In this case, the ndarray interface is not performing argument validation, so the duplicate validation concern is not relevant.

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.

Meaning, the main export can call the ndarray interface directly.

- **SMALL**: [`Float64Array`][mdn-float64array] containing a single element equal to the underflow threshold.
- **LARGE**: [`Float64Array`][mdn-float64array] containing a single element equal to the overflow threshold.

#### dlabad.ndarray( SMALL, offsetSMALL, LARGE, offsetLARGE )

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
#### dlabad.ndarray( SMALL, offsetSMALL, LARGE, offsetLARGE )
#### dlabad.ndarray( small, offsetSmall, large, offsetLarge )

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.

Applies here and throughout this PR.

@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 Jun 1, 2026
@iampratik13

Copy link
Copy Markdown
Member Author

cc @anandkaranubc and @kgryte, thanks for the reviews! Since we assume IEEE 754 compliance, I’ll close this PR and focus on the remaining LAPACK implementations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Issue or pull request for adding a new feature. 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.

4 participants