Package API¶
This page documents the top-level hilbertsfc package exports (including cache helpers).
hilbertsfc package.
This package is intended to host Hilbert space-filling curve kernels and their lookup tables as lazily-loaded package resources.
Public API lives in:
- hilbertsfc.hilbert2d
- hilbertsfc.hilbert3d
get_hilbert_decode_2d_kernel ¶
get_hilbert_decode_2d_kernel(
nbits: int,
) -> Callable[[IntScalar], tuple[int, int]]
Return a Numba-compiled scalar 2D Hilbert decoder.
This is the low-level kernel used by :func: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 |
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 = np.uint16
) -> Callable[[IntScalar], tuple[int, int, int]]
Return a Numba-compiled scalar 3D Hilbert decoder.
This is the low-level kernel used by :func: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 :func: |
uint16
|
Returns:
| Type | Description |
|---|---|
callable
|
A Numba-compiled function with signature |
get_hilbert_encode_2d_kernel ¶
get_hilbert_encode_2d_kernel(
nbits: int,
) -> Callable[[IntScalar, IntScalar], int]
Return a Numba-compiled scalar 2D Hilbert encoder.
This is the low-level kernel used by :func: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 |
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 = np.uint16
) -> Callable[[IntScalar, IntScalar, IntScalar], IntScalar]
Return a Numba-compiled scalar 3D Hilbert encoder.
This is the low-level kernel used by :func: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 |
hilbert_decode_2d ¶
hilbert_decode_2d(
index: IntScalar | IntArray,
*,
nbits: int | None = None,
out_xs: IntArray | None = None,
out_ys: IntArray | None = None,
parallel: bool = False,
) -> tuple[int, int] | tuple[IntArray, IntArray]
Decode a Hilbert index to 2D coordinates.
This is a unified entrypoint:
- Scalar mode: if
indexis a scalar integer, returns(x, y)as Pythonint. - Array mode: if
indexis a NumPy integer array, returns(xs, ys)as NumPy arrays and supportsout_xs=/out_ys=.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
IntScalar | IntArray
|
Hilbert index or indices to decode.
Boolean inputs are rejected. |
required |
nbits
|
int | None
|
Number of coordinate bits (grid domain is Must satisfy If
|
None
|
out_xs
|
IntArray | None
|
Optional output buffers for array mode. Either provide both or neither.
Must have the same shape as |
None
|
out_ys
|
IntArray | None
|
Optional output buffers for array mode. Either provide both or neither.
Must have the same shape as |
None
|
parallel
|
bool
|
Array mode: if Scalar mode: accepted for API consistency, but ignored. If The number of threads can be controlled with the environment variable
|
False
|
Returns:
| Type | Description |
|---|---|
(int, int) or (ndarray, ndarray)
|
The decoded coordinates. When output buffers are not provided in array mode, the coordinate dtype is chosen automatically:
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If boolean inputs are provided or if output buffers are used in scalar mode. |
ValueError
|
If |
hilbert_decode_3d ¶
hilbert_decode_3d(
index: IntScalar | IntArray,
*,
nbits: int | None = None,
out_xs: IntArray | None = None,
out_ys: IntArray | None = None,
out_zs: IntArray | None = None,
parallel: bool = False,
) -> (
tuple[int, int, int]
| tuple[IntArray, IntArray, IntArray]
)
Decode a Hilbert index to 3D coordinates.
This is a unified entrypoint:
- Scalar mode: if
indexis a scalar integer, returns(x, y, z)as Pythonint. - Array mode: if
indexis a NumPy integer array, returns(xs, ys, zs)as NumPy arrays and supportsout_xs=/out_ys=/out_zs=.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
IntScalar | IntArray
|
Hilbert index or indices to decode.
Boolean inputs are rejected. |
required |
nbits
|
int | None
|
Number of coordinate bits (grid domain is Must satisfy If
|
None
|
out_xs
|
IntArray | None
|
Optional output buffers for array mode. Either provide all three or none.
Must have the same shape as |
None
|
out_ys
|
IntArray | None
|
Optional output buffers for array mode. Either provide all three or none.
Must have the same shape as |
None
|
out_zs
|
IntArray | None
|
Optional output buffers for array mode. Either provide all three or none.
Must have the same shape as |
None
|
parallel
|
bool
|
Array mode: if Scalar mode: accepted for API consistency, but ignored. If The number of threads can be controlled with the environment variable
|
False
|
Returns:
| Type | Description |
|---|---|
(int, int, int) or (ndarray, ndarray, ndarray)
|
The decoded coordinates. When output buffers are not provided in array mode, the coordinate dtype is chosen automatically:
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If boolean inputs are provided or if output buffers are used in scalar mode. |
ValueError
|
If |
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 coordinates to a Hilbert index.
This is a unified entrypoint:
- Scalar mode: if
xandyare scalar integers, returns a Pythonint. - Array mode: if
xandyare NumPy integer arrays, returns a NumPy array of indices (and supportsout=).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
IntScalar | IntArray
|
Coordinates to encode.
Boolean inputs are rejected. |
required |
y
|
IntScalar | IntArray
|
Coordinates to encode.
Boolean inputs are rejected. |
required |
nbits
|
int | None
|
Number of coordinate bits (grid domain is Must satisfy If
For array mode, if the inferred value exceeds the algorithm maximum
(32 bits), a |
None
|
out
|
IntArray | None
|
Optional output array for array mode. Must have the same shape as |
None
|
parallel
|
bool
|
Array mode: if Scalar mode: accepted for API consistency, but ignored. If The number of threads can be controlled with the environment variable
|
False
|
Returns:
| Type | Description |
|---|---|
int or ndarray
|
When
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
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 coordinates to a Hilbert index.
This is a unified entrypoint:
- Scalar mode: if
x,y,zare scalar integers, returns a Pythonint. - Array mode: if
x,y,zare NumPy integer arrays, returns a NumPy array of indices (and supportsout=).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
IntScalar | IntArray
|
Coordinates to encode.
Boolean inputs are rejected. |
required |
y
|
IntScalar | IntArray
|
Coordinates to encode.
Boolean inputs are rejected. |
required |
z
|
IntScalar | IntArray
|
Coordinates to encode.
Boolean inputs are rejected. |
required |
nbits
|
int | None
|
Number of coordinate bits (grid domain is Must satisfy If
For array mode, if the inferred value exceeds the algorithm maximum
(21 bits), a |
None
|
out
|
IntArray | None
|
Optional output array for array mode. Must have the same shape as
|
None
|
parallel
|
bool
|
Array mode: if Scalar mode: accepted for API consistency, but ignored. If The number of threads can be controlled with the environment variable
|
False
|
Returns:
| Type | Description |
|---|---|
int or ndarray
|
When
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs are mixed between scalar and array modes, if boolean inputs are
provided, or if |
ValueError
|
If |