Skip to content

test: migrate blas/base/csrot to ULP-based assertions - #15890

Draft
kgryte wants to merge 1 commit into
developfrom
kgryte/ulp-blas-base-csrot
Draft

kgryte wants to merge 1 commit into
developfrom
kgryte/ulp-blas-base-csrot

Conversation

@kgryte

@kgryte kgryte commented Oct 4, 2026

Copy link
Copy Markdown
Member

Resolves a part of #11352.

Description

What is the purpose of this pull request?

This pull request:

Concretely, in each of test/test.csrot.js, test/test.csrot.native.js, test/test.ndarray.js, and test/test.ndarray.native.js, the following helper

function isApprox( t, actual, expected, rtol ) {
	var delta;
	var tol;
	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+'.' );
		}
	}
}

is replaced by

function isApprox( t, actual, expected, ulp ) {
	var i;

	t.strictEqual( actual.length, expected.length, 'returns expected value' );
	for ( i = 0; i < expected.length; i++ ) {
		t.strictEqual( isAlmostSameValuef( actual[ i ], expected[ i ], ulp ), true, 'returns expected value' );
	}
}

along with adding the @stdlib/number/float32/base/assert/is-almost-same-value require and dropping the now-unused @stdlib/math/base/special/abs and @stdlib/constants/float32/eps requires.

As this package operates on single-precision complex floating-point numbers, the tests use the single-precision assertion utility (isAlmostSameValuef), matching the convention already established by the sibling package blas/base/wasm/csrot (#15871), whose converted test files use the same isApprox( t, actual, expected, ulp ) helper shape with a per-call-site integer ULP bound.

ULP bounds

Every tolerance-based assertion in this package compares a Float32Array view against expected Float32Array values, in viewX/viewY pairs. The measured minimum differs between the two members of each pair, so each assertion carries its own bound rather than a single uniform value:

Assertion ULP constant Measured minimum
isApprox( t, viewX, xe, ... ) 0 0
isApprox( t, viewY, ye, ... ) 1 1

The bounds are identical across all four files and across all test cases (plane rotation, x stride, x offset, y stride, y offset, negative strides, complex access patterns, and view offsets), replacing the previous uniform 2.0 relative tolerance (i.e., 2.0 * EPS * abs( expected )) at every call site.

The bounds were tightened empirically rather than guessed. Starting from a high value and lowering it, the viewX results are bit-exact against the expected values and so pass at 0, while the viewY results differ by exactly one ULP and so fail at 0 and pass at 1:

# maximum measured ULP distance per call site
test.csrot.js             viewX: 0   viewY: 1   (6 cases)
test.csrot.native.js      viewX: 0   viewY: 1   (6 cases)
test.ndarray.js           viewX: 0   viewY: 1   (7 cases)
test.ndarray.native.js    viewX: 0   viewY: 1   (7 cases)

So 1 is the tightest possible non-exact bound for the viewY assertions, and the viewX assertions require no tolerance at all. Minimality was confirmed in both directions: lowering the viewY bound to 0 makes test/test.csrot.js fail (113 passing, 9 failing) and test/test.ndarray.native.js fail (129 passing, 12 failing), while the chosen bounds pass everywhere.

Notably, the JavaScript and native implementations agree bit-for-bit on these fixtures, so the same bounds apply to both; no JS-vs-C divergence had to be accommodated. To establish this rather than assume it, the native add-on was compiled locally (make install-node-addons NODE_ADDONS_PATTERN="blas/base/csrot") so that test/test.csrot.native.js and test/test.ndarray.native.js actually executed rather than being skipped via tryRequire.

The full test suite was run twice at the final values to confirm the result is stable (no FMA/arch-dependent variation); both runs report identical passing counts and 0 failures.

Note that the prior state of this package applied a uniform 2.0 * EPS relative tolerance to both members of each pair, which is why the viewX cases were not previously distinguishable as exact. If reviewers would prefer a uniform 1 in both positions — trading the tighter bound for robustness against a future bit-level change in the implementation — that is a one-character change per call site and I am happy to make it.

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Questions

Any questions for reviewers of this pull request?

Only the one noted above: whether the exact (0 ULP) bound on the viewX assertions is preferred over a uniform 1, given that the issue asks for the minimum required ULP value.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

Only the four test files containing tolerance-based assertions are modified; no source, documentation, benchmark, or fixture files are touched. test/test.js contains no tolerance-based assertions and is left unchanged. The assertion count is unchanged by this migration, as the removed exact/approximate branch emitted exactly one assertion per element either way.

Verification performed:

  • make test TESTS_FILTER=".*/blas/base/csrot/.*" — 531 passing, 0 failing across all five test files (122 + 122 + 141 + 141 + 5), with the native tests executing rather than skipping. Run twice, with identical results.
  • Minimality confirmed by re-running with the viewY bound lowered to 0, which fails as expected.
  • make lint-javascript-tests TESTS_FILTER=".*/blas/base/csrot/.*" — clean, 0 problems across all files.
  • EditorConfig compliance (LF endings, UTF-8, no trailing whitespace introduced, final newline, tab indentation) verified directly against .editorconfig, as the editorconfig-checker binary could not be downloaded in the sandbox used to author this change. The four pre-existing trailing-whitespace lines in these files are untouched by this diff (git diff --check is clean).

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

This PR was authored by Claude Code running as an unattended task. It studied the migration idiom from the previously converted sibling packages in the same family (blas/base/wasm/csrot, blas/base/zdrot), applied the mechanical substitution to the four affected test files, and determined the ULP bounds by instrumenting the test helper to report the maximum observed ULP distance per call site, then confirming that a lower bound fails while the chosen bound passes and re-running the suite to confirm the result is deterministic.


@stdlib-js/reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_01GM1tQCdB4tfVPW72Q5eaAo


Generated by Claude Code

Migrates the tests for `blas/base/csrot` from relative tolerance
testing to ULP difference testing by replacing the computed
`delta`/`tol` comparisons in the `isApprox` test helper with
`@stdlib/number/float32/base/assert/is-almost-same-value`.

The ULP bounds were tightened empirically to their measured minima:
`0` for the `viewX` assertions (bit-exact) and `1` for the `viewY`
assertions.

Ref: #11352

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GM1tQCdB4tfVPW72Q5eaAo
@stdlib-bot stdlib-bot added BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). Good First PR A pull request resolving a Good First Issue. labels Oct 4, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
blas/base/csrot $\\color{green}418/418$
$\\color{green}+100.00\\%$
$\\color{green}17/17$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}418/418$
$\\color{green}+100.00\\%$

The above coverage report was generated for the changes in this PR.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). Good First PR A pull request resolving a Good First Issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants