From 6ad90d9896caf2772d112e3e5bccd4664d585d20 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 12 Oct 2026 22:30:10 +0000 Subject: [PATCH] test: migrate `blas/base/zaxpy` to ULP-based assertions Replace the relative-tolerance `isApprox` helper with ULP difference testing via `@stdlib/assert/is-almost-same-value`, tightening each assertion to the minimum required ULP bound. Ref: https://github.com/stdlib-js/stdlib/issues/11352 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01TpH47f7GqLWYmKXoVNEzuu --- 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: skipped - 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 --- --- .../blas/base/zaxpy/test/test.ndarray.js | 33 +++++++---------- .../base/zaxpy/test/test.ndarray.native.js | 35 +++++++------------ .../blas/base/zaxpy/test/test.zaxpy.js | 31 ++++++---------- .../blas/base/zaxpy/test/test.zaxpy.native.js | 31 ++++++---------- 4 files changed, 47 insertions(+), 83 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/zaxpy/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/zaxpy/test/test.ndarray.js index bc313d9c0b05..68e81de7b21a 100644 --- a/lib/node_modules/@stdlib/blas/base/zaxpy/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/zaxpy/test/test.ndarray.js @@ -24,8 +24,7 @@ var tape = require( 'tape' ); var Float64Array = require( '@stdlib/array/float64' ); var Complex128Array = require( '@stdlib/array/complex128' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var EPS = require( '@stdlib/constants/float64/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var zaxpy = require( './../lib/ndarray.js' ); @@ -38,22 +37,14 @@ var zaxpy = require( './../lib/ndarray.js' ); * @param {Object} t - test object * @param {Collection} actual - actual values * @param {Collection} expected - expected values -* @param {number} rtol - relative tolerance +* @param {NonNegativeInteger} ulp - maximum allowed ULP difference */ -function isApprox( t, actual, expected, rtol ) { - var delta; - var tol; +function isApprox( t, actual, expected, ulp ) { var i; t.strictEqual( actual.length, expected.length, 'returns expected value' ); for ( i = 0; i < expected.length; i++ ) { - if ( actual[ i ] === expected[ i ] ) { - t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); - } else { - delta = abs( actual[ i ] - expected[ i ] ); - tol = rtol * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' ); } } @@ -131,7 +122,7 @@ tape( 'the function scales elements from `x` by `alpha` and adds the result to ` 0.8, -0.7 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 24 ); t.end(); }); @@ -195,7 +186,7 @@ tape( 'the function supports an `x` stride', function test( t ) { 0.8, -0.7 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 8 ); t.end(); }); @@ -259,7 +250,7 @@ tape( 'the function supports an `x` offset', function test( t ) { 0.8, -0.7 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 11 ); t.end(); }); @@ -323,7 +314,7 @@ tape( 'the function supports a `y` stride', function test( t ) { 0.32, // 4 -1.16 // 4 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 6 ); t.end(); }); @@ -387,7 +378,7 @@ tape( 'the function supports a `y` offset', function test( t ) { 0.8, -0.7 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 1 ); t.end(); }); @@ -513,7 +504,7 @@ tape( 'the function supports a negative `x` stride', function test( t ) { 0.8, -0.7 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 24 ); t.end(); }); @@ -577,7 +568,7 @@ tape( 'the function supports a negative `y` stride', function test( t ) { 0.52, // 1 -1.51 // 1 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 8 ); t.end(); }); @@ -641,6 +632,6 @@ tape( 'the function supports complex access patterns', function test( t ) { 0.32, // 1 -1.16 // 1 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 6 ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/zaxpy/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/zaxpy/test/test.ndarray.native.js index c0951fb971ad..54e7e6f33bec 100644 --- a/lib/node_modules/@stdlib/blas/base/zaxpy/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/zaxpy/test/test.ndarray.native.js @@ -25,8 +25,7 @@ var tape = require( 'tape' ); var Float64Array = require( '@stdlib/array/float64' ); var Complex128Array = require( '@stdlib/array/complex128' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var EPS = require( '@stdlib/constants/float64/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -47,22 +46,14 @@ var opts = { * @param {Object} t - test object * @param {Collection} actual - actual values * @param {Collection} expected - expected values -* @param {number} rtol - relative tolerance +* @param {NonNegativeInteger} ulp - maximum allowed ULP difference */ -function isApprox( t, actual, expected, rtol ) { - var delta; - var tol; +function isApprox( t, actual, expected, ulp ) { var i; t.strictEqual( actual.length, expected.length, 'returns expected value' ); for ( i = 0; i < expected.length; i++ ) { - if ( actual[ i ] === expected[ i ] ) { - t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); - } else { - delta = abs( actual[ i ] - expected[ i ] ); - tol = rtol * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' ); } } @@ -140,7 +131,7 @@ tape( 'the function scales elements from `x` by `alpha` and adds the result to ` 0.8, -0.7 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 24 ); t.end(); }); @@ -204,7 +195,7 @@ tape( 'if dcabs1( alpha ) === 0.0; the function returns the second input array u 0.8, -0.7 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 0 ); t.end(); }); @@ -268,7 +259,7 @@ tape( 'the function supports an `x` stride', opts, function test( t ) { 0.8, -0.7 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 8 ); t.end(); }); @@ -332,7 +323,7 @@ tape( 'the function supports an `x` offset', opts, function test( t ) { 0.8, -0.7 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 11 ); t.end(); }); @@ -396,7 +387,7 @@ tape( 'the function supports a `y` stride', opts, function test( t ) { 0.32, // 4 -1.16 // 4 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 6 ); t.end(); }); @@ -460,7 +451,7 @@ tape( 'the function supports a `y` offset', opts, function test( t ) { 0.8, -0.7 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 1 ); t.end(); }); @@ -563,7 +554,7 @@ tape( 'the function supports a negative `x` stride', opts, function test( t ) { 0.8, -0.7 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 24 ); t.end(); }); @@ -627,7 +618,7 @@ tape( 'the function supports a negative `y` stride', opts, function test( t ) { 0.52, // 1 -1.51 // 1 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 8 ); t.end(); }); @@ -691,6 +682,6 @@ tape( 'the function supports complex access patterns', opts, function test( t ) 0.32, // 1 -1.16 // 1 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 6 ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/zaxpy/test/test.zaxpy.js b/lib/node_modules/@stdlib/blas/base/zaxpy/test/test.zaxpy.js index c02ccd798e51..5f9b67edb3e0 100644 --- a/lib/node_modules/@stdlib/blas/base/zaxpy/test/test.zaxpy.js +++ b/lib/node_modules/@stdlib/blas/base/zaxpy/test/test.zaxpy.js @@ -24,8 +24,7 @@ var tape = require( 'tape' ); var Float64Array = require( '@stdlib/array/float64' ); var Complex128Array = require( '@stdlib/array/complex128' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var EPS = require( '@stdlib/constants/float64/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var zaxpy = require( './../lib/zaxpy.js' ); @@ -38,22 +37,14 @@ var zaxpy = require( './../lib/zaxpy.js' ); * @param {Object} t - test object * @param {Collection} actual - actual values * @param {Collection} expected - expected values -* @param {number} rtol - relative tolerance +* @param {NonNegativeInteger} ulp - maximum allowed ULP difference */ -function isApprox( t, actual, expected, rtol ) { - var delta; - var tol; +function isApprox( t, actual, expected, ulp ) { var i; t.strictEqual( actual.length, expected.length, 'returns expected value' ); for ( i = 0; i < expected.length; i++ ) { - if ( actual[ i ] === expected[ i ] ) { - t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); - } else { - delta = abs( actual[ i ] - expected[ i ] ); - tol = rtol * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' ); } } @@ -131,7 +122,7 @@ tape( 'the function scales elements from `x` by `alpha` and adds the result to ` 0.8, -0.7 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 24 ); t.end(); }); @@ -195,7 +186,7 @@ tape( 'the function supports an `x` stride', function test( t ) { 0.8, -0.7 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 8 ); t.end(); }); @@ -259,7 +250,7 @@ tape( 'the function supports a `y` stride', function test( t ) { 0.32, // 4 -1.16 // 4 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 6 ); t.end(); }); @@ -385,7 +376,7 @@ tape( 'the function supports negative `x` strides', function test( t ) { 0.8, -0.7 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 24 ); t.end(); }); @@ -449,7 +440,7 @@ tape( 'the function supports negative `y` strides', function test( t ) { 0.52, // 1 -1.51 // 1 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 8 ); t.end(); }); @@ -513,7 +504,7 @@ tape( 'the function supports complex access patterns', function test( t ) { 0.32, // 1 -1.16 // 1 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 6 ); t.end(); }); @@ -579,6 +570,6 @@ tape( 'the function supports view offsets', function test( t ) { -0.96 // 4 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 24 ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/zaxpy/test/test.zaxpy.native.js b/lib/node_modules/@stdlib/blas/base/zaxpy/test/test.zaxpy.native.js index d3e7808edfb8..ff77475878ae 100644 --- a/lib/node_modules/@stdlib/blas/base/zaxpy/test/test.zaxpy.native.js +++ b/lib/node_modules/@stdlib/blas/base/zaxpy/test/test.zaxpy.native.js @@ -25,8 +25,7 @@ var tape = require( 'tape' ); var Float64Array = require( '@stdlib/array/float64' ); var Complex128Array = require( '@stdlib/array/complex128' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var EPS = require( '@stdlib/constants/float64/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -47,22 +46,14 @@ var opts = { * @param {Object} t - test object * @param {Collection} actual - actual values * @param {Collection} expected - expected values -* @param {number} rtol - relative tolerance +* @param {NonNegativeInteger} ulp - maximum allowed ULP difference */ -function isApprox( t, actual, expected, rtol ) { - var delta; - var tol; +function isApprox( t, actual, expected, ulp ) { var i; t.strictEqual( actual.length, expected.length, 'returns expected value' ); for ( i = 0; i < expected.length; i++ ) { - if ( actual[ i ] === expected[ i ] ) { - t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); - } else { - delta = abs( actual[ i ] - expected[ i ] ); - tol = rtol * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( isAlmostSameValue( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' ); } } @@ -140,7 +131,7 @@ tape( 'the function scales elements from `x` by `alpha` and adds the result to ` 0.8, -0.7 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 24 ); t.end(); }); @@ -204,7 +195,7 @@ tape( 'the function supports an `x` stride', opts, function test( t ) { 0.8, -0.7 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 8 ); t.end(); }); @@ -268,7 +259,7 @@ tape( 'the function supports a `y` stride', opts, function test( t ) { 0.32, // 4 -1.16 // 4 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 6 ); t.end(); }); @@ -394,7 +385,7 @@ tape( 'the function supports negative `x` strides', opts, function test( t ) { 0.8, -0.7 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 24 ); t.end(); }); @@ -458,7 +449,7 @@ tape( 'the function supports negative `y` strides', opts, function test( t ) { 0.52, // 1 -1.51 // 1 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 8 ); t.end(); }); @@ -522,7 +513,7 @@ tape( 'the function supports complex access patterns', opts, function test( t ) 0.32, // 1 -1.16 // 1 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 6 ); t.end(); }); @@ -588,6 +579,6 @@ tape( 'the function supports view offsets', opts, function test( t ) { -0.96 // 4 ]); - isApprox( t, viewY, expected, 14.0 ); + isApprox( t, viewY, expected, 24 ); t.end(); });