From 61867fb97527dcd59c55ef3275ed1dbd91e0925a Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 15 Sep 2026 14:16:58 +0000 Subject: [PATCH] test: migrate `lapack/base/spttrf` to ULP-based assertions Migrate the `lapack/base/spttrf` tests from computed relative-tolerance comparisons to ULP-difference assertions using `@stdlib/number/float32/base/assert/is-almost-same-value`. Ref: https://github.com/stdlib-js/stdlib/issues/11352 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_016pbi1frD9BsfTzxAMAHerB --- .../lapack/base/spttrf/test/test.ndarray.js | 51 ++++++++++--------- .../lapack/base/spttrf/test/test.spttrf.js | 27 ++++------ 2 files changed, 36 insertions(+), 42 deletions(-) diff --git a/lib/node_modules/@stdlib/lapack/base/spttrf/test/test.ndarray.js b/lib/node_modules/@stdlib/lapack/base/spttrf/test/test.ndarray.js index ae50fce2d530..bec697ed6932 100644 --- a/lib/node_modules/@stdlib/lapack/base/spttrf/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/lapack/base/spttrf/test/test.ndarray.js @@ -24,8 +24,7 @@ var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); -var EPS = require( '@stdlib/constants/float32/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); var spttrf = require( './../lib/ndarray.js' ); @@ -38,22 +37,14 @@ var spttrf = 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( isAlmostSameValuef( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' ); } } @@ -104,10 +95,12 @@ tape( 'the function computes the `L * D * L^T` factorization of a real symmetric var expectedD; var expectedE; var info; + var ULP; var D; var E; var N; + ULP = 26; N = 3; D = new Float32Array( [ 4.0, 5.0, 6.0 ] ); @@ -118,8 +111,8 @@ tape( 'the function computes the `L * D * L^T` factorization of a real symmetric info = spttrf( N, D, 1, 0, E, 1, 0 ); t.strictEqual( info, 0, 'returns expected value' ); - isApprox( t, D, expectedD, 2.0 ); - isApprox( t, E, expectedE, 2.0 ); + isApprox( t, D, expectedD, ULP ); + isApprox( t, E, expectedE, ULP ); N = 7; @@ -131,8 +124,8 @@ tape( 'the function computes the `L * D * L^T` factorization of a real symmetric info = spttrf( N, D, 1, 0, E, 1, 0 ); t.strictEqual( info, 0, 'returns expected value' ); - isApprox( t, D, expectedD, 15.0 ); - isApprox( t, E, expectedE, 2.0 ); + isApprox( t, D, expectedD, ULP ); + isApprox( t, E, expectedE, ULP ); t.end(); }); @@ -141,10 +134,12 @@ tape( 'the function supports providing index offsets', function test( t ) { var expectedD; var expectedE; var info; + var ULP; var D; var E; var N; + ULP = 0; N = 3; D = new Float32Array( [ 0.0, 0.0, 4.0, 5.0, 6.0 ] ); @@ -155,8 +150,8 @@ tape( 'the function supports providing index offsets', function test( t ) { info = spttrf( N, D, 1, 2, E, 1, 3 ); t.strictEqual( info, 0, 'returns expected value' ); - isApprox( t, D, expectedD, 2.0 ); - isApprox( t, E, expectedE, 2.0 ); + isApprox( t, D, expectedD, ULP ); + isApprox( t, E, expectedE, ULP ); t.end(); }); @@ -165,10 +160,12 @@ tape( 'the function supports providing positive strides', function test( t ) { var expectedD; var expectedE; var info; + var ULP; var D; var E; var N; + ULP = 0; N = 3; D = new Float32Array( [ 0.0, 0.0, 4.0, 0.0, 0.0, 5.0, 0.0, 0.0, 6.0 ] ); @@ -179,8 +176,8 @@ tape( 'the function supports providing positive strides', function test( t ) { info = spttrf( N, D, 3, 2, E, 2, 3 ); t.strictEqual( info, 0, 'returns expected value' ); - isApprox( t, D, expectedD, 2.0 ); - isApprox( t, E, expectedE, 2.0 ); + isApprox( t, D, expectedD, ULP ); + isApprox( t, E, expectedE, ULP ); t.end(); }); @@ -189,10 +186,12 @@ tape( 'the function supports providing mixed sign strides', function test( t ) { var expectedD; var expectedE; var info; + var ULP; var D; var E; var N; + ULP = 0; N = 3; D = new Float32Array( [ 6.0, 0.0, 0.0, 5.0, 0.0, 0.0, 4.0 ] ); @@ -203,8 +202,8 @@ tape( 'the function supports providing mixed sign strides', function test( t ) { info = spttrf( N, D, -3, 6, E, 2, 3 ); t.strictEqual( info, 0, 'returns expected value' ); - isApprox( t, D, expectedD, 2.0 ); - isApprox( t, E, expectedE, 2.0 ); + isApprox( t, D, expectedD, ULP ); + isApprox( t, E, expectedE, ULP ); t.end(); }); @@ -213,10 +212,12 @@ tape( 'the function supports providing negative strides', function test( t ) { var expectedD; var expectedE; var info; + var ULP; var D; var E; var N; + ULP = 0; N = 3; D = new Float32Array( [ 6.0, 0.0, 0.0, 5.0, 0.0, 0.0, 4.0 ] ); @@ -227,8 +228,8 @@ tape( 'the function supports providing negative strides', function test( t ) { info = spttrf( N, D, -3, 6, E, -2, 5 ); t.strictEqual( info, 0, 'returns expected value' ); - isApprox( t, D, expectedD, 2.0 ); - isApprox( t, E, expectedE, 2.0 ); + isApprox( t, D, expectedD, ULP ); + isApprox( t, E, expectedE, ULP ); t.end(); }); diff --git a/lib/node_modules/@stdlib/lapack/base/spttrf/test/test.spttrf.js b/lib/node_modules/@stdlib/lapack/base/spttrf/test/test.spttrf.js index 2ff65bab938b..d16d0e30f193 100644 --- a/lib/node_modules/@stdlib/lapack/base/spttrf/test/test.spttrf.js +++ b/lib/node_modules/@stdlib/lapack/base/spttrf/test/test.spttrf.js @@ -24,8 +24,7 @@ var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); -var EPS = require( '@stdlib/constants/float32/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); var spttrf = require( './../lib/spttrf.js' ); @@ -38,22 +37,14 @@ var spttrf = require( './../lib/spttrf.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( isAlmostSameValuef( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' ); } } @@ -104,10 +95,12 @@ tape( 'the function computes the `L * D * L^T` factorization of a real symmetric var expectedD; var expectedE; var info; + var ULP; var D; var E; var N; + ULP = 26; N = 3; D = new Float32Array( [ 4.0, 5.0, 6.0 ] ); @@ -118,8 +111,8 @@ tape( 'the function computes the `L * D * L^T` factorization of a real symmetric info = spttrf( N, D, E ); t.strictEqual( info, 0, 'returns expected value' ); - isApprox( t, D, expectedD, 2.0 ); - isApprox( t, E, expectedE, 2.0 ); + isApprox( t, D, expectedD, ULP ); + isApprox( t, E, expectedE, ULP ); N = 7; @@ -131,8 +124,8 @@ tape( 'the function computes the `L * D * L^T` factorization of a real symmetric info = spttrf( N, D, E ); t.strictEqual( info, 0, 'returns expected value' ); - isApprox( t, D, expectedD, 15.0 ); - isApprox( t, E, expectedE, 2.0 ); + isApprox( t, D, expectedD, ULP ); + isApprox( t, E, expectedE, ULP ); t.end(); });