/* Appellation: arith Contrib: FL03 */ #![cfg(test)] extern crate acme_tensor as acme; use acme::prelude::Tensor; #[test] fn test_add() { let shape = (2, 2); let a = Tensor::::ones(shape); let b = Tensor::::ones(shape); let c = &a + &b; assert_eq!(c, Tensor::fill(shape, 2_f64)); let a = Tensor::::ones(shape); let b = a + 1_f64; assert_eq!(b, Tensor::fill(shape, 2_f64)); } #[test] fn test_div() { let shape = (2, 2); let a = Tensor::::ones(shape); let b = Tensor::::fill(shape, 2_f64); let c = a / b; assert_eq!(c, Tensor::::fill(shape, 0.5)); } #[test] fn test_mul() { let shape = (2, 2); let a = Tensor::::ones(shape); let b = Tensor::::ones(shape); let c = a * b; assert_eq!(c, Tensor::::ones(shape)); } #[test] fn test_sub() { let shape = (2, 2); let a = Tensor::::ones(shape); let b = Tensor::::ones(shape); let c = a - &b; assert_eq!(c, Tensor::::zeros(shape)); } #[test] fn test_trig() { let a = Tensor::::ones((2, 2)); let b = a.sin(); let c = a.cos(); assert_eq!(b[[0, 0]], 1_f64.sin()); assert_eq!(c[[0, 0]], 1_f64.cos()); }