From 93aa026786f856cd776628e3664ddcb6cb440d86 Mon Sep 17 00:00:00 2001 From: Hiroshi Shinaoka Date: Thu, 8 Oct 2026 04:38:26 +0900 Subject: [PATCH] Scale the DLR round-trip tolerance in the axis test by its conditioning The axis test compares the same logical data with the coefficient axis in two places. The transform applies the same linear map either way, but the contraction geometry differs, so the two results differ by one rounding unit amplified by the transform's own condition number. The sampling transforms are well conditioned and keep the fixed 1e-12 bound; the DLR round trip is not (cond ~ 2.2e5 for the fixture here), and a library built from sparse-ir-rs main misses that bound by 2%. SpM-lab/sparse-ir-rs#326. Co-Authored-By: Claude Opus 5 --- tests/test_boundary.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/test_boundary.py b/tests/test_boundary.py index 79c8a1a..fefa251 100644 --- a/tests/test_boundary.py +++ b/tests/test_boundary.py @@ -341,8 +341,22 @@ def test_axis_on_three_dimensional_input(bases, stat, axis): rtol=0, atol=1e-13 * np.abs(ref).max()) back = backward(out, axis=axis) back_ref = backward(ref, axis=0) + # The two calls place the coefficient axis differently, which can select + # a different contraction geometry, so their rounding can differ; the + # ill-conditioned DLR round trip amplifies that (SpM-lab/sparse-ir-rs#326). + # The sampling transforms are well conditioned and keep the fixed bound. + if name == "DLR.from_IR": + # G_l = -S_l sum_p V_l(w_p) c_p, as DiscreteLehmannRepresentation + # documents; its conditioning is what amplifies the input. + amp = np.linalg.cond(-basis.s[:, None] + * basis.v(obj.sampling_points)) + assert np.isfinite(amp) + else: + amp = 1.0 + atol = max(1e-12, amp * np.finfo(np.float64).eps) \ + * np.abs(back_ref).max() np.testing.assert_allclose(np.moveaxis(back, axis, 0), back_ref, - rtol=0, atol=1e-12 * np.abs(back_ref).max()) + rtol=0, atol=atol) # ---------------------------------------------------------------------------