API Reference¶
Reference documentation is generated from Python docstrings in the grumpy package. For narrative tutorials, start at Home and follow the section links at the bottom of each page.
Top-level API¶
Grumpy: high-performance numerical computing on ragged and nested data.
Grumpy provides Awkward-like layout semantics with strong typing, explicit nullability,
mutable arrays, Zarr-backed lazy I/O via :func:open, and optional compilation of transforms.
Layouts
Arrays use either list-chains (ListOffset -> … -> Leaf) or **UnionScalarList``**
(mixed scalar/list rows at one axis). Both are constructed with :func:array`, persisted to
Zarr, streamed, and used in dataframes.
Notes
- :func:
openexposes lazy on-disk dataframes; row/schema indexing materializes subsets; column access returns lazy column proxies until indexed. gr.compileaccepts a restricted subset of Python (see :func:compile); scalar elementwise opcodes fuse on union batches as well as list-chains.
add ¶
Elementwise add with optional pre-allocated out.
array ¶
Construct a GrumpyArray from Python scalars / nested lists or tuples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Python scalar or nested Python sequences (lists/tuples) of arbitrary depth. |
required | |
dtype
|
DType | None
|
Optional explicit dtype. If omitted, dtype is inferred from non-null leaves. |
None
|
bincount ¶
can_cast ¶
Return whether from_dtype can be cast to to_dtype under casting.
cat ¶
Concatenate arrays along a ragged dimension.
from_numpy ¶
Build a rectangular :class:GrumpyArray from a C-contiguous NumPy array.
from_tensorflow ¶
Build a rectangular :class:GrumpyArray from a TensorFlow tensor (via .numpy()).
from_torch ¶
Build a rectangular :class:GrumpyArray from a PyTorch tensor (via .numpy()).
full_like ¶
Create an array with the same ragged structure as x, filled with fill_value.
gpu_available ¶
Return True when a GPU backend (Metal or CUDA) is available.
gpu_backend ¶
Return 'metal', 'cuda', or None if no GPU backend is active.
grid_pool ¶
grid_pool(x: GrumpyArray, grid_size: tuple[int, int, int], *, origin: tuple[float, float, float] | None = None, voxel_size: tuple[float, float, float] | None = None, dim: int = 1) -> GrumpyArray
Voxelize point clouds by counting points per grid cell (occupancy pooling).
Returns (n_groups, nx*ny*nz) occupancy grids per group.
histogram ¶
histogram(x: GrumpyArray, bins: int = 10, range: tuple[float, float] | None = None, density: bool = False, weights: GrumpyArray | None = None) -> tuple[GrumpyArray, GrumpyArray]
is_rectangular ¶
Return whether arr can be exported as a dense rectangular tensor.
multiply ¶
Elementwise multiply with optional pre-allocated out (NumPy out= style).
neighbors ¶
neighbors(query: GrumpyArray, data: GrumpyArray, k: int | None = None, radius: float | None = None, dim: int = 0, loop: bool = True, return_distances: bool = False, gpu: bool | str = False)
Compute neighbors and return an edge index (and optionally distances).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
GrumpyArray
|
Coordinate arrays. For |
required |
data
|
GrumpyArray
|
Coordinate arrays. For |
required |
k
|
int | None
|
Number of nearest neighbors (mutually exclusive with |
None
|
radius
|
float | None
|
Include all neighbors within this distance (mutually exclusive with |
None
|
dim
|
int
|
Axis along which groups of points live ( |
0
|
loop
|
bool
|
If |
True
|
return_distances
|
bool
|
If |
False
|
gpu
|
bool | str
|
|
False
|
Returns:
| Name | Type | Description |
|---|---|---|
edge_index |
Ragged edge index with last axis length 2: |
|
distances (optional):
|
Returned when |
ones_like ¶
Create an array with the same ragged structure as x, filled with ones.
open ¶
Open a saved dataset as a lazy on-disk handle.
Row and schema indexing materialize subset dataframes. Column selection
(df['col'] or df.col) returns an :class:OpenColumn proxy until
the column is indexed.
cache controls session I/O caching: "chunks" (default) keeps a
byte-bounded LRU of decoded Zarr chunks; "metadata" pins only offset
buffers; "none" disables caching.
Call :meth:~grumpy.OpenDataFrame.close when finished, or use a context
manager::
with gr.open("data.gr") as h:
batch = h[[0, 1, 2]]
pairwise_distances ¶
All-pairs Euclidean distances within each point cloud (group).
For dim=1, input shape is (n_groups, n_points, d); output is
(n_groups, n_points, n_points) distance matrices.
promote_types ¶
NumPy-style binary result dtype for two dtypes.
save ¶
Save a GrumpyArray/DataFrame, or incrementally write batches from a generator.
subtract ¶
Elementwise subtract with optional pre-allocated out.
zeros_like ¶
Create an array with the same ragged structure as x, filled with zeros.
Core types¶
Compilation¶
Compile restricted batch transforms into fused Rust execution plans.
The compiler analyzes straight-line Python functions (typically def f(batch): ...)
and builds :class:~grumpy._core.CompiledPlan opcode lists for the
:func:compile decorator and direct invocation on batches.
Supported inputs
- List-chain and
UnionScalarListbatches for scalar elementwise opcodes (batch * 2,batch + 1, …). - Reduction and neighbor opcodes when the underlying Rust kernel supports the layout.
Known limitations
- No control flow (
if/for/try), no imports, singlebatchparameter. - Rust scheduling of multi-batch pipelines is handled outside Grumpy (e.g. Fabric).
CompiledTransform ¶
Callable wrapper that runs a compiled Rust plan when possible.
Instances are returned by :func:compile.
Attributes:
| Name | Type | Description |
|---|---|---|
is_compiled |
bool
|
Whether a Rust :class: |
compile_error |
str or None
|
Compilation failure message when |
Examples:
>>> import grumpy as gr
>>> @gr.compile
... def scale(batch):
... return batch * 2
...
>>> scale.is_compiled
True
>>> scale(gr.array([1, 2])).to_list()
[2, 4]
compile_error
property
¶
is_compiled
property
¶
__call__ ¶
Run the compiled plan or fall back to the original Python function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
GrumpyArray or GrumpyDataFrame
|
Input batch. |
required |
Returns:
| Type | Description |
|---|---|
GrumpyArray or GrumpyDataFrame
|
Transformed batch. |
Examples:
compile ¶
Compile a restricted batch transform into a Rust execution plan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
callable
|
Function |
required |
Returns:
| Type | Description |
|---|---|
CompiledTransform
|
Callable wrapper that executes the plan when compilation succeeds. |
Examples:
Next: Developer — repository layout, implementation notes, and error handling.