Skip to content

Commit

Permalink
abs
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Aug 1, 2023
1 parent e06228d commit 4fac0ea
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ta_lib/core/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ impl Series<f64> {
self.fmap(|val| val.map(|v| v.min(scalar)).or(Some(scalar)))
}

pub fn abs(&self) -> Self {
self.fmap(|val| val.map(|v| v.abs()))
}

pub fn cumsum(&self) -> Self {
let mut sum = 0.0;

Expand Down Expand Up @@ -152,6 +156,17 @@ mod tests {
}
}

#[test]
fn test_abs() {
let source = vec![-1.0, 2.0, -3.0, 4.0, 5.0];
let expected = vec![Some(1.0), Some(2.0), Some(3.0), Some(4.0), Some(5.0)];
let series = Series::from(&source);

let result = series.abs();

assert_eq!(result, expected);
}

#[test]
fn test_cumsum() {
let source = vec![1.0, 2.0, 3.0, 4.0, 5.0];
Expand Down

0 comments on commit 4fac0ea

Please sign in to comment.