Add optional Rust-accelerated triangulation backend for LearnerND#493
Merged
Conversation
If the optional adaptive-triangulation package (>= 0.2.1) is installed, its Rust Triangulation implementation is now used automatically as a drop-in replacement for the pure-Python one, making LearnerND significantly faster. - New adaptive/learner/triangulation_backend.py selects the backend at import time; ADAPTIVE_TRIANGULATION_BACKEND=auto|python|rust overrides the automatic selection globally. - LearnerND gains a triangulation_backend keyword argument accepting "auto" (default), "python", "rust", or a Triangulation-compatible class for per-learner control. - The pure-Python adaptive.learner.triangulation names are never shadowed, so existing pickles that reference them keep loading. - Fix _pop_highest_existing_simplex evaluating `None in ...simplices` for stale queue entries (Python sets return False; the Rust proxy raises TypeError). - Add the `rust` optional-dependency extra, tests, and docs.
This was referenced Jun 10, 2026
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.
Summary
If the optional adaptive-triangulation package (>= 0.2.1) is installed, its Rust
Triangulationis now used automatically as a drop-in replacement for the pure-Python implementation, makingLearnerNDsignificantly faster (~3.7x end-to-end onring_of_fire, and ~7x faster thanLearner2Dat 5k points).pip install "adaptive[rust]"How it works
adaptive/learner/triangulation_backend.pyselects the backend at import time: the Rust package when importable and >= 0.2.1, otherwise the pure-Python implementation.learnerND.py,learner1D.py, andlearner2D.pyimportTriangulation/circumsphere/point_in_simplex/simplex_volume_in_embeddingfrom it.LearnerND(..., triangulation_backend="auto" | "python" | "rust"), or pass aTriangulation-compatible class directly."rust"raises a helpfulImportErrorwhen the package is missing or too old.ADAPTIVE_TRIANGULATION_BACKEND=auto|python|rustenvironment variable.adaptive.learner.triangulationnames are deliberately never shadowed, so existing pickles that referenceadaptive.learner.triangulation.Triangulationby qualified name keep loading, and oldLearnerNDpickles fall back to a class-level_triangulation_classattribute.Bug fix
_pop_highest_existing_simplexevaluatedNone in self._subtriangulations[simplex].simplicesfor stale queue entries. Python sets returnFalse; the Rust proxy raisesTypeError. Now guarded withsubsimplex is not None.Testing
adaptive/tests/unit/test_triangulation_backend.pycovering auto-selection, env-var override, constructor argument, custom class pass-through, and error paths.simplex_volume_in_embeddingraises on collinear input where the reference returns 0.0) - to be fixed there; only a_MIN_RUST_VERSIONbump is needed here afterwards.Note: the
rustextra is not added to thetest/devextras yet; consider adding a CI job with the Rust backend once the degenerate-simplex fix is released.