Skip to content

test: make strided out tests compare against an independent reference - #388

Open
antonwolfy wants to merge 2 commits into
masterfrom
fix/strided-out-tests
Open

antonwolfy wants to merge 2 commits into
masterfrom
fix/strided-out-tests

Conversation

@antonwolfy

Copy link
Copy Markdown
Collaborator

Four tests that check out= with strided arrays pass the same out to both mkl_fft and numpy.fft:

result = getattr(mkl_fft, func)(x, axis=axis, out=out)
expected = getattr(np.fft, func)(x, axis=axis, out=out)
assert_allclose(result, expected)

Both calls return out, so result is expected and the assertion compares out with itself. The tests pass even if mkl_fft writes nothing, or garbage, into out. test_fft_out_strided also rebinds out to a contiguous array, so despite its name it never tests a strided out.

The affected tests cover 20 parametrized cases, all added in #157:

  • test_fft1d.py: test_fft_out_strided, test_rfft_out_strided, test_irfft_out_strided
  • test_fftnd.py: test_out_strided

Changes

  • Compute the NumPy reference without out, as NumPy's own test_pocketfft.py does.
  • Assert that out is returned.
  • Make out in test_fft_out_strided an actual strided view.
  • Take out as a view of a sentinel-filled buffer and check that nothing outside the view is written to.

Verification

  • With master's code, all 20 cases pass, also over 20 repeated runs, and so does the full suite.
  • Mutation check: I replaced fft/ifft/rfft/irfft/fftn/ifftn with a stub that returns out untouched. The current tests still pass all 20 cases; the updated tests fail all 20.

This is a test-only change, so there is no CHANGELOG entry. Found while reviewing #387.

`test_fft_out_strided`, `test_rfft_out_strided`, `test_irfft_out_strided`
and `test_out_strided` passed the same `out` array to both mkl_fft and
numpy.fft. Since both return `out`, `result` and `expected` were the same
object and the assertions compared `out` with itself, so the tests could
not fail. `test_fft_out_strided` also rebound `out` to a contiguous array
and so never exercised a strided `out`.

Compute the NumPy reference without `out`, assert that `out` is returned,
make `out` in `test_fft_out_strided` actually strided, and check that
nothing outside of the `out` view is written to.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant