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.