Skip to content

Commit

Permalink
add tests for periodic
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasBoss committed Jan 19, 2024
1 parent 4891764 commit 0bb4e04
Showing 1 changed file with 51 additions and 11 deletions.
62 changes: 51 additions & 11 deletions tests/cubic_spline_strat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ fn bounds_shape_error1() {
let y = array![[0.5, 1.0], [0.0, 1.5], [3.0, 0.5],];
let boundaries = BoundaryCondition::Individual(array![[
RowBoundary::Natural,
RowBoundary::Periodic,
RowBoundary::Clamped,
RowBoundary::NotAKnot
],]);
Interp1DBuilder::new(y)
Expand All @@ -440,23 +440,63 @@ fn bounds_shape_error2() {
}

#[test]
#[should_panic(expected = "First: 1.0, last: 0.5")]
#[should_panic(
expected = "First: [0.5, 1.0], shape=[2], strides=[1], layout=CFcf (0xf), const ndim=1, last: [0.5, 1.1]"
)]
fn periodic_wrong_values() {
let y = array![[0.5, 1.0], [0.0, 1.5], [3.0, 0.5],];
let boundaries =
BoundaryCondition::Individual(array![[RowBoundary::Natural, RowBoundary::Periodic],]);
let y = array![[0.5, 1.0], [0.0, 1.5], [0.5, 1.1],];
Interp1DBuilder::new(y)
.strategy(CubicSpline::new().boundary(boundaries))
.strategy(CubicSpline::new().boundary(BoundaryCondition::Periodic))
.build()
.unwrap();
}

#[test]
#[should_panic(expected = "First: [0.5, 1.0], shape=[2], strides=[1], layout=CFcf (0xf), const ndim=1, last: [0.5, 1.1]")]
fn periodic_wrong_values2() {
let y = array![[0.5, 1.0], [0.0, 1.5], [0.5, 1.1],];
Interp1DBuilder::new(y)
.strategy(CubicSpline::new().boundary(BoundaryCondition::Periodic))
fn extrapolate_periodic() {
let data = array![1.0, 2.0, 2.5, 2.5, 3.0, 2.0, 1.0, -2.0, 3.0, 5.0, 6.3, 1.0];
let interp = Interp1D::builder(data)
.strategy(
CubicSpline::new()
.extrapolate(true)
.boundary(BoundaryCondition::Periodic),
)
.build()
.unwrap();
let q = Array1::linspace(-3.0, 15.0, 30);
let res = interp.interp_array(&q).unwrap();

// values from scipy.interpolate.QubicSpline with bc_type=((1,-0.1),(1,-0.5))
let expect = array![
3.,
4.45171164,
5.5978812,
6.54905092,
3.79486808,
0.76011398,
1.36656494,
2.4432986,
2.50822019,
2.40158688,
2.63514361,
3.01451693,
2.59950279,
1.96267846,
1.65029582,
-0.22831889,
-2.04318459,
0.41031552,
3.63201944,
4.66215778,
6.05245899,
6.19632834,
2.68818585,
0.64246067,
1.77979077,
2.52789822,
2.46676892,
2.41681682,
2.76866398,
3.
];
assert_relative_eq!(res, expect, epsilon = f64::EPSILON, max_relative = 0.001);
}

0 comments on commit 0bb4e04

Please sign in to comment.