Skip to main content

Module rotation_matrix

Module rotation_matrix 

Source
Expand description

Canonical orthogonal rotation matrix (ChaCha → faer QR → sign correction).

Pipeline:

  1. Fill a dim * dim row-major f64 buffer from [ChaChaGaussianStream].
  2. Load the buffer into a faer Mat<f64> and compute A = Q R via faer::Mat::qr.
  3. Apply the Haar-measure sign correction Q[:, j] *= sign(R[j, j]) so that the resulting orthogonal matrix is uniquely determined by the RNG stream (mirrors the Python reference).
  4. Store the corrected Q in row-major order inside an Arc<[f64]>.

Numerical contract:

  • apply_into promotes f32 to f64, does the matmul in f64, and casts the result back to f32. This matches NumPy’s implicit promotion for float64 @ float32 and is required for the round-trip parity target of < 1e-5.
  • apply_inverse_into uses the stored matrix’s transpose (valid because it’s orthogonal), again with an f64 accumulator.

See docs/design/rust/numerical-semantics.md §R1 for the full recipe and rationale.

Structs§

RotationMatrix
Deterministically generated orthogonal matrix for vector preconditioning.