Files
dotfiles/overlays/patches/scipy/README.md
T

2.8 KiB

SciPy STFT test tolerances

The x86-64-v3 build can produce small floating-point residuals in inverse-STFT comparisons and scaling round trips. The original bounds reject these results, including residuals around 4e-17 where a round trip expects zero for a signal with amplitude 2.

Scope and behavior

stft-test-tolerances.patch changes only the signal tests:

  • The inverse-STFT comparison in _scipy_spectral_test_shim.py uses max(1e-7, 2 * np.finfo(x.dtype).eps) as its relative tolerance. Float64 keeps the original bound, and the existing i686 override remains.
  • Three scaling round trips in test_spectral.py gain an absolute tolerance of one epsilon for the input dtype, allowing small residuals near zero.

The tests remain enabled, and the production STFT implementation is unchanged.

Reproduction and focused checks

From this directory, apply the patch to a disposable SciPy 1.18.0 checkout:

patch --fuzz=0 -d /path/to/scipy -p1 < stft-test-tolerances.patch

Build and install that tree with SciPy's test dependencies. From outside the source directory, run the installed tests:

python -m pytest --pyargs scipy.signal.tests.test_spectral \
  -k 'roundtrip_float32 or roundtrip_scaling' -q

Use the same compiler flags and numerical libraries for before/after runs. The earlier reproduction called TestSTFT.test_roundtrip_float32 and TestSTFT.test_roundtrip_scaling against the x86-64-v3 libraries, then loaded patched copies of the test modules. Both failed with the original bounds and passed with the adjusted bounds.

Upstream status

SciPy issue #25488 records related test failures with architecture-specific compiler flags. It is context for the local tolerance repair; this exact patch has not been submitted upstream during this work.

Local NixOS integration and build results

../default.nix loads default.nix through pythonPackagesExtensions, preserving the package's existing patches. The override also covers SciPy used to test other Python dependencies, including pgvector in portal's shared Python environment.

From the repository root:

nix build --no-link -L .#nixosConfigurations.portal-1.pkgs.python314Packages.scipy

The original remote build of patched SciPy 1.18.0 passed 87,723 tests, with 8,342 skips, 300 expected failures, and 22 unexpected passes. The patch and override have been restored byte-for-byte from commit 24cbf74f; those counts describe the earlier full build.

Restoration checks confirmed that the patch applies to the pinned source without fuzz, portal's evaluated SciPy retains its existing patch and install checks, and pgvector uses the patched SciPy. A full package or system rebuild was not repeated for this restoration.