pub struct Clamp<T>where
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 for Clamp<T>where
T: Copy,
Source§impl<T> ElementOp<T> for Clamp<T>where
T: NumericElement + Copy,
impl<T> ElementOp<T> for Clamp<T>where
T: NumericElement + Copy,
Source§unsafe fn apply<Arch>(
self,
a: <Arch as SimdKernel<T>>::Vector,
_b: <Arch as SimdKernel<T>>::Vector,
) -> <Arch as SimdKernel<T>>::Vectorwhere
Arch: SimdKernel<T>,
unsafe fn apply<Arch>(
self,
a: <Arch as SimdKernel<T>>::Vector,
_b: <Arch as SimdKernel<T>>::Vector,
) -> <Arch as SimdKernel<T>>::Vectorwhere
Arch: SimdKernel<T>,
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> StructuralPartialEq for Clamp<T>
Source§impl<T> UnaryOp<T> for Clamp<T>where
T: NumericElement + PartialOrd,
impl<T> UnaryOp<T> for Clamp<T>where
T: NumericElement + PartialOrd,
Source§unsafe fn apply<Arch>(
self,
v: <Arch as SimdKernel<T>>::Vector,
) -> <Arch as SimdKernel<T>>::Vectorwhere
Arch: SimdKernel<T>,
unsafe fn apply<Arch>(
self,
v: <Arch as SimdKernel<T>>::Vector,
) -> <Arch as SimdKernel<T>>::Vectorwhere
Arch: SimdKernel<T>,
self.apply::<Arch>(v) -> result. Read more