injective_math/
vector.rs

1use crate::fp_decimal::FPDecimal;
2
3pub fn sum(vec: &[FPDecimal]) -> FPDecimal {
4    vec.iter().fold(FPDecimal::ZERO, |acc, &el| acc + el)
5}
6
7pub fn dot(vec: &[FPDecimal], other: &[FPDecimal]) -> FPDecimal {
8    mul(vec, other).iter().sum()
9}
10
11pub fn mul(vec: &[FPDecimal], other: &[FPDecimal]) -> Vec<FPDecimal> {
12    vec.iter().zip(other).map(|(&i1, &i2)| i1 * i2).collect()
13}
14
15pub fn mul_const(vec: &[FPDecimal], other: FPDecimal) -> Vec<FPDecimal> {
16    vec.iter().map(|&i| i * other).collect()
17}
18
19pub fn div_const(vec: &[FPDecimal], other: FPDecimal) -> Vec<FPDecimal> {
20    vec.iter().map(|&i| i / other).collect()
21}
22
23pub fn add(vec: &[FPDecimal], other: &[FPDecimal]) -> Vec<FPDecimal> {
24    vec.iter().zip(other).map(|(&i1, &i2)| i1 + i2).collect()
25}
26
27pub fn sub(vec: &[FPDecimal], other: &[FPDecimal]) -> Vec<FPDecimal> {
28    vec.iter().zip(other).map(|(&i1, &i2)| i1 - i2).collect()
29}
30
31pub fn abs(vec: &[FPDecimal]) -> Vec<FPDecimal> {
32    vec.iter().map(|&i| i.abs()).collect()
33}