Function dfdx::tensor_ops::nans_to
source · pub fn nans_to<S: Shape, E: Dtype, D: UnaryKernel<NansToKernelOp<E>, E>, T: Tape<E, D>>(
t: Tensor<S, E, D, T>,
value: impl Into<f64>
) -> Tensor<S, E, D, T>
Expand description
Replaces any std::f32::NAN with value
.
Pytorch equivalent: t.nan_to_num(value)
Example:
let t = dev.tensor([1.0, f32::NAN, f32::NAN, 4.0]);
let r = t.nans_to(0.0);
assert_eq!(r.array(), [1.0, 0.0, 0.0, 4.0]);