pub struct Clamp<T: Copy> {
pub lo: T,
pub hi: T,
}Expand description
Elementwise clamp: min(max(a[i], lo), hi).
Unlike the other strategies, Clamp carries its bounds as value fields — the
bounds are T-typed and cannot be encoded as const generics for a generic T.
The struct is Copy and 2×size_of::<T>() bytes; the compiler monomorphizes per
(T, Arch) pair.
§Usage
Elementwise clamp: a[i].clamp(lo, hi).
For binary elementwise use via zip_cow, the second operand is ignored —
bounds are carried in the struct and broadcast-splat at each SIMD iteration.
For unary use via map_unary, pass Clamp { lo, hi } directly.
Inlined by the optimizer at each monomorphization site: Clamp<T> bounds
become register-constant splat values with no indirect reads.
Fields§
§lo: TLower bound (inclusive).
hi: TUpper bound (inclusive).
Implementations§
Trait Implementations§
impl<T: Copy + Copy> Copy for Clamp<T>
Source§impl<T: Scalar + Copy> ElementOp<T> for Clamp<T>
impl<T: Scalar + Copy> ElementOp<T> for Clamp<T>
Source§unsafe fn apply<Arch: SimdKernel<T>>(
self,
a: Arch::Vector,
_b: Arch::Vector,
) -> Arch::Vector
unsafe fn apply<Arch: SimdKernel<T>>( self, a: Arch::Vector, _b: Arch::Vector, ) -> Arch::Vector
Clamp lanes: min(max(a_lane, lo_splat), hi_splat).
The second operand _b is unused — Clamp is a unary operation whose
bounds are carried in the struct. Use clamp_cow or transform_with_clamp
to apply this as a true single-operand transform.
The compiler hoists the splat(lo) and splat(hi) outside the vectorized
loop because self is captured by value in each zip_cow iteration.
Source§fn apply_scalar(self, a: T, _b: T) -> T
fn apply_scalar(self, a: T, _b: T) -> T
impl<T: PartialEq + Copy> StructuralPartialEq for Clamp<T>
Source§impl<T: Scalar + PartialOrd + NumericElement> UnaryOp<T> for Clamp<T>
impl<T: Scalar + PartialOrd + NumericElement> UnaryOp<T> for Clamp<T>
Auto Trait Implementations§
impl<T> Freeze for Clamp<T>where
T: Freeze,
impl<T> RefUnwindSafe for Clamp<T>where
T: RefUnwindSafe,
impl<T> Send for Clamp<T>where
T: Send,
impl<T> Sync for Clamp<T>where
T: Sync,
impl<T> Unpin for Clamp<T>where
T: Unpin,
impl<T> UnsafeUnpin for Clamp<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Clamp<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.