hilbert
Hilbert curve encoding and decoding between coordinates and curve indices.
Functions:
-
right_shiftβShift a tensor of bits right by
kpositions, 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 [source] ΒΆ
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 [source] ΒΆ
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 [source] ΒΆ
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 [source] ΒΆ
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_dimstimesnum_bitsmust fit in anint64.
Returns:
-
TensorβThe Hilbert indices, shape \((N,)\) and dtype
int64.
decode [source] ΒΆ
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_dimstimesnum_bitsmust fit in anint64.
Returns:
-
TensorβThe integer coordinates, shape \((N, \text{num\_dims})\) and dtype
int64.