pub fn linspace(start: f32, stop: f32, n: usize) -> Vec<f32> {
if n <= 1 {
return vec![start];
}
let delta = (stop - start) / (n - 1) as f32;
(0..n).map(|i| start + i as f32 * delta).collect()
}
use std::f32::consts::PI;
fn _sin_taylor(v: f32) -> f32 {
v - (1.0 / 6.0) * v.powi(3) + (1.0 / 120.0) * v.powi(5)
}
fn _sin(mut x: f32) -> f32 {
let two_pi = 2.0 * PI;
x %= two_pi;
if x < 0.0 {
x += two_pi;
}
if x <= 0.5 * PI {
_sin_taylor(x)
} else if x <= 1.5 * PI {
_sin_taylor(PI - x)
} else {
_sin_taylor(x - two_pi)
}
}
pub fn sin(x: &[f32]) -> Vec<f32> {
x.iter().map(|&v| _sin(v)).collect()
}