Function dfdx::tensor_ops::sub
source · pub fn sub<S: Shape, E: Dtype, D, T: Tape<E, D> + Merge<R>, R>(
lhs: Tensor<S, E, D, T>,
rhs: Tensor<S, E, D, R>
) -> Tensor<S, E, D, T>where
D: BinaryKernel<BinarySubKernelOp, E>,
Expand description
Element wise and scalar subtraction.
Example:
let a = dev.tensor([[1.0, 2.0, 3.0], [-1.0, -2.0, -3.0]]);
let b = dev.ones();
let r = a - b;
assert_eq!(r.array(), [[0.0, 1.0, 2.0], [-2.0, -3.0, -4.0]]);
Scalar Example:
let a = dev.tensor([[1.0, 2.0, 3.0], [-1.0, -2.0, -3.0]]);
let r = a - 1.0;
assert_eq!(r.array(), [[0.0, 1.0, 2.0], [-2.0, -3.0, -4.0]]);