|
| 1 | +# Batched coordinate layout |
| 2 | + |
| 3 | +::: warpconvnet.geometry.base.geometry.Geometry |
| 4 | + |
| 5 | +Geometry containers in WarpConvNet treat batched data as a pair of concatenated tensors |
| 6 | +plus an `offsets` vector. This “batched” layout stores every sample back-to-back inside a |
| 7 | +single tensor while recording where each sample begins so ragged batches stay addressable. |
| 8 | + |
| 9 | +## Concatenated coordinates |
| 10 | + |
| 11 | +`warpconvnet.geometry.base.coords.Coords` keeps two tensors: |
| 12 | + |
| 13 | +- `batched_tensor`: shape `[N, D]` with all coordinates concatenated in batch order. |
| 14 | +- `offsets`: shape `[B + 1]` with `offsets[b]` marking the starting row for batch `b`. |
| 15 | + |
| 16 | +The difference `offsets[b + 1] - offsets[b]` gives the number of coordinates in sample |
| 17 | +`b`. Because the data lives in one tensor, it is cheap to move, sort, or feed to CUDA |
| 18 | +kernels that expect CSR-style layouts. |
| 19 | + |
| 20 | +## Features that share offsets |
| 21 | + |
| 22 | +`warpconvnet.geometry.base.features.Features` mirrors the coordinate batching strategy. |
| 23 | +Both `CatFeatures` (concatenated) and `PadFeatures` (padded) expose the same offsets so |
| 24 | +`Geometry` subclasses can hop between dense and ragged views without recomputing metadata. |
| 25 | + |
| 26 | +- Concatenated features: `[N, C]` storage with the same CSR-style offsets as the |
| 27 | + coordinates. |
| 28 | +- Padded features: `[B, L_max, C]` storage when kernels need dense memory, but each row |
| 29 | + still references the shared offsets to keep track of valid entries. |
| 30 | + |
| 31 | +## Putting it together |
| 32 | + |
| 33 | +The base `Geometry` class validates that coordinates and features have identical offsets, |
| 34 | +then exposes helpers such as `geometry.batch_indexed_coordinates` and AMP-aware feature |
| 35 | +accessors. Subclasses (e.g., `Points`, `Voxels`, `Grid`) inherit these guarantees and add |
| 36 | +type-specific methods on top. |
| 37 | + |
| 38 | +```python |
| 39 | +import torch |
| 40 | +from warpconvnet.geometry.types.points import Points |
| 41 | + |
| 42 | +coords = torch.tensor( |
| 43 | + [ |
| 44 | + [0, 0, 0], |
| 45 | + [0, 1, 0], |
| 46 | + [1, 0, 0], |
| 47 | + [5, 5, 5], |
| 48 | + [6, 5, 5], |
| 49 | + ], |
| 50 | + dtype=torch.int32, |
| 51 | +) |
| 52 | +offsets = torch.tensor([0, 3, 5], dtype=torch.int32) |
| 53 | +features = torch.randn(5, 32) |
| 54 | + |
| 55 | +points = Points(coords, features, offsets=offsets) |
| 56 | +# points.batched_coordinates.offsets == points.batched_features.offsets |
| 57 | +``` |
| 58 | + |
| 59 | +In this example two ragged samples (lengths 3 and 2) share one coordinate tensor and one |
| 60 | +feature tensor. The shared offsets allow the geometry module to slice, move devices, or |
| 61 | +convert between concatenated and padded features without copying metadata. |
0 commit comments