Skip to content

Commit fe75779

Browse files
committed
code formatting and refactoring
1 parent 00c44c7 commit fe75779

File tree

10 files changed

+81
-32
lines changed

10 files changed

+81
-32
lines changed

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@
119119
//! See [issue](https://github.com/vbarrielle/sprs/issues/184) for details.
120120
//!
121121
122-
123122
mod errors;
124123
mod ndarrayext;
125124
mod sprsext;

src/ndarrayext.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ use crate::{CsapsError::ReshapeError, Result};
2626

2727

2828
pub fn diff<'a, T: 'a, D, V>(data: V, axis: Option<Axis>) -> Array<T, D>
29-
where T: NumOps + ScalarOperand, D: Dimension, V: AsArray<'a, T, D>
29+
where
30+
T: NumOps + ScalarOperand,
31+
D: Dimension,
32+
V: AsArray<'a, T, D>
3033
{
3134
let data_view = data.into();
3235
let axis = axis.unwrap_or(Axis(data_view.ndim() - 1));
@@ -39,8 +42,9 @@ pub fn diff<'a, T: 'a, D, V>(data: V, axis: Option<Axis>) -> Array<T, D>
3942

4043

4144
pub fn to_2d<'a, T: 'a, D, I>(data: I, axis: Axis) -> Result<ArrayView2<'a, T>>
42-
where D: Dimension,
43-
I: AsArray<'a, T, D>,
45+
where
46+
D: Dimension,
47+
I: AsArray<'a, T, D>,
4448
{
4549
let data_view = data.into();
4650
let ndim = data_view.ndim();
@@ -95,9 +99,10 @@ pub fn to_2d_simple<'a, T: 'a, D>(data: ArrayView<'a, T, D>) -> Result<ArrayView
9599

96100

97101
pub fn from_2d<'a, T: 'a, D, S, I>(data: I, shape: S, axis: Axis) -> Result<ArrayView<'a, T, S::Dim>>
98-
where D: Dimension,
99-
S: IntoDimension<Dim = D>,
100-
I: AsArray<'a, T, Ix2>,
102+
where
103+
D: Dimension,
104+
S: IntoDimension<Dim = D>,
105+
I: AsArray<'a, T, Ix2>,
101106
{
102107
let shape = shape.into_dimension();
103108
let ndim = shape.ndim();
@@ -145,9 +150,10 @@ pub fn from_2d<'a, T: 'a, D, S, I>(data: I, shape: S, axis: Axis) -> Result<Arra
145150
///
146151
/// This code works if `bins` is increasing
147152
pub fn digitize<'a, T: 'a, A, B>(arr: A, bins: B) -> Array1<usize>
148-
where T: NdFloat + AlmostEqual,
149-
A: AsArray<'a, T, Ix1>,
150-
B: AsArray<'a, T, Ix1>,
153+
where
154+
T: NdFloat + AlmostEqual,
155+
A: AsArray<'a, T, Ix1>,
156+
B: AsArray<'a, T, Ix1>,
151157
{
152158
let arr_view = arr.into();
153159
let bins_view = bins.into();

src/ndg.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ impl<'a, T, D> NdGridSpline<'a, T, D>
111111
/// and data dimension.
112112
///
113113
/// The methods API of `GridCubicSmoothingSpline` is implemented as builder-like pattern or in other
114-
/// words as chained API (also as `CubicSmoothingSpline` struct):
114+
/// words as chained API (also as `CubicSmoothingSpline` struct).
115+
///
116+
/// # Examples
115117
///
116118
/// ```
117119
/// use ndarray::array;
@@ -263,7 +265,6 @@ impl<'a, T, D> GridCubicSmoothingSpline<'a, T, D>
263265
/// - If the spline yet has not been computed
264266
///
265267
pub fn evaluate(&self, xi: &[ArrayView1<'a, T>]) -> Result<Array<T, D>> {
266-
let xi = xi.to_vec();
267268
self.evaluate_validate(&xi)?;
268269
let yi = self.evaluate_spline(&xi);
269270

src/ndg/validate.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use ndarray::{
22
NdFloat,
3-
ArrayView1,
43
ArrayView,
4+
ArrayView1,
55
Dimension,
66
};
77

@@ -39,6 +39,16 @@ impl<'a, T, D> GridCubicSmoothingSpline<'a, T, D>
3939
)
4040
}
4141

42+
for xi_ax in xi.iter() {
43+
if xi_ax.len() < 1 {
44+
return Err(
45+
InvalidInputData(
46+
"The sizes of `xi` vectors must be greater or equal to 1".to_string()
47+
)
48+
)
49+
}
50+
}
51+
4252
Ok(())
4353
}
4454
}

src/sprsext.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use sprs_ldl::LdlNumeric;
1212
/// because sprs crate does not provide DIA matrices currently.
1313
///
1414
pub fn diags<T>(diags: Array2<T>, offsets: &[isize], shape: Shape) -> CsMat<T>
15-
where T: NdFloat
15+
where
16+
T: NdFloat
1617
{
1718
let (rows, cols) = shape;
1819

@@ -73,7 +74,8 @@ pub fn diags<T>(diags: Array2<T>, offsets: &[isize], shape: Shape) -> CsMat<T>
7374
///
7475
///
7576
pub fn diagonal<T>(m: &CsMat<T>, k: isize) -> Array1<T>
76-
where T: NdFloat
77+
where
78+
T: NdFloat
7779
{
7880
let (rows, cols) = m.shape();
7981

@@ -90,7 +92,8 @@ fn diagonal_csr<T>(k: isize,
9092
indptr: &[usize],
9193
indices: &[usize],
9294
data: &[T]) -> Array1<T>
93-
where T: NdFloat
95+
where
96+
T: NdFloat
9497
{
9598
let (rows, cols) = shape;
9699

@@ -131,7 +134,8 @@ fn diagonal_csr<T>(k: isize,
131134
/// b: MxN stack of b-vectors where M is equal to A rows/cols and N is the data dimensional
132135
///
133136
pub fn solve<T>(a: &CsMat<T>, b: &Array2<T>) -> Array2<T>
134-
where T: NdFloat
137+
where
138+
T: NdFloat
135139
{
136140
let mut x = Array2::<T>::zeros(b.raw_dim());
137141

src/umv.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ pub struct NdSpline<'a, T: NdFloat>
4949

5050

5151
impl<'a, T> NdSpline<'a, T>
52-
where T: NdFloat + AlmostEqual
52+
where
53+
T: NdFloat + AlmostEqual
5354
{
5455
/// Creates `NdSpline` struct from given `breaks` and `coeffs`
5556
///
@@ -114,7 +115,9 @@ impl<'a, T> NdSpline<'a, T>
114115
/// and data dimension.
115116
///
116117
/// The methods API of `CubicSmoothingSpline` is implemented as builder-loke pattern or in other
117-
/// words as chained API:
118+
/// words as chained API.
119+
///
120+
/// # Examples
118121
///
119122
/// ```
120123
/// use csaps::CubicSmoothingSpline;
@@ -146,7 +149,9 @@ impl<'a, T> NdSpline<'a, T>
146149
/// ```
147150
///
148151
pub struct CubicSmoothingSpline<'a, T, D>
149-
where T: NdFloat, D: Dimension
152+
where
153+
T: NdFloat,
154+
D: Dimension
150155
{
151156
/// X data sites (also breaks)
152157
x: ArrayView1<'a, T>,
@@ -169,7 +174,9 @@ pub struct CubicSmoothingSpline<'a, T, D>
169174

170175

171176
impl<'a, T, D> CubicSmoothingSpline<'a, T, D>
172-
where T: NdFloat + Default + AlmostEqual, D: Dimension
177+
where
178+
T: NdFloat + Default + AlmostEqual,
179+
D: Dimension
173180
{
174181
/// Creates `CubicSmoothingSpline` struct from the given `X` data sites and `Y` data values
175182
///
@@ -182,8 +189,9 @@ impl<'a, T, D> CubicSmoothingSpline<'a, T, D>
182189
/// equal to 2 and etc.
183190
///
184191
pub fn new<X, Y>(x: X, y: Y) -> Self
185-
where X: AsArray<'a, T>,
186-
Y: AsArray<'a, T, D>
192+
where
193+
X: AsArray<'a, T>,
194+
Y: AsArray<'a, T, D>
187195
{
188196
CubicSmoothingSpline {
189197
x: x.into(),
@@ -236,7 +244,8 @@ impl<'a, T, D> CubicSmoothingSpline<'a, T, D>
236244
/// `weights.len()` must be equal to `x.len()`
237245
///
238246
pub fn with_weights<W>(mut self, weights: W) -> Self
239-
where W: AsArray<'a, T>
247+
where
248+
W: AsArray<'a, T>
240249
{
241250
self.invalidate();
242251
self.weights = Some(weights.into());
@@ -248,7 +257,8 @@ impl<'a, T, D> CubicSmoothingSpline<'a, T, D>
248257
/// `weights.len()` must be equal to `x.len()`
249258
///
250259
pub fn with_optional_weights<W>(mut self, weights: Option<W>) -> Self
251-
where W: AsArray<'a, T>
260+
where
261+
W: AsArray<'a, T>
252262
{
253263
self.invalidate();
254264
self.weights = weights.map(|w| w.into());
@@ -297,7 +307,8 @@ impl<'a, T, D> CubicSmoothingSpline<'a, T, D>
297307
/// - If the spline yet has not been computed
298308
///
299309
pub fn evaluate<X>(&self, xi: X) -> Result<Array<T, D>>
300-
where X: AsArray<'a, T>
310+
where
311+
X: AsArray<'a, T>
301312
{
302313
let xi = xi.into();
303314
self.evaluate_validate(xi)?;

src/umv/evaluate.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
use ndarray::{NdFloat, Dimension, Array, Array1, Array2, ArrayView1, Axis, s, stack, ArrayView2};
1+
use ndarray::{
2+
NdFloat,
3+
Dimension,
4+
Array,
5+
Array1,
6+
Array2,
7+
ArrayView1,
8+
ArrayView2,
9+
Axis,
10+
s,
11+
stack,
12+
};
13+
214
use almost::AlmostEqual;
315

416
use crate::{Result, ndarrayext};
517
use super::{CubicSmoothingSpline, NdSpline};
618

719

820
impl<'a, T> NdSpline<'a, T>
9-
where T: NdFloat + AlmostEqual
21+
where
22+
T: NdFloat + AlmostEqual
1023
{
1124
/// Implements evaluating the spline on the given mesh of Xi-sites
1225
///

src/umv/make.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use super::{NdSpline, CubicSmoothingSpline};
77

88

99
impl<'a, T, D> CubicSmoothingSpline<'a, T, D>
10-
where T: NdFloat + Default + AlmostEqual, D: Dimension
10+
where
11+
T: NdFloat + Default + AlmostEqual,
12+
D: Dimension
1113
{
1214
pub(super) fn make_spline(&mut self) -> Result<()> {
1315
let one = T::one();

src/umv/validate.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use crate::{
1717

1818

1919
impl<'a, T, D> CubicSmoothingSpline<'a, T, D>
20-
where T: NdFloat + Default + AlmostEqual, D: Dimension
20+
where
21+
T: NdFloat + Default + AlmostEqual,
22+
D: Dimension
2123
{
2224
pub(super) fn make_validate(&self) -> Result<()> {
2325
let x_size = self.x.len();
@@ -84,7 +86,7 @@ impl<'a, T, D> CubicSmoothingSpline<'a, T, D>
8486
if xi.len() < 1 {
8587
return Err(
8688
InvalidInputData(
87-
"The size of data vectors must be greater or equal to 1".to_string()
89+
"The size of `xi` vector must be greater or equal to 1".to_string()
8890
)
8991
)
9092
}

src/validate.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use crate::{Result, CsapsError::InvalidInputData};
55

66

77
pub(crate) fn validate_data_sites<T>(x: ArrayView1<T>) -> Result<()>
8-
where T: NdFloat + AlmostEqual
8+
where
9+
T: NdFloat + AlmostEqual
910
{
1011
for w in x.windows(2) {
1112
let e1 = w[0];

0 commit comments

Comments
 (0)