Skip to content

Conversation

basnijholt
Copy link
Member

@basnijholt basnijholt commented Aug 21, 2025

This is just an experiment and 100% vibe coded... I want to see whether we can get a significant speedup by implementing the LearnerND in Rust.

This commit introduces a high-performance Rust implementation of the triangulation
module for the adaptive library, providing significant speedup for geometric operations.

Key changes:
- Add Rust project structure with PyO3 bindings (Cargo.toml, src/)
- Implement core geometric algorithms in Rust (circumsphere, volume, point_in_simplex)
- Create full Bowyer-Watson triangulation algorithm in Rust
- Add Python wrapper with automatic fallback to Python implementation
- Achieve 12-17x speedup for point addition and 14-15x for point location

The Rust implementation maintains 100% API compatibility with the existing Python
code and includes optimizations for 2D/3D cases while supporting N-dimensional
operations. All tests pass with the new implementation.

To build: maturin develop
To use: The triangulation_rust.py module automatically uses Rust when available
…ation

- Fixed incorrect indexing in Cramer's rule implementation for N-dimensional circumsphere
- Added direct triangulation performance benchmarks showing 11-16x speedup
- Verified Rust implementation works correctly in release mode

Performance results:
- Triangulation creation/addition: 11.64x speedup
- Point location queries: 16.13x speedup
@basnijholt basnijholt closed this Aug 22, 2025
@akhmerov
Copy link
Contributor

What were your findings?

@basnijholt
Copy link
Member Author

That in (N>2)D SciPy is actually really fast, it was like >100x faster then the Rust code but in 2D Rust was 5-30x faster. Didn't do a lot of validation of whether it was doing the optimal thing though.

@akhmerov
Copy link
Contributor

I thought scipy triangulation isn't designed for incremental updates; did you test on adding points one at a time or all at once?

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.

2 participants