2018-09-20 20:23:31 +08:00
|
|
|
use na::{Real, DefaultAllocator};
|
2018-09-20 16:50:34 +08:00
|
|
|
use aliases::Vec;
|
2018-09-20 20:23:31 +08:00
|
|
|
use traits::{Alloc, Dimension};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Componentwise exponential.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn exp<N: Real, D: Dimension>(v: &Vec<N, D>) -> Vec<N, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
2018-09-20 20:23:31 +08:00
|
|
|
v.map(|x| x.exp())
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Componentwise base-2 exponential.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn exp2<N: Real, D: Dimension>(v: &Vec<N, D>) -> Vec<N, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
2018-09-20 20:23:31 +08:00
|
|
|
v.map(|x| x.exp2())
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Compute the inverse of the square root of each component of `v`.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn inversesqrt<N: Real, D: Dimension>(v: &Vec<N, D>) -> Vec<N, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
2018-09-20 20:23:31 +08:00
|
|
|
v.map(|x| N::one() / x.sqrt())
|
|
|
|
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Componentwise logarithm.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn log<N: Real, D: Dimension>(v: &Vec<N, D>) -> Vec<N, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
2018-09-20 20:23:31 +08:00
|
|
|
v.map(|x| x.ln())
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Componentwise base-2 logarithm.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn log2<N: Real, D: Dimension>(v: &Vec<N, D>) -> Vec<N, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
2018-09-20 20:23:31 +08:00
|
|
|
v.map(|x| x.log2())
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Componentwise power.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn pow<N: Real, D: Dimension>(base: &Vec<N, D>, exponent: &Vec<N, D>) -> Vec<N, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
2018-09-20 20:23:31 +08:00
|
|
|
base.zip_map(exponent, |b, e| b.powf(e))
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Componentwise square root.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn sqrt<N: Real, D: Dimension>(v: &Vec<N, D>) -> Vec<N, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
2018-09-20 20:23:31 +08:00
|
|
|
v.map(|x| x.sqrt())
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|