Repository navigation
Add regular-grid and boundary-Delaunay fast paths for coordinate maps containing partial NaNs in map_utils.compose_maps, map_utils.invert_map, and map_utils.fill_missing, and unify 2D and 3D map inversion in invert_map. - #127
Merged
Conversation
… containing partial NaNs in `map_utils.compose_maps`, `map_utils.invert_map`, and `map_utils.fill_missing`, and unify 2D and 3D map inversion in `invert_map`. When a coordinate map contains even a single NaN (such as thin out-of-bounds borders produced during `ReconcileCrossBlockMaps` offset composition), `compose_maps` and `invert_map` previously rejected their dense bilinear/Newton paths and fell back to running Qhull Delaunay triangulation over all valid grid nodes, and `fill_missing` similarly triangulated all valid interior nodes. Now: * `compose_maps` runs the vectorized/JIT regular-grid bilinear pass (`_compose_maps_bilinear`, using 1D flat-offset gathers on the NumPy path) across all slices when `h2 >= 2` and `w2 >= 2`, restricts residual Delaunay fallback to queries within the valid boundary bounding box whose enclosing 2x2 cell contains a NaN, triangulates only valid boundary nodes (`_boundary_valid_mask`), and reuses the triangulation across slices sharing an identical boundary mask. * `invert_map` unifies 2D slice-stack and 3D volume inversion across dense Newton (`_invert_dense_newton` + `_invert_newton_jit`), partial-NaN Newton (`_invert_partial_newton`), and residual Delaunay fallback without per-dimension dispatch branches, using 1D flat-offset corner gathers and single-pass cofactor solves (`_newton_step_flat`). `_invert_partial_newton` runs the Gale-Nikaido-checked multilinear Newton solver on an EDT-extended copy of the map, retains exact preimages inside all-corner-valid source cells, and resolves only residual queries via boundary-node Delaunay triangulation. * `fill_missing` restricts 2D `interpolate_first` Delaunay triangulation to `_boundary_valid_mask(valid)`. On AMD EPYC 7B13 CPU microbenchmarks, this speeds up partial-NaN `compose_maps` by 84.8x-940.6x (and dense `compose_maps` by 1.75x-4.55x), partial-NaN `invert_map` by 17.4x in 2D and 4.12x in 3D (and dense `invert_map` by 1.33x-1.61x), and curved-border/hole `fill_missing` by 96.5x. PiperOrigin-RevId: 1029809966
copybara-service
Bot
force-pushed
the
test_1028186121
branch
from
November 25, 2026 12:19
303011c to
6975449
Compare
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.
Add regular-grid and boundary-Delaunay fast paths for coordinate maps containing partial NaNs in
map_utils.compose_maps,map_utils.invert_map, andmap_utils.fill_missing, and unify 2D and 3D map inversion ininvert_map.When a coordinate map contains even a single NaN (such as thin out-of-bounds borders produced during
ReconcileCrossBlockMapsoffset composition),compose_mapsandinvert_mappreviously rejected their dense bilinear/Newton paths and fell back to running Qhull Delaunay triangulation over all valid grid nodes, andfill_missingsimilarly triangulated all valid interior nodes.Now:
compose_mapsruns the vectorized/JIT regular-grid bilinear pass (_compose_maps_bilinear, using 1D flat-offset gathers on the NumPy path) across all slices whenh2 >= 2andw2 >= 2, restricts residual Delaunay fallback to queries within the valid boundary bounding box whose enclosing 2x2 cell contains a NaN, triangulates only valid boundary nodes (_boundary_valid_mask), and reuses the triangulation across slices sharing an identical boundary mask.invert_mapunifies 2D slice-stack and 3D volume inversion across dense Newton (_invert_dense_newton+_invert_newton_jit), partial-NaN Newton (_invert_partial_newton), and residual Delaunay fallback without per-dimension dispatch branches, using 1D flat-offset corner gathers and single-pass cofactor solves (_newton_step_flat)._invert_partial_newtonruns the Gale-Nikaido-checked multilinear Newton solver on an EDT-extended copy of the map, retains exact preimages inside all-corner-valid source cells, and resolves only residual queries via boundary-node Delaunay triangulation.fill_missingrestricts 2Dinterpolate_firstDelaunay triangulation to_boundary_valid_mask(valid).On AMD EPYC 7B13 CPU microbenchmarks, this speeds up partial-NaN
compose_mapsby 84.8x-940.6x (and densecompose_mapsby 1.75x-4.55x), partial-NaNinvert_mapby 17.4x in 2D and 4.12x in 3D (and denseinvert_mapby 1.33x-1.61x), and curved-border/holefill_missingby 96.5x.