pub struct PaddingHadamard<A>where
A: Allocator,{ /* private fields */ }Expand description
A Hadamard transform that zero pads non-power-of-two dimensions to the next power of two.
This struct performs the transformation
HDx / sqrt(n)where
His a Hadamard MatrixDis a diagonal matrix with diagonal entries in{-1, +1}.xis the vector to transform, zero padded to have a length that is a multiple of two.nis the output-dimension.
Implementations§
Source§impl<A> PaddingHadamard<A>where
A: Allocator,
impl<A> PaddingHadamard<A>where
A: Allocator,
Sourcepub fn new<R>(
dim: NonZeroUsize,
target: TargetDim,
rng: &mut R,
allocator: A,
) -> Result<Self, AllocatorError>
pub fn new<R>( dim: NonZeroUsize, target: TargetDim, rng: &mut R, allocator: A, ) -> Result<Self, AllocatorError>
Construct a new PaddingHadamard that transforms input vectors of dimension dim.
The parameter rng is used to randomly initialize the diagonal matrix 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().next_power_of_two()
TargetDim::Overrideself.input_dim() == dim.get()self.output_dim(): The value provided by the override.
Subsampling occurs if self.output_dim() is not a power of two and greater-than or
equal to self.input_dim().
Sourcepub fn try_from_parts(
signs: Poly<[u32], A>,
padded_dim: usize,
subsample: Option<Poly<[u32], A>>,
) -> Result<Self, PaddingHadamardError>
pub fn try_from_parts( signs: Poly<[u32], A>, padded_dim: usize, subsample: Option<Poly<[u32], A>>, ) -> Result<Self, PaddingHadamardError>
Construct Self from constituent parts. This validates that the necessary
invariants hold for the constituent parts, returning an error if they do not.
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 not a power of two greater than or equal to 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 PaddingHadamard<A>where
A: Freeze,
impl<A> RefUnwindSafe for PaddingHadamard<A>where
A: RefUnwindSafe,
impl<A> Send for PaddingHadamard<A>where
A: Send,
impl<A> Sync for PaddingHadamard<A>where
A: Sync,
impl<A> Unpin for PaddingHadamard<A>where
A: Unpin,
impl<A> UnwindSafe for PaddingHadamard<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