Skip to content

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
copybara-service[bot] merged 1 commit into
mainfrom
test_1028186121
Nov 25, 2026

Conversation

@copybara-service

Copy link
Copy Markdown

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.

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.

… 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
copybara-service Bot merged commit 6975449 into main Nov 25, 2026
4 checks passed
@copybara-service
copybara-service Bot deleted the test_1028186121 branch November 25, 2026 12:19
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.

1 participant