1
- use ndarray:: { prelude:: * , stack} ;
1
+ use ndarray:: { prelude:: * , stack, concatenate } ;
2
2
3
3
use crate :: {
4
4
Real ,
@@ -17,9 +17,9 @@ impl<'a, T, D> CubicSmoothingSpline<'a, T, D>
17
17
{
18
18
pub ( super ) fn make_spline ( & mut self ) -> Result < ( ) > {
19
19
let one = T :: one ( ) ;
20
- let two = T :: from ( 2.0 ) . unwrap ( ) ;
21
- let three = T :: from ( 3.0 ) . unwrap ( ) ;
22
- let six = T :: from ( 6.0 ) . unwrap ( ) ;
20
+ let two = T :: from :: < f64 > ( 2.0 ) . unwrap ( ) ;
21
+ let three = T :: from :: < f64 > ( 3.0 ) . unwrap ( ) ;
22
+ let six = T :: from :: < f64 > ( 6.0 ) . unwrap ( ) ;
23
23
24
24
let breaks = self . x ;
25
25
@@ -41,8 +41,8 @@ impl<'a, T, D> CubicSmoothingSpline<'a, T, D>
41
41
// The corner case for Nx2 data (2 data points)
42
42
if pcount == 2 {
43
43
drop ( dx) ;
44
- let yi = y. slice ( s ! [ .., 0 ] ) . insert_axis ( Axis ( 1 ) ) ;
45
- let coeffs = stack ! [ Axis ( 1 ) , dydx, yi] ;
44
+ let yi = y. slice ( s ! [ .., 0 as usize ] ) . insert_axis ( Axis ( 1 ) ) ;
45
+ let coeffs = concatenate ! [ Axis ( 1 ) , dydx, yi] ;
46
46
47
47
self . smooth = Some ( one) ;
48
48
self . spline = Some ( NdSpline :: new ( breaks, coeffs) ) ;
@@ -56,11 +56,11 @@ impl<'a, T, D> CubicSmoothingSpline<'a, T, D>
56
56
let qtwq = {
57
57
let qt = {
58
58
let odx = ones ( pcount - 1 ) / & dx;
59
- let odx_head = odx. slice ( s ! [ ..-1 ] ) . insert_axis ( Axis ( 0 ) ) . into_owned ( ) ;
60
- let odx_tail = odx. slice ( s ! [ 1 ..] ) . insert_axis ( Axis ( 0 ) ) . into_owned ( ) ;
59
+ let odx_head = odx. slice ( s ! [ ..-1 as i32 ] ) . insert_axis ( Axis ( 0 ) ) . into_owned ( ) ;
60
+ let odx_tail = odx. slice ( s ! [ 1 as i32 ..] ) . insert_axis ( Axis ( 0 ) ) . into_owned ( ) ;
61
61
drop ( odx) ;
62
62
let odx_body = -( & odx_tail + & odx_head) ;
63
- let diags_qt = stack ! [ Axis ( 0 ) , odx_head, odx_body, odx_tail] ;
63
+ let diags_qt = concatenate ! [ Axis ( 0 ) , odx_head, odx_body, odx_tail] ;
64
64
65
65
sprsext:: diags ( diags_qt, & [ 0 , 1 , 2 ] , ( pcount - 2 , pcount) )
66
66
} ;
@@ -76,10 +76,10 @@ impl<'a, T, D> CubicSmoothingSpline<'a, T, D>
76
76
} ;
77
77
78
78
let r = {
79
- let dx_head = dx. slice ( s ! [ ..-1 ] ) . insert_axis ( Axis ( 0 ) ) . into_owned ( ) ;
80
- let dx_tail = dx. slice ( s ! [ 1 ..] ) . insert_axis ( Axis ( 0 ) ) . into_owned ( ) ;
79
+ let dx_head = dx. slice ( s ! [ ..-1 as i32 ] ) . insert_axis ( Axis ( 0 ) ) . into_owned ( ) ;
80
+ let dx_tail = dx. slice ( s ! [ 1 as i32 ..] ) . insert_axis ( Axis ( 0 ) ) . into_owned ( ) ;
81
81
let dx_body = ( & dx_tail + & dx_head) * two;
82
- let diags_r = stack ! [ Axis ( 0 ) , dx_tail, dx_body, dx_head] ;
82
+ let diags_r = concatenate ! [ Axis ( 0 ) , dx_tail, dx_body, dx_head] ;
83
83
84
84
sprsext:: diags ( diags_r, & [ -1 , 0 , 1 ] , ( pcount - 2 , pcount - 2 ) )
85
85
} ;
@@ -109,11 +109,11 @@ impl<'a, T, D> CubicSmoothingSpline<'a, T, D>
109
109
sprsext:: solve ( & a, & b)
110
110
} ;
111
111
112
- // Compute and stack spline coefficients
112
+ // Compute and concatenatespline coefficients
113
113
let coeffs = {
114
114
let vpad = |arr : & Array2 < T > | -> Array2 < T > {
115
115
let pad = Array2 :: < T > :: zeros ( ( 1 , arr. shape ( ) [ 1 ] ) ) ;
116
- stack ( Axis ( 0 ) , & [ pad. view ( ) , arr. view ( ) , pad. view ( ) ] ) . unwrap ( )
116
+ concatenate ( Axis ( 0 ) , & [ pad. view ( ) , arr. view ( ) , pad. view ( ) ] ) . unwrap ( )
117
117
} ;
118
118
119
119
let dx = dx. insert_axis ( Axis ( 1 ) ) ;
@@ -133,17 +133,17 @@ impl<'a, T, D> CubicSmoothingSpline<'a, T, D>
133
133
} ;
134
134
135
135
let c3 = vpad ( & ( usol * smooth) ) ;
136
- let c3_head = c3. slice ( s ! [ ..-1 , ..] ) ;
137
- let c3_tail = c3. slice ( s ! [ 1 .., ..] ) ;
136
+ let c3_head = c3. slice ( s ! [ ..-1 as i32 , ..] ) ;
137
+ let c3_tail = c3. slice ( s ! [ 1 as i32 .., ..] ) ;
138
138
139
139
let p1 = diff ( & c3, Some ( Axis ( 0 ) ) ) / & dx;
140
140
let p2 = & c3_head * three;
141
141
let p3 = diff ( & yi, Some ( Axis ( 0 ) ) ) / & dx - ( & c3_head * two + c3_tail) * dx;
142
- let p4 = yi. slice ( s ! [ ..-1 , ..] ) ;
142
+ let p4 = yi. view ( ) . slice ( s ! [ ..-1 as i32 , ..] ) ;
143
143
144
144
drop ( c3) ;
145
145
146
- stack ! [ Axis ( 0 ) , p1 , p2, p3, p4] . t ( ) . to_owned ( )
146
+ concatenate ( Axis ( 0 ) , & [ p1 . view ( ) , p2. view ( ) , p3. view ( ) , p4] ) . unwrap ( ) . t ( ) . to_owned ( )
147
147
} ;
148
148
149
149
self . smooth = Some ( smooth) ;
0 commit comments