pub struct RandomRotation {
pub dim: usize,
pub matrix: Vec<f32>,
/* private fields */
}Expand description
A random (approximately) orthogonal rotation.
Build once, apply many times. The default constructor random yields a
Haar-uniform D×D matrix for backward compatibility; hadamard opts in
to the O(D log D) HD-HD-HD variant.
Fields§
§dim: usize§matrix: Vec<f32>Kept for backward compatibility with snapshots that accessed the raw
matrix. Populated only for HaarDense; empty for Hadamard.
Implementations§
Source§impl RandomRotation
impl RandomRotation
Sourcepub fn random(dim: usize, seed: u64) -> Self
pub fn random(dim: usize, seed: u64) -> Self
Sample a Haar-uniform orthogonal matrix of size dim × dim.
Backward-compatible default: existing callers that expect a dense
matrix under self.matrix keep working unchanged.
Sourcepub fn hadamard(dim: usize, seed: u64) -> Self
pub fn hadamard(dim: usize, seed: u64) -> Self
Construct a randomised Hadamard rotation D₁·H·D₂·H·D₃.
Stores only 3 × padded_dim ±1 entries — no matrix materialised.
padded_dim is the next power of two ≥ dim; for dyadic dim it
equals dim.
Sourcepub fn kind(&self) -> RandomRotationKind
pub fn kind(&self) -> RandomRotationKind
Which construction backs this rotation.
Sourcepub fn apply(&self, v: &[f32]) -> Vec<f32>
pub fn apply(&self, v: &[f32]) -> Vec<f32>
Apply the rotation: out = P · v (length must equal dim).
Sourcepub fn apply_into(&self, v: &[f32], out: &mut [f32])
pub fn apply_into(&self, v: &[f32], out: &mut [f32])
In-place variant that writes into a caller-provided buffer.
Callers doing many rotations (hot query path) should reuse one
Vec<f32> instead of allocating per call — saves one malloc
per query in the ANN index’s encode_query_packed path.
Trait Implementations§
Source§impl Clone for RandomRotation
impl Clone for RandomRotation
Source§fn clone(&self) -> RandomRotation
fn clone(&self) -> RandomRotation
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'de> Deserialize<'de> for RandomRotation
impl<'de> Deserialize<'de> for RandomRotation
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for RandomRotation
impl RefUnwindSafe for RandomRotation
impl Send for RandomRotation
impl Sync for RandomRotation
impl Unpin for RandomRotation
impl UnsafeUnpin for RandomRotation
impl UnwindSafe for RandomRotation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more