❒ Gridpoints — Multi dimensional sort for point clouds
Gridpoints maps unstructured point clouds to structured grids through a bijective transformation: one point, one cell, no overlap, fully invertible. It replaces and enhances the squarenet project with a more powerfull sorting algorithm.
What it does: Take raw point cloud P(N, D) and find a grid shape and an index permutation order such that Pgrid = P[order].reshape(*gridshape, D)
is sorted along every axis of the grid. E.g. in 3D, for Pgrid = (x, y, z):
x[i+1, j, k] >= x[i, j, k]
y[i, j+1, k] >= y[i, j, k]
z[i, j, k+1] >= z[i, j, k]
→ On the Pgrid view of P, neighbor queries become a simple stencil look-up :
neighborhood[i, j, k] = {Pgrid[i±di, j±dj, k±dk] | (di, dj, dk) ≤ R},
where R is a radius cutoff to determine, allowing local operations in linear time.
→ Standard operations (convolution, clustering, …) can then be applied
directly on the Pgrid view instead of relying on complex graph convolutions
or other point-cloud techniques.
P can be a NumPy, PyTorch or CuPy array of any dimension (N, D).
To allow natural padding when the grid has more cells than points,
NaNs and Infs are supported in a consistent manner:
- nans → random position
- (+-) infs → border of the grid
This allow to gridsort prime or variable number of points N, as long as one is ready to deal with void/special grid cells.
Expected runtime for sorting 1 million points: CPU → < 10s, GPU → < 500 ms
Installation
pip install gridpoints # core only
pip install gridpoints[demo] # for the demonstration notebook, see `notebook.ipynb`
Quickstart
import gridpoints as grid
import numpy as np
# Raw point cloud (numpy, pytorch or cupy)
A = np.random.rand(1_000_000, 3)
# Sorted view: place the points inside the grid
order = grid.argsort(A, gridshape=(100, 100, 100))
Bflat = A[order]
Bgrid = Bflat.reshape(100, 100, 100, 3)
# Rest of your pipeline, working with grids
Cgrid = apply_something(Bgrid)
# Back to the original points indexing
Cflat = Cgrid.reshape(-1, 3)
orderinv = grid.invert_permutation(order)
C = Cflat[orderinv] # matches the initial points order
Note on the cutoff radius R
There is no strict theoretical guarantee about what the cutof radius R should be for a given task. E.g the relative grid position between a point and its nearest neighbors can't be garanted to be in the exact adjacent grid cells. What is guaranteed from the sorted ordering is only grid monotonicity: x coordinates increase along rows, y coordinates along columns, and so on.
As an example, empirical results in 2-D show that R = 5 is enough for ~99 % of the nearest neighbors; some outlier neighbors will sit further apart for complex geometries with pronounced peaks, holes or any non-smoothness. When a stricter neighborhood is required, or in high dimensional setting, the best practice is to build an assembly of grid experts, each working on a rotated / projected view of the points, as discussed in this topic.
Note on efficient stencil operations
The typical use-case of Gridpoints is to allow fast local operations on arbitrary point clouds using stencil kernels:
output(i, j, k) = f( Pgrid[i±di, j±dj, k±dk] | di, dj, dk in local window )
To go beyond standard (slow) python loops, this can be accelerated with native grid convolution operations of standard libraries whenever possible, or with pystencils or taichi compilers for complex/non linear grid kernels.
Metadata
Release files for gridpoints 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gridpoints-1.0.4.tar.gz | 14.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gridpoints-1.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.7 kB
Release files / gridpoints-1.0.4.tar.gz
| Download URL | gridpoints-1.0.4.tar.gz |
|---|---|
| Size | 14.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2755f0b90f3d00e9a11da450657e8adce1ba9317289bef42736f54d0d0acb78a
|
|
BLAKE2b-256 checksum How to use checksums |
867fe616a37b01a7116ddfe9e91bdcf5cc9a10b8f7e3ab0be727a219ed9c5412
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Release files / gridpoints-1.0.4-py3-none-any.whl
| Download URL | gridpoints-1.0.4-py3-none-any.whl |
|---|---|
| Size | 14.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7a822695665513cd20c3943451a9e008350aa1003201daade824a13c3629abc6
|
|
BLAKE2b-256 checksum How to use checksums |
9f6212c61e86cdf773eca866a1ba14322c0b4e603506153c27e00c33f9686b65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|