vibespatial.constructive.make_valid_gpu

GPU-resident make_valid batch repair pipeline (ADR-0019 + ADR-0033).

Phase 16: Batch repolygonization. All invalid polygons are collected into one contiguous batch and processed through the GPU repair pipeline together, eliminating the per-polygon Python loop. shapely.polygonize and shapely.make_valid are no longer used in the primary GPU path.

Pipeline stages (batched across all invalid polygons):

Phase A: GPU self-intersection detection (extract ring segments, classify pairs) Phase B: Simple repair kernels (close rings, remove duplicate vertices, fix orientation) Phase C: Self-intersection splitting (count/scatter split events, sort, dedup, rebuild) Phase D: Re-polygonization (half-edges, face walk, face containment, assembly) Phase E: Output assembly (build OwnedGeometryArray, convert to Shapely)

All kernels use fp64 compute (CONSTRUCTIVE class per ADR-0002). Tier 1: NVRTC for geometry-specific work. Tier 3a: CCCL for scan/sort/compact. Tier 2: CuPy for element-wise ops.

Attributes

cp

Classes

GPURepairResult

Result of GPU make_valid repair.

Functions

gpu_repair_invalid_polygons(→ GPURepairResult | None)

GPU-resident batch repair of invalid polygon geometries (Phase 16).

Module Contents

vibespatial.constructive.make_valid_gpu.cp = None
class vibespatial.constructive.make_valid_gpu.GPURepairResult

Result of GPU make_valid repair.

repaired_geometries: numpy.ndarray
repaired_count: int
gpu_phases_used: tuple[str, Ellipsis]
vibespatial.constructive.make_valid_gpu.gpu_repair_invalid_polygons(owned: vibespatial.geometry.owned.OwnedGeometryArray, invalid_rows: numpy.ndarray, geometries: numpy.ndarray, *, method: str = 'linework', keep_collapsed: bool = True) GPURepairResult | None

GPU-resident batch repair of invalid polygon geometries (Phase 16).

Implements the full make_valid pipeline on GPU with batch processing: 1. Collect all invalid polygon coordinates into one contiguous batch 2. Phase B: Close rings, remove duplicates, fix orientation (batched) 3. Phase A+C: Detect and split self-intersections (batched) 4. Phase D: Re-polygonize via overlay half-edge/face-walk pipeline (batched) 5. Map output polygons back to global row indices

No per-polygon Python loop. No shapely.polygonize or shapely.make_valid fallback. All repair is GPU-resident.

Returns None if GPU repair is not applicable (no GPU, no polygon families, or CuPy not available).

Parameters

owned : OwnedGeometryArray with device_state invalid_rows : indices of invalid rows to repair geometries : shapely geometry array for all rows method : repair method (only “linework” supported on GPU) keep_collapsed : whether to keep collapsed geometries