1- use ndarray:: { NdFloat , Dimension , Array , Array1 , Array2 , ArrayView1 , Axis , s, stack} ;
1+ use ndarray:: { NdFloat , Dimension , Array , Array1 , Array2 , ArrayView1 , Axis , s, stack, ArrayView2 } ;
22use almost:: AlmostEqual ;
33
44use crate :: { Result , ndarrayext} ;
@@ -9,10 +9,16 @@ impl<'a, T> NdSpline<'a, T>
99 where T : NdFloat + AlmostEqual
1010{
1111 /// Implements evaluating the spline on the given mesh of Xi-sites
12- pub ( super ) fn evaluate_spline ( & self , xi : ArrayView1 < ' a , T > ) -> Array2 < T > {
12+ pub ( crate ) fn evaluate_spline (
13+ order : usize ,
14+ pieces : usize ,
15+ breaks : ArrayView1 < ' _ , T > ,
16+ coeffs : ArrayView2 < ' _ , T > ,
17+ xi : ArrayView1 < ' a , T > ) -> Array2 < T >
18+ {
1319
1420 let edges = {
15- let mesh = self . breaks . slice ( s ! [ 1 ..-1 ] ) ;
21+ let mesh = breaks. slice ( s ! [ 1 ..-1 ] ) ;
1622 let one = Array1 :: < T > :: ones ( ( 1 , ) ) ;
1723 let left_bound = & one * T :: neg_infinity ( ) ;
1824 let right_bound = & one * T :: infinity ( ) ;
@@ -24,7 +30,7 @@ impl<'a, T> NdSpline<'a, T>
2430
2531 // Go to local coordinates
2632 let xi = {
27- let indexed_breaks = indices. mapv ( |i| self . breaks [ i] ) ;
33+ let indexed_breaks = indices. mapv ( |i| breaks[ i] ) ;
2834 & xi - & indexed_breaks
2935 } ;
3036
@@ -35,7 +41,7 @@ impl<'a, T> NdSpline<'a, T>
3541 let get_indexed_coeffs = |inds : & Array1 < usize > | {
3642 // Returns Nx1 2-d array of coeffs by given index
3743 let coeffs_by_index = |& index| {
38- self . coeffs . slice ( s ! [ .., index] ) . insert_axis ( Axis ( 1 ) )
44+ coeffs. slice ( s ! [ .., index] ) . insert_axis ( Axis ( 1 ) )
3945 } ;
4046
4147 // Get the M-sized vector of coeffs values Nx1 arrays
@@ -51,8 +57,8 @@ impl<'a, T> NdSpline<'a, T>
5157 // Vectorized computing the spline pieces (polynoms) on the given data sites
5258 let mut values = get_indexed_coeffs ( & indices) ;
5359
54- for _ in 1 ..self . order {
55- indices += self . pieces ;
60+ for _ in 1 ..order {
61+ indices += pieces;
5662 values = values * & xi + get_indexed_coeffs ( & indices) ;
5763 }
5864
@@ -75,7 +81,7 @@ impl<'a, T, D> CubicSmoothingSpline<'a, T, D>
7581 shape[ i] = s
7682 }
7783
78- let yi_2d = self . spline . as_ref ( ) . unwrap ( ) . evaluate_spline ( xi) ;
84+ let yi_2d = self . spline . as_ref ( ) . unwrap ( ) . evaluate ( xi) ;
7985 let yi = ndarrayext:: from_2d ( & yi_2d, shape, axis) ?. to_owned ( ) ;
8086
8187 Ok ( yi)
0 commit comments