feat: add lapack/base/dlabad#12264
Conversation
---
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
---
Coverage Report
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
---
There was a problem hiding this comment.
/**
* @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
There was a problem hiding this comment.
Agreed. Providing different values is desirable.
There was a problem hiding this comment.
/**
* @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.
| function dlabad( SMALL, offsetSMALL, LARGE, offsetLARGE ) { | ||
| if ( log10( LARGE[ offsetLARGE ] ) > 2000.0 ) { | ||
| SMALL[ offsetSMALL ] = sqrt( SMALL[ offsetSMALL ] ); | ||
| LARGE[ offsetLARGE ] = sqrt( LARGE[ offsetLARGE ] ); | ||
| } | ||
| } |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
| * 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 ); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ) |
There was a problem hiding this comment.
| #### dlabad.ndarray( SMALL, offsetSMALL, LARGE, offsetLARGE ) | |
| #### dlabad.ndarray( small, offsetSmall, large, offsetLarge ) |
There was a problem hiding this comment.
Applies here and throughout this PR.
|
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. |
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes. report:
Resolves none.
Description
This pull request:
lapack/base/dlabadRelated Issues
This pull request has the following related issues:
Questions
No.
Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
{{TODO: add disclosure if applicable}}
@stdlib-js/reviewers