Make planar aspect cupy backend match numpy in [0, 360) (#2827)#2833
Merged
Conversation
The cupy device function snapped any aspect above 359.999 to 0 while the numpy/numba kernel left it as-is. Since the numpy compass conversion never reaches 360, the clamp only existed on the GPU side and made cupy and dask+cupy disagree with numpy by ~360 on a near-degenerate gradient. Remove the band clamp, align the GPU radian-to-degree constant with the numpy kernel's 180/pi so the compass branch selects the same way on both backends, and wrap any exact-360 result back to [0, 360) to match the numpy output range. Add cross-backend tests for the near-360 band covering numpy, dask+numpy, cupy, and dask+cupy.
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 #2827
What
The planar
aspect()cupy device function snapped any aspect above 359.999 down to 0, but the numpy/numba kernel did not. The numpy compass conversion produces values in [0, 360) and never reaches 360, so the clamp lived only on the GPU side and made cupy and dask+cupy disagree with numpy by about 360 on a near-degenerate gradient (tiny east gradient, strong north gradient).Removing the clamp surfaced a second, related divergence: the GPU used a coarse radian-to-degree constant (57.29578) while numpy uses 180/pi. On an exact-90 tie that pushed the intermediate value into a different compass branch and produced 360 where numpy produced 0 (seen on uint32/uint64 random rasters).
Changes
_aspect > 359.999 -> 0clamp from the cupy_gpukernel.Backend coverage
numpy, dask+numpy, cupy, dask+cupy. The geodesic path is untouched; it already canonicalizes consistently on CPU and GPU.
Test plan
test_near_360_*tests pass on numpy, dask+numpy, cupy, dask+cupytest_aspect.pyandtest_geodesic_aspect.pysuites pass (235 passed)