# 🟦 SquareNet
SquareNet maps unstructured point clouds to structured grids through a bijective transformation. It replaces expensive spatial queries (k-NN, radius search) with super fast sliding window operations. Think of it as a powerful alternative to kd-trees, voxelization, rasterization and neighborhood graphs. ✔ Works in any dimension ✔ Handles non-convex geometries ✔ Scales to millions of points (fast processing)
-
Speed:
$O(N)$ local operations via vectorized sliding windows. - Memory: Contiguous memory access instead of irregular spatial lookups.
- Simplicity: Pure NumPy-based logic, no heavy spatial dependencies.
pip install squarenet
# To include the demo (shapely)
# pip install "squarenet[demo]"from squarenet import SquareNet
import numpy as np
# Initialize and Fit
N = 5*11*7*13
d = 4
points = np.random.rand(N, d)
IJKL = (5, 11, 7, 13)
sqnet = SquareNet(IJ=IJKL) # Define grid dimensions, here 4D
sqnet.fit(points)
# Map any property of the points to the grid e.g. the norm, could be anything else
Xpts = np.linalg.norm(points, axis = 1) #(N, ...)
Xmap = sqnet.map(Xpts) #(5, 11, 7, 13, ...)
Xrec = sqnet.invert_map(Xmap) #(N, ...)
# Compute Local Gram Matrix (Sparse), restricted to a window
G = sqnet.gram(points, ws=5) #(N, (2ws+1)**d)You can use the built-in checkerboard to verify neighborhood preservation:
sqnet = SquareNet(IJ=(200, 200))
sqnet.fit("france")
sqnet.checkerboard()- Point Cloud Processing: Fast local feature aggregation.
- Kernel Methods: Efficient sparse approximation of large kernels.
- Deep Learning: Pre-structuring irregular data for CNN/Transformer inputs.
License: MIT | Author: ArmanddeCacqueray
