2018-09-22 19:18:59 +08:00
|
|
|
use na::{self, DefaultAllocator};
|
2018-09-21 01:54:12 +08:00
|
|
|
|
|
|
|
use traits::{Number, Alloc, Dimension};
|
|
|
|
use aliases::Mat;
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The sum of every components of the given matrix or vector.
|
2018-09-21 01:54:12 +08:00
|
|
|
pub fn comp_add<N: Number, R: Dimension, C: Dimension>(m: &Mat<N, R, C>) -> N
|
|
|
|
where DefaultAllocator: Alloc<N, R, C> {
|
|
|
|
m.iter().fold(N::zero(), |x, y| x + *y)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The maximum of every components of the given matrix or vector.
|
2018-09-21 01:54:12 +08:00
|
|
|
pub fn comp_max<N: Number, R: Dimension, C: Dimension>(m: &Mat<N, R, C>) -> N
|
|
|
|
where DefaultAllocator: Alloc<N, R, C> {
|
|
|
|
m.iter().fold(N::min_value(), |x, y| na::sup(&x, y))
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The minimum of every components of the given matrix or vector.
|
2018-09-21 01:54:12 +08:00
|
|
|
pub fn comp_min<N: Number, R: Dimension, C: Dimension>(m: &Mat<N, R, C>) -> N
|
|
|
|
where DefaultAllocator: Alloc<N, R, C> {
|
|
|
|
m.iter().fold(N::max_value(), |x, y| na::inf(&x, y))
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The product of every components of the given matrix or vector.
|
2018-09-21 01:54:12 +08:00
|
|
|
pub fn comp_mul<N: Number, R: Dimension, C: Dimension>(m: &Mat<N, R, C>) -> N
|
|
|
|
where DefaultAllocator: Alloc<N, R, C> {
|
|
|
|
m.iter().fold(N::one(), |x, y| x * *y)
|
|
|
|
}
|
|
|
|
|
|
|
|
//pub fn vec< L, floatType, Q > compNormalize (vec< L, T, Q > const &v)
|
|
|
|
//pub fn vec< L, T, Q > compScale (vec< L, floatType, Q > const &v)
|