Skip to content

Commit 29e7839

Browse files
committed
wip: ndg make
1 parent 33c1b28 commit 29e7839

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

src/ndg/make.rs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use ndarray::{NdFloat, Dimension};
22
use almost::AlmostEqual;
33

4-
use crate::Result;
4+
use crate::{Result, CsapsError::ReshapeError, CubicSmoothingSpline};
55
use super::{GridCubicSmoothingSpline, NdGridSpline};
66

77

@@ -11,6 +11,59 @@ impl<'a, T, D> GridCubicSmoothingSpline<'a, T, D>
1111
D: Dimension
1212
{
1313
pub(super) fn make_spline(&mut self) -> Result<()> {
14-
unimplemented!();
14+
let ndim = self.x.len();
15+
let ndim_m1 = ndim - 1;
16+
17+
let breaks = self.x.to_vec();
18+
let mut coeffs = self.y.view();
19+
let mut coeffs_shape = coeffs.shape().to_vec();
20+
21+
let mut smooth: Vec<Option<T>> = Vec::new();
22+
23+
let mut permute_axes = D::zeros(ndim);
24+
permute_axes[0] = ndim_m1;
25+
for ax in 0..ndim_m1 {
26+
permute_axes[ax+1] = ax;
27+
}
28+
29+
for ax in (0..ndim).rev() {
30+
let x = breaks[ax].view();
31+
32+
if ndim > 2 {
33+
let coeffs_2d = {
34+
let shape = coeffs.shape().to_vec();
35+
let new_shape = [shape[0..ndim_m1].iter().product(), shape[ndim_m1]];
36+
37+
match coeffs.view().into_shape(new_shape) {
38+
Ok(coeffs_2d) => coeffs_2d,
39+
Err(err) => {
40+
return Err(
41+
ReshapeError(
42+
format!("Cannot reshape data array with shape {:?} to 2-d array with shape {:?}\n{}",
43+
shape, new_shape, err)
44+
)
45+
)
46+
}
47+
}
48+
};
49+
50+
// CubicSmoothingSpline::new(x, coeffs_2d.view())
51+
// .make()?
52+
// .spline().unwrap()
53+
// .coeffs().to_owned()
54+
//
55+
// } else {
56+
//
57+
// CubicSmoothingSpline::new(x, coeffs.view())
58+
// .make()?
59+
// .spline().unwrap()
60+
// .coeffs().to_owned()
61+
}
62+
}
63+
64+
self.smooth = Some(smooth);
65+
self.spline = Some(NdGridSpline::new(breaks, coeffs.to_owned()));
66+
67+
Ok(())
1568
}
1669
}

0 commit comments

Comments
 (0)