Skip to content

Add golden-value tests pinning edge_detection to scipy.ndimage#3681

Open
brendancol wants to merge 2 commits into
mainfrom
deep-sweep-reference-validation-edge_detection-2026-07-18-01
Open

Add golden-value tests pinning edge_detection to scipy.ndimage#3681
brendancol wants to merge 2 commits into
mainfrom
deep-sweep-reference-validation-edge_detection-2026-07-18-01

Conversation

@brendancol

Copy link
Copy Markdown
Contributor

Closes #3677

  • Adds TestGoldenScipyParity to xrspatial/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 (default mode='reflect')
  • Asserts the boundary='reflect' full arrays match the reference exactly, and the default boundary='nan' interiors match the reference interiors
  • Includes the reference-validation sweep state row for edge_detection (verdict: MATCHES)

Test-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)
  • flake8 on the test file: no new findings (one pre-existing E302 left alone)

@brendancol brendancol left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

  • TestGoldenScipyParity pins boundary='reflect' (full array) and the default boundary='nan' (interior). nearest and wrap stay covered only by assert_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 matched ndi.correlate bit 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).

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.

Pin edge_detection against scipy.ndimage with golden-value tests

1 participant