Torch Delaunay - The Delaunay triangulation library for PyTorch

March 28, 2025 · View on GitHub

This is a fast library for computing Delaunay triangulation of 2-dimensional points.

The implementation is based on a sweep-algorithm, introduced by David Sinclair1 and later improved by Volodymyr Agafonkin2.

Here is an example of triangulation output produced by Torch Delaunay library for a random set of points: example

Installation

The library is distributed as PyPI package, to install the package, execute the following command:

pip install torch_delaunay

You can use the torch_delaunay library for a fast computation of Delaunay triangulation for points defined as PyTorch tensors.

Usage

import torch
from torch_delaunay.functional import shull2d
import matplotlib.pyplot as plt

# Compute Delaunay triangulation for randomly-generated 2-dimensional points.
points = torch.rand((100, 2))
simplices = shull2d(points)

# Plot the result
plt.triplot(points[:, 0], points[:, 1], triangles=simplices)
plt.title("Delaunay Triangulation")

Benchmarks

Benchmarks are collected on Apple M1 Pro chip with 32 GiB of memory.

Prob. DistributionData TypeSamplesTimeCPUIterations
UniformFloat64100004.18 ms4.11 ms171
UniformFloat6410000049.6 ms48.3 ms15
UniformFloat641000000600 ms592 ms1
UniformFloat32100004.37 ms4.29 ms161
UniformFloat3210000047.4 ms46.4 ms15
UniformFloat321000000573 ms568 ms1
NormalFloat64100004.60 ms4.49 ms156
NormalFloat6410000048.5 ms47.4 ms15
NormalFloat641000000568 ms563 ms1
NormalFloat32100004.42 ms4.33 ms165
NormalFloat3210000046.5 ms45.4 ms15
NormalFloat321000000550 ms547 ms1

License

The Torch Delaunay is distributed under GPLv3 license. See the LICENSE file for full license text.

Footnotes

  1. David Sinclair - S-hull: a fast radial sweep-hull routine for Delaunay triangulation.

  2. Volodymyr Agafonkin - Delaunator: An incredibly fast and robust JavaScript library for Delaunay triangulation of 2D points.