-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add lapack/base/dlaisnan
#12183
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,182 @@ | ||||||
| <!-- | ||||||
|
|
||||||
| @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. | ||||||
|
|
||||||
| --> | ||||||
|
|
||||||
| # dlaisnan | ||||||
|
|
||||||
| > LAPACK auxiliary routine to test input for NaN by comparing two double-precision floating-point arguments for inequality. | ||||||
|
|
||||||
| <section class="usage"> | ||||||
|
|
||||||
| ## Usage | ||||||
|
|
||||||
| ```javascript | ||||||
| var dlaisnan = require( '@stdlib/lapack/base/dlaisnan' ); | ||||||
| ``` | ||||||
|
|
||||||
| #### dlaisnan( DIN1, DIN2 ) | ||||||
|
|
||||||
| Tests whether two double-precision floating-point arguments are unequal and thus at least one is NaN. | ||||||
|
|
||||||
| ```javascript | ||||||
| var bool = dlaisnan( NaN, NaN ); | ||||||
| // returns true | ||||||
|
|
||||||
| bool = dlaisnan( NaN, 5.0 ); | ||||||
| // returns true | ||||||
|
|
||||||
| bool = dlaisnan( 5.0, 5.0 ); | ||||||
| // returns false | ||||||
| ``` | ||||||
|
|
||||||
| The function has the following parameters: | ||||||
|
|
||||||
| - **DIN1**: first number to compare. | ||||||
| - **DIN2**: second number to compare. | ||||||
|
|
||||||
| </section> | ||||||
|
|
||||||
| <!-- /.usage --> | ||||||
|
|
||||||
| <section class="notes"> | ||||||
|
|
||||||
| ## 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`. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a link to lapack isnan too |
||||||
| - `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 )`). | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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`. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| </section> | ||||||
|
|
||||||
| <!-- /.notes --> | ||||||
|
|
||||||
| <section class="examples"> | ||||||
|
|
||||||
| ## Examples | ||||||
|
|
||||||
| <!-- eslint no-undef: "error" --> | ||||||
|
|
||||||
| ```javascript | ||||||
| var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); | ||||||
| var logEachMap = require( '@stdlib/console/log-each-map' ); | ||||||
| var dlaisnan = require( '@stdlib/lapack/base/dlaisnan' ); | ||||||
|
|
||||||
| var opts = { | ||||||
| 'dtype': 'float64' | ||||||
| }; | ||||||
| var x = discreteUniform( 100, -50, 50, opts ); | ||||||
| var y = discreteUniform( 100, -50, 50, opts ); | ||||||
|
|
||||||
| logEachMap( 'dlaisnan( %d, %d ) = %s', x, y, dlaisnan ); | ||||||
| ``` | ||||||
|
|
||||||
| </section> | ||||||
|
|
||||||
| <!-- /.examples --> | ||||||
|
|
||||||
| <!-- C interface documentation. --> | ||||||
|
|
||||||
| * * * | ||||||
|
|
||||||
| <section class="c"> | ||||||
|
|
||||||
| ## C APIs | ||||||
|
|
||||||
| <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> | ||||||
|
|
||||||
| <section class="intro"> | ||||||
|
|
||||||
| </section> | ||||||
|
|
||||||
| <!-- /.intro --> | ||||||
|
|
||||||
| <!-- C usage documentation. --> | ||||||
|
|
||||||
| <section class="usage"> | ||||||
|
|
||||||
| ### Usage | ||||||
|
|
||||||
| ```c | ||||||
| TODO | ||||||
| ``` | ||||||
|
|
||||||
| #### TODO | ||||||
|
|
||||||
| TODO. | ||||||
|
|
||||||
| ```c | ||||||
| TODO | ||||||
| ``` | ||||||
|
|
||||||
| TODO | ||||||
|
|
||||||
| ```c | ||||||
| TODO | ||||||
| ``` | ||||||
|
|
||||||
| </section> | ||||||
|
|
||||||
| <!-- /.usage --> | ||||||
|
|
||||||
| <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||||||
|
|
||||||
| <section class="notes"> | ||||||
|
|
||||||
| </section> | ||||||
|
|
||||||
| <!-- /.notes --> | ||||||
|
|
||||||
| <!-- C API usage examples. --> | ||||||
|
|
||||||
| <section class="examples"> | ||||||
|
|
||||||
| ### Examples | ||||||
|
|
||||||
| ```c | ||||||
| TODO | ||||||
| ``` | ||||||
|
|
||||||
| </section> | ||||||
|
|
||||||
| <!-- /.examples --> | ||||||
|
|
||||||
| </section> | ||||||
|
|
||||||
| <!-- /.c --> | ||||||
|
|
||||||
| <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||||||
|
|
||||||
| <section class="related"> | ||||||
|
|
||||||
| </section> | ||||||
|
|
||||||
| <!-- /.related --> | ||||||
|
|
||||||
| <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||||||
|
|
||||||
| <section class="links"> | ||||||
|
|
||||||
| [lapack]: https://www.netlib.org/lapack/explore-html/ | ||||||
|
|
||||||
| [lapack-dlaisnan]: https://www.netlib.org/lapack/explore-html/d3/d22/group__laisnan_gad49d1fe3d6890e9c4f60e0429abab3c9.html | ||||||
|
|
||||||
| </section> | ||||||
|
|
||||||
| <!-- /.links --> | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /** | ||
| * @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
| var uniform = require( '@stdlib/random/array/uniform' ); | ||
| var pkg = require( './../package.json' ).name; | ||
| var dlaisnan = require( './../lib' ); | ||
|
|
||
|
|
||
| // MAIN // | ||
|
|
||
| bench( pkg, function benchmark( b ) { | ||
| var len; | ||
| var x; | ||
| var y; | ||
| var z; | ||
| var i; | ||
|
|
||
| len = 100; | ||
| x = uniform( len, -50, 50 ); | ||
| y = uniform( len, -50, 50 ); | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| z = dlaisnan( x[ i % len ], y[ i % len ] ); | ||
| if ( isnan( z ) ) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please follow the pattern in |
||
| b.fail( 'should not return NaN' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( isnan( z ) ) { | ||
| b.fail( 'should not return NaN' ); | ||
| } | ||
| b.pass( 'benchmark finished' ); | ||
| b.end(); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
|
|
||
| {{alias}}( DIN1, DIN2 ) | ||
| Tests whether two double-precision floating-point arguments are unequal | ||
| and thus at least one is NaN. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| DIN1: number | ||
| First number to compare. | ||
|
|
||
| DIN2: number | ||
| Second number to compare. | ||
|
|
||
| Returns | ||
| ------- | ||
| bool: boolean | ||
| Boolean indicating whether the arguments are unequal. | ||
|
|
||
| Examples | ||
| -------- | ||
| > var bool = {{alias}}( NaN, NaN ) | ||
| true | ||
| > bool = {{alias}}( NaN, 5.0 ) | ||
| true | ||
| > bool = {{alias}}( 5.0, 5.0 ) | ||
| false | ||
|
|
||
| See Also | ||
| -------- |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * @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. | ||
| */ | ||
|
|
||
| // TypeScript Version: 4.1 | ||
|
|
||
| /** | ||
| * LAPACK auxiliary routine to test input for NaN by comparing two double-precision floating-point arguments for inequality. | ||
| * | ||
| * @param DIN1 - first number to compare | ||
| * @param DIN2 - second number to compare | ||
| * @returns boolean indicating whether the arguments are unequal | ||
| * | ||
| * @example | ||
| * var bool = dlaisnan( NaN, NaN ); | ||
| * // returns true | ||
| * | ||
| * @example | ||
| * var bool = dlaisnan( 5.0, 5.0 ); | ||
| * // returns false | ||
| */ | ||
| declare function dlaisnan( DIN1: number, DIN2: number ): boolean; | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| export = dlaisnan; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * @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. | ||
| */ | ||
|
|
||
| import dlaisnan = require( './index' ); | ||
|
|
||
|
|
||
| // TESTS // | ||
|
|
||
| // The function returns a boolean... | ||
| { | ||
| dlaisnan( 8, 2 ); // $ExpectType boolean | ||
| } | ||
|
|
||
| // The compiler throws an error if the function is provided values other than two numbers... | ||
| { | ||
| dlaisnan( true, 3 ); // $ExpectError | ||
| dlaisnan( false, 2 ); // $ExpectError | ||
| dlaisnan( '5', 1 ); // $ExpectError | ||
| dlaisnan( [], 1 ); // $ExpectError | ||
| dlaisnan( {}, 2 ); // $ExpectError | ||
| dlaisnan( ( x: number ): number => x, 2 ); // $ExpectError | ||
|
|
||
| dlaisnan( 9, true ); // $ExpectError | ||
| dlaisnan( 9, false ); // $ExpectError | ||
| dlaisnan( 5, '5' ); // $ExpectError | ||
| dlaisnan( 8, [] ); // $ExpectError | ||
| dlaisnan( 9, {} ); // $ExpectError | ||
| dlaisnan( 8, ( x: number ): number => x ); // $ExpectError | ||
|
|
||
| dlaisnan( [], true ); // $ExpectError | ||
| dlaisnan( {}, false ); // $ExpectError | ||
| dlaisnan( false, '5' ); // $ExpectError | ||
| dlaisnan( {}, [] ); // $ExpectError | ||
| dlaisnan( '5', ( x: number ): number => x ); // $ExpectError | ||
| } | ||
|
|
||
| // The compiler throws an error if the function is provided insufficient arguments... | ||
| { | ||
| dlaisnan(); // $ExpectError | ||
| dlaisnan( 3 ); // $ExpectError | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.