Skip to main content

❒ 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 faster sorting algorithm.

Take raw point cloud X(N, D)
→ find a grid shape and a permutation order such that
Xgrid = X[order].reshape(*gridshape, D) is sorted along every axis of the grid.
→ On the Xgrid view of X, neighbor queries become a simple stencil look-up
neighborhood[i, j, k] = {Xgrid[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 (grid convolution, clustering, …) can then be applied
directly on the Xgrid view instead of relying on complex graph convolutions
or other point-cloud techniques.

X 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 deal with prime or variable 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)
X = np.random.rand(1_000_000, 3)

# Sorted view: place the points inside the grid
order = grid.argsort(X, gridshape=(100, 100, 100))
Yflat = X[order]
Ygrid = Yflat.reshape(100, 100, 100, 3)

# Rest of your pipeline, working with grids
Zgrid = apply_something(Ygrid)

# Back to the original points indexing
Zflat = Zgrid.reshape(-1, 2)
orderinv = grid.invert_permutation(order)
Z = Zflat[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( Xgrid[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.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gridpoints 1.0.3
File Size Uploaded
gridpoints-1.0.3.tar.gz 14.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gridpoints 1.0.3
File Interpreter ABI Platform
gridpoints-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 28.6 kB

Release files / gridpoints-1.0.3.tar.gz

Download URL gridpoints-1.0.3.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
699e418eb940f1512265831f36c36e125dd31d1f3afbb67dc0e4270f63802565
BLAKE2b-256 checksum
How to use checksums
0bcea5e470ddc6a1d1f61420f1a5f3e2d0163f4ceed5bd061601eea577aa07fe
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.3-py3-none-any.whl

Download URL gridpoints-1.0.3-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e1f06d3e213fd3e838a61ac72c08bb5dc72c5c04c408238f6884878e91e8665c
BLAKE2b-256 checksum
How to use checksums
4888779c8523f7cf8ca295a5d3f6934544ed21e9c85ad23808984d709e350938
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release history Release notifications | RSS feed

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page