Skip to main content

Module rhdh

Module rhdh 

Source
Expand description

Randomized Hadamard Transform (RHDH): R = (1/sqrt(d’)) · H · D.

H is the Walsh-Hadamard matrix (d’ = next power of two >= d), D is a diagonal matrix of random +/-1 signs derived deterministically from a seed. After RHDH, coordinates of a unit vector are approximately N(0, 1), which makes the precomputed Lloyd-Max N(0,1) tables valid without any training pass.

The transform runs in O(d log d) via the fast Walsh-Hadamard transform.

Structs§

Rhdh
A reusable RHDH context: the random sign diagonal for a padded dimension.

Functions§

fwht
Fast in-place Walsh-Hadamard transform (unnormalized). v.len() must be a power of two.
padded_dim
Pad dimension up to the next power of two.