Skip to content

Helpers

Lower-level building blocks exposed for advanced use. Most users should reach for one of the index classes.

rht

rht

rht(x: NDArray[float32], seed: int) -> NDArray[np.float32]

Randomized Hadamard Transform: D·H·x / sqrt(d).

Parameters:

Name Type Description Default
x (NDArray[float32], shape(..., d))

Input vector(s). d must already be a power of 2.

required
seed int

Rotation seed. Use the same seed consistently for an index.

required

Returns:

Type Description
NDArray[np.float32], same shape as x.

padded_dim

padded_dim

padded_dim(dim: int) -> int

Return the WHT-padded dimension for a given embedding dimension.

get_codebook

get_codebook

get_codebook(bits: int) -> tuple[NDArray[np.float32], NDArray[np.float32]]

Return (centroids, boundaries) for the given bit-width.

Parameters:

Name Type Description Default
bits int

Quantization bits. Must be 2, 3, or 4.

required

Returns:

Name Type Description
centroids (NDArray[float32], shape(2 ** bits))

Reconstruction values.

boundaries (NDArray[float32], shape(2 ** bits - 1))

Decision thresholds for np.searchsorted.