Skip to content

Add longitude normalization to CUDA inverse projection kernels#1089

Merged
brendancol merged 2 commits into
masterfrom
issue-1088
Mar 30, 2026
Merged

Add longitude normalization to CUDA inverse projection kernels#1089
brendancol merged 2 commits into
masterfrom
issue-1088

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #1088

Summary

  • CUDA longitude normalization: Six CUDA inverse projection kernels returned raw lam + lon0 without wrapping to [-pi, pi], while the CPU Numba kernels all pass through _norm_lon_rad(). Added a _d_norm_lon_rad device function and applied it to LCC, AEA, CEA, Sinusoidal, LAEA, and Polar Stereographic inverses (7 return statements total).

  • Dead code cleanup: Removed an unused loop in _tmerc_params() that computed dCn via a broken recurrence, immediately overwritten by the correct _clenshaw_complex_py() call.

Test plan

  • New test: test_sinusoidal_round_trip_stays_in_range verifies CPU sinusoidal inverse keeps longitude in [-180, 180] near antimeridian
  • New test: test_lcc_round_trip_stays_in_range verifies CPU LCC inverse round-trip
  • Full reproject test suite: 89/89 pass
  • CUDA kernels require GPU hardware to test directly; the CPU tests verify the normalization logic that the CUDA _d_norm_lon_rad replicates

Six CUDA inverse projection kernels returned raw `lam + lon0` without
wrapping to [-pi, pi]. The CPU Numba kernels all pass through
`_norm_lon_rad()` before converting to degrees. Without normalization,
coordinates far from the central meridian (e.g., near the antimeridian)
can produce longitude values outside [-180, 180].

Added `_d_norm_lon_rad` device function and applied it to:
- LCC inverse (2 return paths)
- AEA inverse
- CEA inverse
- Sinusoidal inverse
- LAEA inverse
- Polar Stereographic inverse

Also removed dead code in `_tmerc_params()` where a loop computed
a value that was immediately overwritten.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Mar 30, 2026
…1088)

- Add _norm_lon_rad to CPU _lcc_inv_point early-return (rho < 1e-30)
  for consistency with the CUDA fix
- Move _WGS84_E2/_WGS84_A constants to top of test file
@brendancol brendancol merged commit e00a52a into master Mar 30, 2026
10 of 11 checks passed
@brendancol brendancol deleted the issue-1088 branch May 4, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CUDA inverse projections missing longitude normalization

1 participant