2D API¶
Public 2D Hilbert API.
This module provides the main user-facing API for 2D Hilbert encoding and decoding:
hilbert_encode_2dhilbert_decode_2d
These accept either Python/NumPy scalar integers (scalar mode) or NumPy integer arrays (array mode).
For advanced use (embedding Hilbert encode/decode into your own Numba-compiled code), this module also exposes kernel accessors:
get_hilbert_encode_2d_kernelget_hilbert_decode_2d_kernel
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_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 |
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_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 |