Repository navigation
Conversation
Adapt the Numba intersection kernel to two changes on main: - UXARRAY#1727 changed gca_const_lat_intersection to return a tuple of tuples instead of a (2, 3) array, so the kernel now reads points as intersections[r][i] rather than intersections[r, i]. - UXARRAY#1705 made the no-intersection and concave-face errors format the face array into their messages, which Numba cannot do, so both raises move from the kernel into the Python wrapper. The kernel now also returns the number of non-dummy edges that the concave check needs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ASV BenchmarkingBenchmark Comparison ResultsBenchmarks that have improved:
Benchmarks that have stayed the same:
Benchmarks that have got worse:
|
… Numba The robust path built several tiny polars DataFrames per candidate face, and that fixed per-call overhead was nearly its whole runtime. Each latitude is now two Numba calls: one computing every candidate face's longitude intervals, and one running the overlap sweep line. Results are bit-identical, and robust zonal means are 52-86x faster, now within 1.3-2.7x of the default path instead of 100-200x slower. Both new per-latitude kernels release the GIL. Each call does milliseconds of work, so from 4 threads the robust weights take 1.09x the single-thread wall time instead of 4.03x. The private helpers now use arrays instead of DataFrames: _zonal_face_weights_robust returns the weights, _get_zonal_face_interval returns (start, end) rows, and _process_overlapped_intervals takes starts/ends/face indices and returns per-face contributions. A face whose crossing longitudes cannot be paired into intervals now raises ValueError rather than polars' ShapeError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Robust zonal weights allocate their scratch space once per latitude instead of three to four small arrays per face, compute each intersection's longitude once, replace np.unique with an in-place sort, and sort the sweep-line events once instead of twice. The default path's per-face arc length builds its points and segments in fixed-size arrays instead of numba typed Lists. Results are bit-identical on oQU480 and oQU120 across 168 latitudes. Robust weights are 2.2x faster, default weights 1.6x faster single-threaded, and the first robust zonal_mean compiles in 1.7 s instead of 2.5 s. Also: - Robust weights return NaN when every candidate face is only touched by the latitude, matching the default path, instead of raising ZeroDivisionError. zonal.py already skips non-finite weights. - Drop the concave-face check, which could not fire, the error branch matching a message nothing raises, and the error helper's prints. - Combine nested ifs flagged by ruff SIM102. - Remove two pole weight tests that were each defined three times with identical bodies, so only the last copy ever ran. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cmdupuis3
marked this pull request as ready for review
November 20, 2026 01:51
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 #1570
Finishes off #790
Overview
This PR moves the per-face work in
uxarray/grid/integrate.pyinto Numba, mainly for the robust zonal-weights path (zonal_mean(..., use_robust_weights=True)). That path used to build several small polars DataFrames for every candidate face, and that fixed per-call cost was nearly all of its runtime. Each latitude is now two Numba calls:zonal_meanoutput is bit-identical tomainfor both the robust and default paths on oQU480 and oQU120. In ASV,ZonalAverage.time_zonal_average_robustdrops from 2.10 s to 13.2 ms at 120 km (about 160×) and from 530 ms to 5.46 ms at 480 km (about 97×). Locally the robust path is now as fast as the default one or faster. Both per-latitude kernels release the GIL (nogil=True): four concurrent calls from four threads take 1.14× the wall time of one.The default path gets a smaller cleanup.
_compute_face_arc_lengthbuilds its points and segments in fixed-size arrays instead of numba typedLists, which makes the default weights about 1.6× faster on a single thread. Cold JIT compilation of the first robustzonal_meandrops from 2.5 s to 1.7 s. The private helpers now take and return arrays instead of DataFrames:_zonal_face_weights_robustreturns the weight array directly._get_zonal_face_intervalreturns(start, end)rows._process_overlapped_intervalstakesstarts,endsand face indices, and returns per-face contributions.The only change outside
integrate.pyis the matching one-line update incore/zonal.py.Behaviour changes, all in private helpers:
ValueErrorinstead of polars'ShapeError.ZeroDivisionError. That matches the default path, andzonal.pyalready skips those latitudes.Two changes on
mainneeded adapting. After #1727,gca_const_lat_intersectionreturns a tuple of tuples. After #1705, the error messages format the face array, which Numba can't do, so the raises moved into the Python wrappers. Two pole tests intest_zonal_weights.pywere each defined three times with identical bodies, so only the last copy ever ran; the extra copies are gone. polars stays a dependency becauseio/_healpix.py,io/_scrip.pyandgrid/validation.pystill use it.PR Checklist
General
Testing & Benchmarking
Documentation and Examples
docs/api.rst; internal (private) function names start with an underscore (_)AI Disclosure
AI Usage: Claude Opus 5