Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-ops/src/series/ops/interpolation/mod.rs
6939 views
1
use std::ops::{Add, Div, Mul, Sub};
2
#[cfg(feature = "interpolate")]
3
pub mod interpolate;
4
#[cfg(feature = "interpolate_by")]
5
pub mod interpolate_by;
6
7
fn linear_itp<T>(low: T, step: T, slope: T) -> T
8
where
9
T: Sub<Output = T> + Mul<Output = T> + Add<Output = T> + Div<Output = T>,
10
{
11
low + step * slope
12
}
13
14
fn nearest_itp<T>(low: T, step: T, diff: T, steps_n: T) -> T
15
where
16
T: Sub<Output = T> + Mul<Output = T> + Add<Output = T> + Div<Output = T> + PartialOrd + Copy,
17
{
18
// 5 - 1 = 5 -> low
19
// 5 - 2 = 3 -> low
20
// 5 - 3 = 2 -> high
21
if (steps_n - step) > step {
22
low
23
} else {
24
low + diff
25
}
26
}
27
28