Skip to main content

Fast N-dimensional Delaunay triangulation with incremental point insertion

Project description

adaptive-triangulation

CI License

Fast N-dimensional Delaunay triangulation in Rust with Python bindings (PyO3). Drop-in replacement for adaptive's Triangulation class — 5-99× faster.

Performance

Standalone triangulation (incremental insertion)

Case Rust Python Speedup
2D, 1K pts 38.5 ms 668 ms 17×
2D, 5K pts 260 ms 8,547 ms 33×
3D, 500 pts 133 ms 5,571 ms 42×

LearnerND integration (end-to-end, ring_of_fire 2D)

N pts Learner2D (scipy) LearnerND (Python) LearnerND (Rust)
1,000 0.34 s 0.91 s 0.23 s
2,000 1.17 s 1.80 s 0.38 s
5,000 6.99 s 4.57 s 0.99 s

LearnerND + Rust is 5× faster than LearnerND + Python, and 7× faster than Learner2D at 5K points.

Installation

pip install adaptive-triangulation

Requires a Rust toolchain for building from source. Pre-built wheels are available for common platforms via CI.

Quick start

from adaptive_triangulation import Triangulation

# Build a 2D triangulation
tri = Triangulation([(0, 0), (1, 0), (0, 1), (1, 1)])

# Insert points incrementally (Bowyer-Watson)
deleted, added = tri.add_point((0.5, 0.5))

# Query properties
print(len(tri.simplices))     # number of triangles
print(tri.dim)                # 2
print(tri.reference_invariant())  # True

Usage with adaptive's LearnerND

This is a drop-in replacement for adaptive's built-in triangulation. Monkey-patch the module to use Rust triangulation everywhere:

import adaptive_triangulation as at
from adaptive.learner import learnerND as lnd_mod
from adaptive.learner.learnerND import LearnerND

# Replace both the class and standalone functions
lnd_mod.Triangulation = at.Triangulation
lnd_mod.circumsphere = at.circumsphere
lnd_mod.simplex_volume_in_embedding = at.simplex_volume_in_embedding
lnd_mod.point_in_simplex = at.point_in_simplex

# Now use LearnerND as normal — it's 5× faster
learner = LearnerND(my_function, bounds=[(-1, 1), (-1, 1)])

See examples/adaptive_learnernd.py for a full working example with timing comparison.

API

Triangulation class

tri = Triangulation(coords)           # Build from initial points
tri.add_point(point)                   # Incremental insertion → (deleted, added)
tri.locate_point(point)                # Find containing simplex
tri.circumscribed_circle(simplex)      # → (center, radius)
tri.volume(simplex)                    # Simplex volume
tri.volumes()                          # All simplex volumes
tri.point_in_simplex(point, simplex)   # Containment test
tri.point_in_circumcircle(pt, simplex) # Circumcircle test
tri.bowyer_watson(pt_index)            # Direct Bowyer-Watson
tri.reference_invariant()              # Consistency check

Properties: vertices, simplices, vertex_to_simplices, hull, dim, default_transform

Standalone functions

from adaptive_triangulation import (
    circumsphere,              # General circumsphere
    fast_2d_circumcircle,      # Optimized 2D
    fast_3d_circumsphere,      # Optimized 3D
    point_in_simplex,          # Containment test
    volume,                    # Simplex volume
    simplex_volume_in_embedding,  # Volume in embedding space
    orientation,               # Face orientation
)

Examples

Development

# Build (requires Rust toolchain)
pip install maturin
maturin develop --release

# Tests
cargo test                    # Rust tests
python -m pytest tests/ -v    # Python tests

# Linting
pre-commit run --all-files    # ruff, mypy, cargo fmt, cargo clippy

License

BSD-3-Clause

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

adaptive_triangulation-0.1.0.tar.gz (76.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

adaptive_triangulation-0.1.0-cp310-abi3-win_amd64.whl (290.7 kB view details)

Uploaded CPython 3.10+Windows x86-64

adaptive_triangulation-0.1.0-cp310-abi3-macosx_11_0_arm64.whl (334.7 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

adaptive_triangulation-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (366.6 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file adaptive_triangulation-0.1.0.tar.gz.

File metadata

  • Download URL: adaptive_triangulation-0.1.0.tar.gz
  • Upload date:
  • Size: 76.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for adaptive_triangulation-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9a1250d6cd8d72a205a5a356bdd3899ccb0220818749b5018d75672c4d50923a
MD5 9e4898e1d12606ff1d53e72526233ae9
BLAKE2b-256 93c4f7b681e659cb9ccb07f8e8d1afa406c4195d4d1deb03a8634273f2e9bc31

See more details on using hashes here.

Provenance

The following attestation bundles were made for adaptive_triangulation-0.1.0.tar.gz:

Publisher: ci.yml on python-adaptive/adaptive-triangulation

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file adaptive_triangulation-0.1.0-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for adaptive_triangulation-0.1.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 87086075a1c0582ec7b66c982414156053746cb8a0d082a657e8739c183f8bf2
MD5 fb0d9e6afcf50ad56324915ed45bcefb
BLAKE2b-256 f1b450bca8f66cbd8b711df1a4762fd37ff827e80a478d221a86d1dbc942c563

See more details on using hashes here.

Provenance

The following attestation bundles were made for adaptive_triangulation-0.1.0-cp310-abi3-win_amd64.whl:

Publisher: ci.yml on python-adaptive/adaptive-triangulation

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file adaptive_triangulation-0.1.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for adaptive_triangulation-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0259002626fccd2b9765d06f5e09fc7e37968771516f20ff23a1d358e5324051
MD5 17a64b473acbfcfe0ecae4b3c7bb963c
BLAKE2b-256 524f33dc53d443dbf3519446d28c7d67aa38c9622c497a55530f53de98ded3c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for adaptive_triangulation-0.1.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: ci.yml on python-adaptive/adaptive-triangulation

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file adaptive_triangulation-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for adaptive_triangulation-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bfb7eae4f5f5fa84d4df662ce7d3f63b80ad42079c613d75b02f7ab0a22b9d75
MD5 e780f1fdef6ae913e14fdd2c2ca77e36
BLAKE2b-256 7797631aa92fdfe6fe2f92544240d49043da4bcf7c4037df85c901af34f659d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for adaptive_triangulation-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci.yml on python-adaptive/adaptive-triangulation

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page