pub struct DoubleHadamard<A>where
A: Allocator,{ /* private fields */ }Expand description
A Double Hadamard transform that applies the signed Hadamard Transform to a head of the vector and then the tail.
This struct performs the transformation
[I 0; 0 H/sqrt(t)] · D1 · [H/sqrt(t) 0; 0 I] · zeropad(D0 · x)nis the dimensionality of the input vector.mis the desired output dimensionality.o = max(n, m)is an intermediate dimension.tis the largest power of 2 less than or equal too.His a Hadamard Matrix of dimensiont,Iis the identity matrix of dimensionn - tD0andD1are diagonal matrices with diagonal entries in{-1, +1}drawn uniformly at random with lengthsnandorespectively.xis the input vector of dimensionn[A 0; 0 B]represents a block diagonal matrix with blocksAandB.zeropadindicates that the resultD0 · xis zero-padded to the dimensionoif needed.
As indicated above, if o is a power of two, then only a single transformation is
applied. Further, if o exceeds n, then the input vector is zero padded at the end to
o dimensions.
Implementations§
Source§impl<A> DoubleHadamard<A>where
A: Allocator,
impl<A> DoubleHadamard<A>where
A: Allocator,
Sourcepub fn new<R>(
dim: NonZeroUsize,
target_dim: TargetDim,
rng: &mut R,
allocator: A,
) -> Result<Self, AllocatorError>
pub fn new<R>( dim: NonZeroUsize, target_dim: TargetDim, rng: &mut R, allocator: A, ) -> Result<Self, AllocatorError>
Construct a new DoubleHadamard that transforms input vectors of dimension dim.
The parameter rng is used to randomly initialize the diagonal matrices portion of
the transform.
The following dimensionalities will be configured depending on the value of target:
TargetDim::Sameself.input_dim() == dim.get()self.output_dim() == dim.get()
TargetDim::Naturalself.input_dim() == dim.get()self.output_dim() == dim.get()
TargetDim::Overrideself.input_dim() == dim.get()self.output_dim(): The value provided by the override.
Subsampling occurs if self.output_dim() is smaller than self.input_dim().
pub fn try_from_parts( signs0: Poly<[u32], A>, signs1: Poly<[u32], A>, subsample: Option<Poly<[u32], A>>, ) -> Result<Self, DoubleHadamardError>
Sourcepub fn output_dim(&self) -> usize
pub fn output_dim(&self) -> usize
Return the output dimension for the transformation.
Sourcepub fn preserves_norms(&self) -> bool
pub fn preserves_norms(&self) -> bool
Return whether or not the transform preserves norms.
For this transform, norms are not preserved when the output dimensionality is less than the input dimensionality.
Sourcepub fn transform_into(
&self,
dst: &mut [f32],
src: &[f32],
allocator: ScopedAllocator<'_>,
) -> Result<(), TransformFailed>
pub fn transform_into( &self, dst: &mut [f32], src: &[f32], allocator: ScopedAllocator<'_>, ) -> Result<(), TransformFailed>
Perform the transformation of the src vector into the dst vector.
§Errors
Returns an error if
src.len() != self.input_dim().dst.len() != self.output_dim().
Trait Implementations§
Auto Trait Implementations§
impl<A> Freeze for DoubleHadamard<A>where
A: Freeze,
impl<A> RefUnwindSafe for DoubleHadamard<A>where
A: RefUnwindSafe,
impl<A> Send for DoubleHadamard<A>where
A: Send,
impl<A> Sync for DoubleHadamard<A>where
A: Sync,
impl<A> Unpin for DoubleHadamard<A>where
A: Unpin,
impl<A> UnsafeUnpin for DoubleHadamard<A>where
A: UnsafeUnpin,
impl<A> UnwindSafe for DoubleHadamard<A>where
A: UnwindSafe,
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> 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