Skip to main content

05_scalar_ops/
05_scalar_ops.rs

1//! Scalar arithmetic: tensor on left and scalar on left (all eight forms).
2//!
3//! Run: cargo run --example 05_scalar_ops
4
5use matten::Tensor;
6
7fn main() {
8    let t = Tensor::new(vec![1.0, 2.0, 3.0, 4.0], &[2, 2]);
9
10    // tensor op scalar
11    println!("t + 10  = {:?}", &t + 10.0);
12    println!("t - 1   = {:?}", &t - 1.0);
13    println!("t * 2   = {:?}", &t * 2.0);
14    println!("t / 2   = {:?}", &t / 2.0);
15
16    // scalar op tensor
17    println!("10 + t  = {:?}", 10.0_f64 + &t);
18    println!("10 - t  = {:?}", 10.0_f64 - &t);
19    println!("2 * t   = {:?}", 2.0_f64 * &t);
20    println!("8 / t   = {:?}", 8.0_f64 / &t);
21}