Skip to content

Commit 73aea16

Browse files
committed
🔍 fix correct minmax index calculations in FPCS algorithm
1 parent fbf546c commit 73aea16

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

downsample_rs/src/fpcs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn fpcs_outer_loop<Ty: PartialOrd + Copy>(
8989

9090
// NOTE: the minmax_idxs are not ordered!!
9191
// So we need to check if the min is actually the min
92-
if arr[min_idx] >= arr[max_idx] {
92+
if arr[min_idx] > arr[max_idx] {
9393
min_idx = chunk[1];
9494
max_idx = chunk[0];
9595
}
@@ -225,7 +225,7 @@ pub(crate) fn fpcs_generic<Tx: Num + AsPrimitive<f64>, Ty: PartialOrd + Copy>(
225225
f_minmax: fn(&[Tx], &[Ty], usize) -> Vec<usize>,
226226
) -> Vec<usize> {
227227
assert_eq!(x.len(), y.len());
228-
let mut minmax_idxs = f_minmax(&x[1..(x.len() - 1)], &y[1..(x.len() - 1)], n_out * 2);
228+
let mut minmax_idxs = f_minmax(&x[1..(x.len() - 1)], &y[1..(x.len() - 1)], (n_out - 2) * 2);
229229
minmax_idxs.iter_mut().for_each(|elem| *elem += 1); // inplace + 1
230230
return fpcs_outer_loop(y, minmax_idxs, n_out);
231231
}
@@ -238,7 +238,7 @@ pub(crate) fn fpcs_generic_without_x<T: PartialOrd + Copy>(
238238
n_out: usize,
239239
f_minmax: fn(&[T], usize) -> Vec<usize>,
240240
) -> Vec<usize> {
241-
let mut minmax_idxs: Vec<usize> = f_minmax(&arr[1..(arr.len() - 1)], n_out * 2);
241+
let mut minmax_idxs: Vec<usize> = f_minmax(&arr[1..(arr.len() - 1)], (n_out - 2) * 2);
242242
minmax_idxs.iter_mut().for_each(|elem| *elem += 1); // inplace + 1
243243
return fpcs_outer_loop(arr, minmax_idxs, n_out);
244244
}

0 commit comments

Comments
 (0)