@@ -19,7 +19,7 @@ use crate::Result;
1919
2020/// N-d grid spline PP-form representation
2121///
22- /// `NdGridSpline` represents n-dimensional splines for n-d grid data. In n-d grid case
22+ /// `NdGridSpline` represents n-dimensional splines for n-dimensional grid data. In n-d grid case
2323/// the spline is represented as tensor-product of univariate spline coefficients along every
2424/// diemnsion.
2525///
@@ -55,6 +55,16 @@ impl<'a, T, D> NdGridSpline<'a, T, D>
5555 T : NdFloat + AlmostEqual ,
5656 D : Dimension
5757{
58+ /// Creates `NdGridSpline` struct from given `breaks` and `coeffs`
59+ ///
60+ /// # Arguments
61+ ///
62+ /// - `breaks` -- The vector of the breaks (data sites) which have been used for computing spline
63+ /// - `coeffs` -- The n-d array of tensor-product spline coefficients
64+ ///
65+ /// # Notes
66+ ///
67+ /// - `NdGridSpline` struct should not be created directly by a user in most cases.
5868 ///
5969 pub fn new ( breaks : Vec < ArrayView1 < ' a , T > > , coeffs : Array < T , D > ) -> Self {
6070 let ndim = breaks. len ( ) ;
@@ -70,7 +80,7 @@ impl<'a, T, D> NdGridSpline<'a, T, D>
7080 }
7181 }
7282
73- /// Returns the spline dimensionality
83+ /// Returns the n-d grid spline dimensionality
7484 pub fn ndim ( & self ) -> usize { self . ndim }
7585
7686 /// Returns the vector of the spline order for each dimension
@@ -94,12 +104,35 @@ impl<'a, T, D> NdGridSpline<'a, T, D>
94104
95105/// N-dimensional grid cubic smoothing spline calculator/evaluator
96106///
97- /// The struct represents n-d grid smoothing cubic spline and allows you to make and evaluate the
98- /// splines for given n-d grid data.
107+ /// The struct represents n-dimensional grid smoothing cubic spline and allows you to make
108+ /// and evaluate the splines for given n-dimensional grid data.
99109///
100- /// `CubicSmoothingSpline ` struct is parametrized by data type (`f64` or `f32`)
110+ /// `GridCubicSmoothingSpline ` struct is parametrized by data type (`f64` or `f32`)
101111/// and data dimension.
102112///
113+ /// The methods API of `GridCubicSmoothingSpline` is implemented as builder-like pattern or in other
114+ /// words as chained API (also as `CubicSmoothingSpline` struct):
115+ ///
116+ /// ```
117+ /// use ndarray::array;
118+ /// use csaps::GridCubicSmoothingSpline;
119+ ///
120+ /// let x0 = array![1.0, 2.0, 3.0, 4.0];
121+ /// let x1 = array![1.0, 2.0, 3.0, 4.0];
122+ /// let x = vec![x0.view(), x1.view()];
123+ ///
124+ /// let y = vec![
125+ /// [0.5, 1.2, 3.4, 2.5],
126+ /// [1.5, 2.2, 4.4, 3.5],
127+ /// [2.5, 3.2, 5.4, 4.5],
128+ /// [3.5, 4.2, 6.4, 5.5],
129+ /// ];
130+ ///
131+ /// let ys = GridCubicSmoothingSpline::new(&x, &y)
132+ /// .make().unwrap()
133+ /// .evaluate(&x).unwrap();
134+ /// ```
135+ ///
103136pub struct GridCubicSmoothingSpline < ' a , T , D >
104137 where
105138 T : NdFloat ,
@@ -117,7 +150,7 @@ pub struct GridCubicSmoothingSpline<'a, T, D>
117150 /// The optional smoothing parameter
118151 smooth : Vec < Option < T > > ,
119152
120- /// `NdSpline ` struct with computed spline
153+ /// `NdGridSpline ` struct with computed spline
121154 spline : Option < NdGridSpline < ' a , T , D > >
122155}
123156
@@ -128,6 +161,13 @@ impl<'a, T, D> GridCubicSmoothingSpline<'a, T, D>
128161 D : Dimension
129162{
130163 /// Creates `NdGridCubicSmoothingSpline` struct from the given `X` data sites and `Y` data values
164+ ///
165+ /// # Arguments
166+ ///
167+ /// - `x` -- the slice of X-data sites 1-d array view for each dimension.
168+ /// Each data sites must strictly increasing: `x1 < x2 < x3 < ... < xN`.
169+ /// - `y` -- The Y-data n-d grid values array-like. `ndim` can be from 1 to N.
170+ ///
131171 pub fn new < Y > ( x : & [ ArrayView1 < ' a , T > ] , y : Y ) -> Self
132172 where
133173 Y : AsArray < ' a , T , D >
@@ -143,19 +183,31 @@ impl<'a, T, D> GridCubicSmoothingSpline<'a, T, D>
143183 }
144184 }
145185
146- /// Sets the data weights
186+ /// Sets the weights data vectors for each dimension
147187 ///
148- /// `weights.len()` must be equal to `x.len()`
188+ /// # Arguments
189+ ///
190+ /// - `weights` -- the slice of optional weights arrays (array-like) for each dimension
191+ ///
192+ /// # Notes
193+ ///
194+ /// `weights` vectors sizes must be equal to `x` data site sizes for each dimension.
149195 ///
150196 pub fn with_weights ( mut self , weights : & [ Option < ArrayView1 < ' a , T > > ] ) -> Self {
151197 self . invalidate ( ) ;
152198 self . weights = weights. to_vec ( ) ;
153199 self
154200 }
155201
156- /// Sets the smoothing parameters for each axis
202+ /// Sets the smoothing parameters for each dimension
203+ ///
204+ /// # Arguments
157205 ///
158- /// The smoothing parameters should be in range `[0, 1]`,
206+ /// - `smooth` - the slice of optional smoothing parameters for each dimension
207+ ///
208+ /// # Notes
209+ ///
210+ /// The smoothing parameters should be in range `[0, 1]` or `None`,
159211 /// where bounds are:
160212 ///
161213 /// - 0: The smoothing spline is the least-squares straight line fit to the data
@@ -169,7 +221,27 @@ impl<'a, T, D> GridCubicSmoothingSpline<'a, T, D>
169221 self
170222 }
171223
172- /// Makes (computes) the n-d grid spline for given data and parameters
224+ /// Sets the smoothing parameter for all dimensions
225+ ///
226+ /// # Arguments
227+ ///
228+ /// - `smooth` - the smoothing parameter value that the same for all dimensions
229+ ///
230+ /// # Notes
231+ ///
232+ /// The smoothing parameter should be in range `[0, 1]`,
233+ /// where bounds are:
234+ ///
235+ /// - 0: The smoothing spline is the least-squares straight line fit to the data
236+ /// - 1: The cubic spline interpolant with natural boundary condition
237+ ///
238+ pub fn with_all_smooth ( mut self , smooth : T ) -> Self {
239+ self . invalidate ( ) ;
240+ self . smooth = vec ! [ Some ( smooth) ; self . x. len( ) ] ;
241+ self
242+ }
243+
244+ /// Makes (computes) the n-dimensional grid spline for given data and parameters
173245 ///
174246 /// # Errors
175247 ///
@@ -183,7 +255,7 @@ impl<'a, T, D> GridCubicSmoothingSpline<'a, T, D>
183255 Ok ( self )
184256 }
185257
186- /// Evaluates the computed n-d grid spline on the given data sites
258+ /// Evaluates the computed n-dimensional grid spline on the given data sites
187259 ///
188260 /// # Errors
189261 ///
0 commit comments