Add golden-value tests pinning edge_detection to scipy.ndimage#3681
Open
brendancol wants to merge 2 commits into
Open
Add golden-value tests pinning edge_detection to scipy.ndimage#3681brendancol wants to merge 2 commits into
brendancol wants to merge 2 commits into
Conversation
brendancol
commented
Jul 18, 2026
brendancol
left a comment
Contributor
Author
There was a problem hiding this comment.
PR Review: Add golden-value tests pinning edge_detection to scipy.ndimage
Blockers (must fix before merge)
None.
Suggestions (should fix, not blocking)
None.
Nits (optional improvements)
-
TestGoldenScipyParitypinsboundary='reflect'(full array) and the defaultboundary='nan'(interior).nearestandwrapstay covered only byassert_boundary_mode_correctness, which checks numpy against dask rather than against a reference. That seems like the right scope call: the reflect full-array already pins the stencil at every pixel plus one edge convention, and per-mode edge handling belongs to the convolution module. Flagging it so the choice is on record, not asking for more arrays.
What looks good
- Expected arrays were generated with scipy.ndimage 1.16.1 and the class docstring says exactly which calls and mode produced them, so the values can be regenerated and checked by hand (xrspatial/tests/test_edge_detection.py:127).
assert_array_equal(exact equality) is justified here and the comment explains why: the input is integer-valued, and xrspatial matchedndi.correlatebit for bit during validation.- The
boundary='nan'interior test reuses the same golden interiors, so a regression in default-mode interior math gets caught without depending on edge conventions. - Test-only diff plus the sweep state row; no source changes, matching what issue #3677 scoped.
Checklist
- Algorithm matches reference (validated against scipy.ndimage 1.16.1; script in #3677)
- All implemented backends produce consistent results (existing parity tests in this file cover cupy/dask+numpy/dask+cupy; golden pin on numpy transfers through them)
- NaN handling is correct (nan-boundary interior asserted; NaN propagation already tested elsewhere in the file)
- Edge cases are covered by tests (edges pinned under reflect; nan edges asserted by existing tests)
- Dask chunk boundaries handled correctly (unchanged by this PR; existing dask tests pass)
- No premature materialization or unnecessary copies (test-only)
- Benchmark exists or is not needed (not needed for tests)
- README feature matrix updated (not applicable, no new functions)
- Docstrings present and accurate (test class docstring records reference tool and version)
97 tests pass locally including the 10 new ones; flake8 adds no new findings (the one E302 predates this PR).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3677
TestGoldenScipyParitytoxrspatial/tests/test_edge_detection.py: a 5x6 integer input with hardcoded expected outputs for sobel_x, sobel_y, prewitt_x, prewitt_y, and laplacian, generated with scipy.ndimage 1.16.1 (defaultmode='reflect')boundary='reflect'full arrays match the reference exactly, and the defaultboundary='nan'interiors match the reference interiorsTest-only change, no source edits. The golden tests run on the numpy backend; the existing tests in this file already check cupy, dask+numpy, and dask+cupy against numpy, so the pin covers all four backends transitively.
Background: I validated all five functions against scipy.ndimage on a Gaussian hill, a tilted plane with known analytic gradient, and a seeded random-walk surface. Interior and edge pixels matched for every boundary mode, and the tilted plane matched the analytic response exactly. The comparison script is in #3677. Nothing diverged; this PR just makes sure the test suite would notice if it ever does.
Test plan:
pytest xrspatial/tests/test_edge_detection.py- 97 passed (87 existing + 10 new)