Function dfdx::tensor_ops::to_dtype
source · pub fn to_dtype<E2: Unit, S: Shape, E1: Unit, D: ToDtypeKernel<E1, E2>>(
tensor: Tensor<S, E1, D>
) -> Tensor<S, E2, D>
Expand description
Copies the elements of a tensor, converting its data to a different dtype.
Example usage:
let a = dev.tensor([1usize, 2, 3, 4, 5]);
let b = a.clone().to_dtype::<i8>();
assert_eq!(b.array(), [1, 2, 3, 4, 5]);
let c = a.clone().to_dtype::<f32>();
assert_eq!(c.array(), [1.0, 2.0, 3.0, 4.0, 5.0]);