Skip to content

hilbert

Hilbert curve encoding and decoding between coordinates and curve indices.

Functions:

  • right_shift –

    Shift a tensor of bits right by k positions, padding the vacated positions with zeros.

  • binary2gray –

    Convert bits from the binary code to the Gray code.

  • gray2binary –

    Convert bits from the Gray code back to the binary code.

  • encode –

    Encode integer grid coordinates into their Hilbert curve indices.

  • decode –

    Decode Hilbert curve indices back into integer grid coordinates.

right_shift

right_shift(
    binary: Tensor, k: int = 1, axis: int = -1
) -> Tensor

Shift a tensor of bits right by k positions, padding the vacated positions with zeros.

Parameters:

  • binary (Tensor) –

    Tensor of bits, most significant bit first along axis.

  • k (int, default: 1 ) –

    Number of positions to shift by.

  • axis (int, default: -1 ) –

    Axis holding the bits.

Returns:

  • Tensor –

    The shifted bits, same shape as binary.

binary2gray

binary2gray(binary: Tensor, axis: int = -1) -> Tensor

Convert bits from the binary code to the Gray code.

Parameters:

  • binary (Tensor) –

    Tensor of bits, most significant bit first along axis.

  • axis (int, default: -1 ) –

    Axis holding the bits.

Returns:

  • Tensor –

    The Gray-coded bits, same shape as binary.

gray2binary

gray2binary(gray: Tensor, axis: int = -1) -> Tensor

Convert bits from the Gray code back to the binary code.

Parameters:

  • gray (Tensor) –

    Tensor of Gray-coded bits, most significant bit first along axis.

  • axis (int, default: -1 ) –

    Axis holding the bits.

Returns:

  • Tensor –

    The binary bits, same shape as gray.

encode

encode(
    locs: Tensor, num_dims: int, num_bits: int
) -> Tensor

Encode integer grid coordinates into their Hilbert curve indices.

Parameters:

  • locs (Tensor) –

    Integer coordinates \((N, \text{num\_dims})\), each in \([0, 2^{\text{num\_bits}})\).

  • num_dims (int) –

    Number of dimensions of the grid.

  • num_bits (int) –

    Number of bits per dimension. num_dims times num_bits must fit in an int64.

Returns:

  • Tensor –

    The Hilbert indices, shape \((N,)\) and dtype int64.

decode

decode(
    hilberts: Tensor, num_dims: int, num_bits: int
) -> Tensor

Decode Hilbert curve indices back into integer grid coordinates.

Parameters:

  • hilberts (Tensor) –

    Hilbert indices \((N,)\).

  • num_dims (int) –

    Number of dimensions of the grid.

  • num_bits (int) –

    Number of bits per dimension. num_dims times num_bits must fit in an int64.

Returns:

  • Tensor –

    The integer coordinates, shape \((N, \text{num\_dims})\) and dtype int64.