2018-09-20 20:23:31 +08:00
|
|
|
use na::{Real, DefaultAllocator};
|
2018-09-23 20:48:45 +08:00
|
|
|
use aliases::TVec;
|
2018-09-20 20:23:31 +08:00
|
|
|
use traits::{Alloc, Dimension};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:21:02 +08:00
|
|
|
/// Component-wise exponential.
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn exp<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<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:21:02 +08:00
|
|
|
/// Component-wise base-2 exponential.
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn exp2<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<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-23 20:48:45 +08:00
|
|
|
pub fn inversesqrt<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<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:21:02 +08:00
|
|
|
/// Component-wise logarithm.
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn log<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<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:21:02 +08:00
|
|
|
/// Component-wise base-2 logarithm.
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn log2<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<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:21:02 +08:00
|
|
|
/// Component-wise power.
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn pow<N: Real, D: Dimension>(base: &TVec<N, D>, exponent: &TVec<N, D>) -> TVec<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:21:02 +08:00
|
|
|
/// Component-wise square root.
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn sqrt<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<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
|
|
|
}
|