Skip to content

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

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

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

Conversation

@kgryte

@kgryte kgryte commented Oct 3, 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.main.js, test/test.ndarray.js, test/test.module.main.js, and test/test.module.ndarray.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 packages blas/base/wasm/cscal, blas/base/wasm/srot, and blas/base/wasm/drotm, 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, cxe, ... ) 0 0
isApprox( t, viewY, cye, ... ) 1 1

The bounds are identical across all four files and across all test cases (plane rotation, x stride, y stride, 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.main.js             viewX: 0   viewY: 1   (6 cases)
test.ndarray.js          viewX: 0   viewY: 1   (7 cases)
test.module.main.js      viewX: 0   viewY: 1   (5 cases)
test.module.ndarray.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.main.js fail (9 failing assertions out of 122), while the chosen bounds pass everywhere.

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 blas/base/csrot — 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, test/test.module.js, and test/test.routine.js contain no tolerance-based assertions and are 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/wasm/csrot/.*" — 536 passing, 0 failing across all seven test files. Run twice, with identical results.
  • Minimality confirmed by re-running the suite with the viewY bound lowered to 0, which fails as expected (113 passing, 9 failing in test/test.main.js).
  • make lint-javascript-tests TESTS_FILTER=".*/blas/base/wasm/csrot/.*" — clean, 0 problems across all files.
  • EditorConfig compliance (LF endings, UTF-8, no trailing whitespace, 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.

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 previously converted sibling packages in the same family (blas/base/wasm/cscal, blas/base/wasm/srot, blas/base/wasm/drotm), 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_014LQ8huwgQVRDzd3oPQiTXw


Generated by Claude Code

Ref: #11352

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014LQ8huwgQVRDzd3oPQiTXw

---
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
---
@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 3, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
blas/base/wasm/csrot $\\color{green}706/706$
$\\color{green}+100.00\\%$
$\\color{green}17/17$
$\\color{green}+100.00\\%$
$\\color{green}6/6$
$\\color{green}+100.00\\%$
$\\color{green}706/706$
$\\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