Function dfdx::tensor_ops::clamp
source · pub fn clamp<S: Shape, E: Dtype, D: UnaryKernel<ClampKernelOp<E>, E>, T: Tape<E, D>>(
t: Tensor<S, E, D, T>,
min: impl Into<f64>,
max: impl Into<f64>
) -> Tensor<S, E, D, T>
Expand description
Clamp all elements between the provided min and max values.
Example:
let t = dev.tensor([-1.0, -0.5, 0.0, 0.5, 1.0]);
let r = t.clamp(-0.5, 0.5);
assert_eq!(r.array(), [-0.5, -0.5, 0.0, 0.5, 0.5]);