Skip to main content

sub

Function sub 

Source
pub fn sub<T: Scalar, B: ElementwiseOps<T>>(
    a: &Tensor<T, B>,
    b: &Tensor<T, B>,
    backend: &B,
) -> Result<Tensor<T, B>, B::Error>
Expand description

Element-wise subtraction.

ยงExamples

use coeus_tensor::Tensor;
use coeus_core::SequentialBackend;
use coeus_ops::sub;

let backend = SequentialBackend::new();
let a = Tensor::<f32, SequentialBackend>::from_slice([4], &[5.0, 6.0, 7.0, 8.0])
    .expect("example tensor allocation succeeds");
let b = Tensor::<f32, SequentialBackend>::from_slice([4], &[1.0, 2.0, 3.0, 4.0])
    .expect("example tensor allocation succeeds");
let c = sub(&a, &b, &backend).expect("example subtraction succeeds");
assert_eq!(c.as_slice(), &[4.0, 4.0, 4.0, 4.0]);