QjlResidual

QJL (Quantized Johnson-Lindenstrauss) residual stage for TurboQuant.

After scalar quantization, there is a residual error: residual = original_rotated - dequantized

The QJL stage projects this residual onto a random low-dimensional subspace and quantizes the projection. This preserves inner-product accuracy (Johnson-Lindenstrauss property) at the cost of additional storage.

This stage is used only by the TurboQuantPolarQjl variant. The TurboQuantPolar variant omits it for simplicity and speed.

Functions

Link copied to clipboard
fun decode(encoded: EncodedResidual, output: FloatArray, seed: Int)

Decode a QJL residual and add it to the base reconstruction.

Link copied to clipboard
fun encode(residual: FloatArray, residualBits: Int, seed: Int): EncodedResidual

Encode a residual vector using QJL projection.