test: migrate blas/base/zaxpy to ULP-based assertions - #15436
Draft
Planeshifter wants to merge 1 commit into
Draft
Planeshifter wants to merge 1 commit into
Planeshifter wants to merge 1 commit into
Conversation
Resolves a part of #11352. Migrates the tests for blas/base/zaxpy from computed relative-tolerance comparisons (delta = abs(actual[i] - expected[i]) / tol = rtol * EPS * abs(expected[i]), asserted via t.ok(delta <= tol, ...)) to ULP-difference assertions using @stdlib/assert/is-almost-same-value, mirroring the established idiom in blas/base/drot: the shared isApprox(t, actual, expected, ulp) helper collapses to a single isAlmostSameValue assertion, and each test body declares a single named ULP constant sized to the minimum integer bound that passes for that test. Applies to all four test files (test.zaxpy.js, test.ndarray.js, and their .native.js counterparts, including the native-only "dcabs1(alpha) === 0.0" test in test.ndarray.native.js). ULP bounds were determined by measuring the exact per-element ULP distance for every fixture via @stdlib/number/float64/base/ulp-difference, run directly against the implementation. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01PLAefATEDhsbjEiq9xEYN4
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves a part of #11352.
Description
This pull request:
blas/base/zaxpyfrom computed relative-tolerance comparisons (delta = abs( actual[ i ] - expected[ i ] )/tol = rtol * EPS * abs( expected[ i ] ), asserted viat.ok( delta <= tol, ... )) to ULP-difference assertions using@stdlib/assert/is-almost-same-value.isApprox( t, actual, expected, rtol )helper:test/test.zaxpy.js,test/test.ndarray.js,test/test.zaxpy.native.js, andtest/test.ndarray.native.js. The helper'srtolparameter becomes aulpparameter, and every call site is preceded by a per-test-bodyvar ULP;declaration set to the minimum integer bound that makes that test's assertions pass.if ( actual[ i ] === expected[ i ] ) { ... } else { ... }branch in the helper into a single ULP assertion, and standardizes the assertion message to'returns expected value'.@stdlib/constants/float64/epsand@stdlib/math/base/special/absrequires and thedeltaandtolvariable declarations.This mirrors the already-merged migration of
blas/base/drot, which uses the sameisApproxhelper shape with@stdlib/assert/is-almost-same-value(double-precision), andlapack/base/crot, which migrated the analogous single-precisionisApproxhelper.The remaining assertions in these files are exact comparisons (arity checks, returned references, and the
deepEqualchecks that both vectors are unchanged whenN <= 0oralpha === 0), which are correct as-is and are left unchanged.Only test files are changed; no implementation, fixture, or documentation changes are included. No new
package.jsondependency was needed, as@stdlib/assert/is-almost-same-valueis already used elsewhere in the repository.ULP bounds
All tests previously used a relative tolerance of
14.0. The measured, tightened ULP bounds are:test/test.zaxpy.js/test/test.zaxpy.native.js— "scales elements fromxbyalphaand adds the result toy": 24 ULPtest/test.zaxpy.js/test/test.zaxpy.native.js— "supports anxstride": 8 ULPtest/test.zaxpy.js/test/test.zaxpy.native.js— "supports aystride": 6 ULPtest/test.zaxpy.js/test/test.zaxpy.native.js— "supports negativexstrides": 24 ULPtest/test.zaxpy.js/test/test.zaxpy.native.js— "supports negativeystrides": 8 ULPtest/test.zaxpy.js/test/test.zaxpy.native.js— "supports complex access patterns": 6 ULPtest/test.zaxpy.js(only) — "supports view offsets": 24 ULPtest/test.ndarray.js/test/test.ndarray.native.js— "supports anxoffset": 11 ULPtest/test.ndarray.js/test/test.ndarray.native.js— "supports ayoffset": 1 ULPtest/test.ndarray.native.js(only) — "ifdcabs1( alpha ) === 0.0, the function returns the second input array unchanged": 0 ULP (exact)Each bound is the minimum integer
Nsuch thatisAlmostSameValue( actual[ i ], expected[ i ], N )holds at every element compared in that test. The bounds were determined by measuring the exact per-element ULP distance with@stdlib/number/float64/base/ulp-difference, run directly against the JavaScript implementation for every fixture in bothtest.zaxpy.jsandtest.ndarray.js. Thetest.*.native.jsfiles reuse the same bounds, since the native addon could not be built/verified in this environment (the tests areskip-guarded viatryRequireand did not execute), and the underlying operation is a straightforward multiply-add with no transcendental functions, so JS/C divergence beyond these bounds is not expected. The one native-only test (dcabs1( alpha ) === 0.0) is an exact no-op case, so its bound is0.make test TESTS_FILTER=".*/blas/base/zaxpy/.*"was run twice at the final bounds with identical results on both runs (test.zaxpy.js: 111/111 passing, test.ndarray.js: 128/128 passing, test.js: 5/5 passing, the two native files fully skipped as their addon is unavailable), ruling out FMA/architecture-dependent flakiness on this platform.npx eslintandmake lint-javascript-tests TESTS_FILTER=".*/blas/base/zaxpy/.*"are clean.I initially attempted
lapack/base/zrot(explicitly suggested as a follow-on in the mergedlapack/base/crotPR), but abandoned it: one fixture element has an expected value of exactly0.0while the actual double-precision result is2.220446049250313e-16(a genuine, reproducible discrepancy, not a transcription error), and the ULP distance between0and that value is astronomically large (~4.37×10¹⁸, since it spans the subnormal range), making a small, meaningful ULP bound impossible for that test.blas/base/zaxpydoes not hit this pathology, since no exact-zero expected values occur alongside nonzero actual results in its ULP-checked comparisons.Related Issues
This pull request has the following related issues:
math/base/specialpackages from relative tolerance testing to ULP difference testing (tracking issue) #11352Questions
No.
Other
Two environment notes, neither of which affected verification:
make install-node-modulesinitially failed withETARGETfores-object-atoms@^1.1.2, because the local npm packument cache served a stale, filtered view of the registry (confirmed by querying the registry directly, which lists1.1.2).npm cache clean --forceresolved it, and the full toolchain was available for the linting and testing reported above.pre-commithook'slint-editorconfig-filesstep could not run, because it downloads theeditorconfig-checkerbinary from a GitHub release that this environment's network policy does not permit (403). The four changed files were instead checked manually against.editorconfig: LF line endings, tab indentation, no trailing whitespace, and a final newline.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was written primarily by Claude Code, running as an unattended scheduled task. It selected the package (after abandoning
lapack/base/zrotfor the reason described above), studied previously migrated packages in the same family (blas/base/drot,lapack/base/crot) to match the established idiom, performed the migration, and determined the minimum passing ULP bounds empirically over every compared element.@stdlib-js/reviewers
🤖 Generated with Claude Code
https://claude.ai/code/session_01PLAefATEDhsbjEiq9xEYN4