Skip to main content

hardtanh

Function hardtanh 

pub fn hardtanh<const D: usize>(
    tensor: Tensor<D>,
    min_val: f64,
    max_val: f64,
) -> Tensor<D>
Expand description

Applies the HardTanh function element-wise, clamping each element to the range [min_val, max_val] (a cheap, piecewise-linear approximation of tanh).

HardTanh(x) = max(min_val, min(max_val, x))