I'm trying to write optimized code to do this:
a = x^2
b = x^2 sin(e^x)
c = x^2 cos(e^x)
Code:
let mut x = arr1(&[1.0, 2.0, 3.0]);
let x2 = &x.mapv(|v| v*v);
let a = x2.view();
x.mapv_inplace(|v| (v.exp()));
let b = x2 * &x.mapv(|v| v.sin());
x.mapv_inplace(|v| v.cos());
x *= x2;
let c = x;
Can this code be optimized any further? I wrote it this way, using in-place operations, so that memory only needs to be allocated for three arrays: when declaring x, x2, and b.