RandomRotation

Random rotation for TurboQuant encoding.

TurboQuant uses random orthogonal rotations to spread quantization error uniformly across dimensions before scalar quantization. This is the first stage of the TurboQuant pipeline.

The rotation is deterministic given a seed, so the same rotation can be reproduced during decoding without storing the full rotation matrix.

Implementation uses fast random Hadamard-like rotations (random sign flips

  • structured permutation) rather than full O(d^2) matrix multiplication. This gives O(d log d) rotation cost.

Functions

Link copied to clipboard
fun inverseRotate(vector: FloatArray, seed: Int)

Apply the inverse rotation to recover the original vector.

Link copied to clipboard
fun rotate(vector: FloatArray, seed: Int)

Apply a seeded random rotation to a vector in-place.

Link copied to clipboard
fun seedFor(layer: Int, head: Int, position: Int): Int

Generate a rotation seed for a given (layer, head, position) triple.