hilbertsfc¶
Core APIs¶
Hilbert¶
Morton¶
Kernel Accessors¶
Hilbert¶
get_hilbert_encode_2d_kernelget_hilbert_decode_2d_kernelget_hilbert_encode_3d_kernelget_hilbert_decode_3d_kernel
Morton¶
get_morton_encode_2d_kernelget_morton_decode_2d_kernelget_morton_encode_3d_kernelget_morton_decode_3d_kernel
Cache Management¶
hilbertsfc ¶
Hilbert space-filling curve kernels.
The top-level hilbertsfc package exposes NumPy/Numba-backed 2D/3D Hilbert
encode/decode functions, plus matching Morton/z-order helpers, kernel accessors,
and cache management utilities.
For GPU acceleration and torch.Tensor inputs, use the optional PyTorch frontend:
hilbertsfc.torch.
Functions¶
hilbert_encode_2d ¶
hilbert_encode_2d(
x: IntScalar | IntArray,
y: IntScalar | IntArray,
*,
nbits: int | None = None,
out: IntArray | None = None,
parallel: bool = False,
) -> int | IntArray
Encode 2D integer coordinates to Hilbert indices.
This function supports both scalar and array inputs:
- Scalar mode: if
xandyare scalar integers, returns a Pythonint. - Array mode: if
xandyare NumPy integer arrays, returns an array of unsigned indices with the same shape and supportsout=.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
IntScalar | IntArray
|
Coordinates to encode.
|
required |
y
|
IntScalar | IntArray
|
Coordinates to encode.
|
required |
nbits
|
int | None
|
Number of bits per coordinate axis. This defines a coordinate domain of
Must satisfy If
For best performance and tighter output dtypes, pass the smallest value that covers the input coordinate range. |
None
|
out
|
IntArray | None
|
Optional output array for array mode. Must have the same shape as Not allowed in scalar mode. |
None
|
parallel
|
bool
|
Controls whether the array-mode Numba kernel may execute in parallel. In scalar mode, this argument is accepted for API consistency but has no
effect. If The number of threads can be controlled with |
False
|
Returns:
| Type | Description |
|---|---|
int | IntArray
|
Hilbert index or indices.
If |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
hilbert_decode_2d ¶
hilbert_decode_2d(
index: IntScalar | IntArray,
*,
nbits: int | None = None,
out_x: IntArray | None = None,
out_y: IntArray | None = None,
parallel: bool = False,
) -> tuple[int, int] | tuple[IntArray, IntArray]
Decode Hilbert indices to 2D integer coordinates.
This function supports both scalar and array inputs:
- Scalar mode: if
indexis a scalar integer, returns(x, y)as Pythonintvalues. - Array mode: if
indexis a NumPy integer array, returns coordinate arrays with the same shape and supportsout_x=/out_y=.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
IntScalar | IntArray
|
Hilbert index or indices to decode.
|
required |
nbits
|
int | None
|
Number of bits per coordinate axis. This defines a coordinate domain of
Must satisfy If
For best performance and tighter output dtypes, pass the smallest value that covers the input index range. |
None
|
out_x
|
IntArray | None
|
Optional output coordinate arrays for array mode. Either provide both or neither. Each must have the same shape as Not allowed in scalar mode. |
None
|
out_y
|
IntArray | None
|
Optional output coordinate arrays for array mode. Either provide both or neither. Each must have the same shape as Not allowed in scalar mode. |
None
|
parallel
|
bool
|
Controls whether the array-mode Numba kernel may execute in parallel. In scalar mode, this argument is accepted for API consistency but has no
effect. If The number of threads can be controlled with |
False
|
Returns:
| Type | Description |
|---|---|
tuple[int, int] | tuple[IntArray, IntArray]
|
Decoded coordinates.
If |
Raises:
| Type | Description |
|---|---|
TypeError
|
If a non-integer input is provided or if output buffers are used in scalar mode. |
ValueError
|
If |
hilbert_encode_3d ¶
hilbert_encode_3d(
x: IntScalar | IntArray,
y: IntScalar | IntArray,
z: IntScalar | IntArray,
*,
nbits: int | None = None,
out: IntArray | None = None,
parallel: bool = False,
) -> int | IntArray
Encode 3D integer coordinates to Hilbert indices.
This function supports both scalar and array inputs:
- Scalar mode: if
x,y, andzare scalar integers, returns a Pythonint. - Array mode: if
x,y, andzare NumPy integer arrays, returns an array of unsigned indices with the same shape and supportsout=.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
IntScalar | IntArray
|
Coordinates to encode.
|
required |
y
|
IntScalar | IntArray
|
Coordinates to encode.
|
required |
z
|
IntScalar | IntArray
|
Coordinates to encode.
|
required |
nbits
|
int | None
|
Number of bits per coordinate axis. This defines a coordinate domain of
Must satisfy If
For best performance and tighter output dtypes, pass the smallest value that covers the input coordinate range. |
None
|
out
|
IntArray | None
|
Optional output array for array mode. Must have the same shape as Not allowed in scalar mode. |
None
|
parallel
|
bool
|
Controls whether the array-mode Numba kernel may execute in parallel. In scalar mode, this argument is accepted for API consistency but has no
effect. If The number of threads can be controlled with |
False
|
Returns:
| Type | Description |
|---|---|
int | IntArray
|
Hilbert index or indices.
If |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
hilbert_decode_3d ¶
hilbert_decode_3d(
index: IntScalar | IntArray,
*,
nbits: int | None = None,
out_x: IntArray | None = None,
out_y: IntArray | None = None,
out_z: IntArray | None = None,
parallel: bool = False,
) -> (
tuple[int, int, int]
| tuple[IntArray, IntArray, IntArray]
)
Decode Hilbert indices to 3D integer coordinates.
This function supports both scalar and array inputs:
- Scalar mode: if
indexis a scalar integer, returns(x, y, z)as Pythonintvalues. - Array mode: if
indexis a NumPy integer array, returns coordinate arrays with the same shape and supportsout_x=,out_y=, andout_z=.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
IntScalar | IntArray
|
Hilbert index or indices to decode.
|
required |
nbits
|
int | None
|
Number of bits per coordinate axis. This defines a coordinate domain of
Must satisfy If
For best performance and tighter output dtypes, pass the smallest value that covers the input index range. |
None
|
out_x
|
IntArray | None
|
Optional coordinate output arrays for array mode. Either provide all three or none. Each must have the same shape as Not allowed in scalar mode. |
None
|
out_y
|
IntArray | None
|
Optional coordinate output arrays for array mode. Either provide all three or none. Each must have the same shape as Not allowed in scalar mode. |
None
|
out_z
|
IntArray | None
|
Optional coordinate output arrays for array mode. Either provide all three or none. Each must have the same shape as Not allowed in scalar mode. |
None
|
parallel
|
bool
|
Controls whether the array-mode Numba kernel may execute in parallel. In scalar mode, this argument is accepted for API consistency but has no
effect. If The number of threads can be controlled with |
False
|
Returns:
| Type | Description |
|---|---|
tuple[int, int, int] | tuple[IntArray, IntArray, IntArray]
|
Decoded coordinates.
If |
Raises:
| Type | Description |
|---|---|
TypeError
|
If a non-integer input is provided or if output buffers are used in scalar mode. |
ValueError
|
If |
morton_encode_2d ¶
morton_encode_2d(
x: IntScalar | IntArray,
y: IntScalar | IntArray,
*,
nbits: int | None = None,
out: IntArray | None = None,
parallel: bool = False,
) -> int | IntArray
Encode 2D integer coordinates to Morton (Z-order) indices.
API semantics (parameters, returns, errors) match
hilbert_encode_2d.
This function supports both scalar and array inputs:
- Scalar mode: if
xandyare scalar integers, returns a Pythonint. - Array mode: if
xandyare NumPy integer arrays, returns an array of unsigned indices with the same shape and supportsout=.
morton_decode_2d ¶
morton_decode_2d(
index: IntScalar | IntArray,
*,
nbits: int | None = None,
out_x: IntArray | None = None,
out_y: IntArray | None = None,
parallel: bool = False,
) -> tuple[int, int] | tuple[IntArray, IntArray]
Decode Morton (Z-order) indices to 2D integer coordinates.
API semantics (parameters, returns, errors) match
hilbert_decode_2d.
This function supports both scalar and array inputs:
- Scalar mode: if
indexis a scalar integer, returns(x, y)as Pythonintvalues. - Array mode: if
indexis a NumPy integer array, returns coordinate arrays with the same shape and supportsout_x=/out_y=.
morton_encode_3d ¶
morton_encode_3d(
x: IntScalar | IntArray,
y: IntScalar | IntArray,
z: IntScalar | IntArray,
*,
nbits: int | None = None,
out: IntArray | None = None,
parallel: bool = False,
) -> int | IntArray
Encode 3D integer coordinates to Morton (Z-order) indices.
API semantics (parameters, returns, errors) match
hilbert_encode_3d.
This function supports both scalar and array inputs:
- Scalar mode: if
x,y, andzare scalar integers, returns a Pythonint. - Array mode: if
x,y, andzare NumPy integer arrays, returns an array of unsigned indices with the same shape and supportsout=.
morton_decode_3d ¶
morton_decode_3d(
index: IntScalar | IntArray,
*,
nbits: int | None = None,
out_x: IntArray | None = None,
out_y: IntArray | None = None,
out_z: IntArray | None = None,
parallel: bool = False,
) -> (
tuple[int, int, int]
| tuple[IntArray, IntArray, IntArray]
)
Decode Morton (Z-order) indices to 3D integer coordinates.
API semantics (parameters, returns, errors) match
hilbert_decode_3d.
This function supports both scalar and array inputs:
- Scalar mode: if
indexis a scalar integer, returns(x, y, z)as Pythonintvalues. - Array mode: if
indexis a NumPy integer array, returns coordinate arrays with the same shape and supportsout_x=,out_y=, andout_z=.
get_hilbert_encode_2d_kernel ¶
get_hilbert_encode_2d_kernel(
nbits: int, *, tile_nbits: TileNBits2D | None = None
) -> Callable[[IntScalar, IntScalar], int]
Return a Numba-compiled scalar 2D Hilbert encoder.
This is the low-level kernel used by hilbert_encode_2d in scalar mode.
It is intended for fusing into your own @numba.njit loops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nbits
|
int
|
Number of coordinate bits (grid domain is |
required |
tile_nbits
|
TileNBits2D | None
|
Select the tile size (in bits) / kernel variant.
The 7-bit variant uses a larger LUT and is generally faster. The 4-bit variant uses a smaller LUT, which may be preferable in cache-intensive kernels. |
None
|
Returns:
| Type | Description |
|---|---|
callable
|
A Numba-compiled function with signature |
get_hilbert_decode_2d_kernel ¶
get_hilbert_decode_2d_kernel(
nbits: int, *, tile_nbits: TileNBits2D | None = None
) -> Callable[[IntScalar], tuple[int, int]]
Return a Numba-compiled scalar 2D Hilbert decoder.
This is the low-level kernel used by hilbert_decode_2d in scalar mode.
It is intended for fusing into your own @numba.njit loops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nbits
|
int
|
Number of coordinate bits (grid domain is |
required |
tile_nbits
|
TileNBits2D | None
|
Select the tile size (in bits) / kernel variant.
The 7-bit variant uses a larger LUT and is generally faster. The 4-bit variant uses a smaller LUT, which may be preferable in cache-intensive kernels. |
None
|
Returns:
| Type | Description |
|---|---|
callable
|
A Numba-compiled function with signature |
get_hilbert_encode_3d_kernel ¶
get_hilbert_encode_3d_kernel(
nbits: int, *, lut_dtype: LutUIntDTypeLike = uint16
) -> Callable[[IntScalar, IntScalar, IntScalar], IntScalar]
Return a Numba-compiled scalar 3D Hilbert encoder.
This is the low-level kernel used by hilbert_encode_3d in scalar mode
and is intended for fusing into your own @numba.njit loops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nbits
|
int
|
Number of coordinate bits (grid domain is |
required |
lut_dtype
|
LutUIntDTypeLike
|
Element dtype used for the internal lookup tables. Default is For best throughput, it is usually better to match |
uint16
|
Returns:
| Type | Description |
|---|---|
callable
|
A Numba-compiled function with signature |
get_hilbert_decode_3d_kernel ¶
get_hilbert_decode_3d_kernel(
nbits: int, *, lut_dtype: LutUIntDTypeLike = uint16
) -> Callable[[IntScalar], tuple[int, int, int]]
Return a Numba-compiled scalar 3D Hilbert decoder.
This is the low-level kernel used by hilbert_decode_3d in scalar mode
and is intended for fusing into your own @numba.njit loops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nbits
|
int
|
Number of coordinate bits (grid domain is |
required |
lut_dtype
|
LutUIntDTypeLike
|
Element dtype used for the internal lookup tables. See |
uint16
|
Returns:
| Type | Description |
|---|---|
callable
|
A Numba-compiled function with signature |
get_morton_encode_2d_kernel ¶
Return a Numba-compiled scalar 2D Morton encoder.
This is the low-level kernel used by morton_encode_2d in scalar mode.
It is intended for fusing into your own @numba.njit loops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nbits
|
int
|
Number of coordinate bits (grid domain is |
required |
Returns:
| Type | Description |
|---|---|
callable
|
A Numba-compiled function with signature |
get_morton_decode_2d_kernel ¶
Return a Numba-compiled scalar 2D Morton decoder.
This is the low-level kernel used by morton_decode_2d in scalar mode.
It is intended for fusing into your own @numba.njit loops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nbits
|
int
|
Number of coordinate bits (grid domain is |
required |
Returns:
| Type | Description |
|---|---|
callable
|
A Numba-compiled function with signature |
get_morton_encode_3d_kernel ¶
get_morton_encode_3d_kernel(
nbits: int,
) -> Callable[[IntScalar, IntScalar, IntScalar], IntScalar]
Return a Numba-compiled scalar 3D Morton encoder.
This is the low-level kernel used by morton_encode_3d in scalar mode.
It is intended for fusing into your own @numba.njit loops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nbits
|
int
|
Number of coordinate bits (grid domain is |
required |
Returns:
| Type | Description |
|---|---|
callable
|
A Numba-compiled function with signature |
get_morton_decode_3d_kernel ¶
Return a Numba-compiled scalar 3D Morton decoder.
This is the low-level kernel used by morton_decode_3d in scalar mode.
It is intended for fusing into your own @numba.njit loops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nbits
|
int
|
Number of coordinate bits (grid domain is |
required |
Returns:
| Type | Description |
|---|---|
callable
|
A Numba-compiled function with signature |
clear_lut_caches ¶
clear_lut_caches() -> None
Clear all registered LUT caches.
Notes
This does not clear torch-side device LUT caches; for those, see
hilbertsfc.torch.clear_torch_lut_caches.
clear_all_caches ¶
clear_all_caches() -> None
Clear LUT caches and kernel builder caches.
Notes
This does not clear torch-side device LUT caches; for those, see
hilbertsfc.torch.clear_torch_lut_caches.