Skip to content

Commit 749ccb9

Browse files
committed
clippy fix
1 parent 0ac6085 commit 749ccb9

25 files changed

+38
-48
lines changed

src/cholesky.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ where
298298
fn factorizec_into(self, uplo: UPLO) -> Result<CholeskyFactorized<S>> {
299299
Ok(CholeskyFactorized {
300300
factor: self.cholesky_into(uplo)?,
301-
uplo: uplo,
301+
uplo,
302302
})
303303
}
304304
}
@@ -311,7 +311,7 @@ where
311311
fn factorizec(&self, uplo: UPLO) -> Result<CholeskyFactorized<OwnedRepr<A>>> {
312312
Ok(CholeskyFactorized {
313313
factor: self.cholesky(uplo)?,
314-
uplo: uplo,
314+
uplo,
315315
})
316316
}
317317
}

src/diagonal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ where
4242
S: DataMut<Elem = A>,
4343
{
4444
for (val, d) in a.iter_mut().zip(self.diag.iter()) {
45-
*val = *val * *d;
45+
*val *= *d;
4646
}
4747
}
4848
}

src/krylov/householder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ where
1313
A: Scalar + Lapack,
1414
S: DataMut<Elem = A>,
1515
{
16-
assert!(x.len() > 0);
16+
assert!(!x.is_empty());
1717
let norm = x.norm_l2();
1818
let alpha = -x[0].mul_real(norm / x[0].abs());
1919
x[0] -= alpha;

src/krylov/mgs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<A: Scalar + Lapack> Orthogonalizer for MGS<A> {
5151
for i in 0..self.len() {
5252
let q = &self.q[i];
5353
let c = q.inner(&a);
54-
azip!((a in &mut *a, &q in q) *a = *a - c * q);
54+
azip!((a in &mut *a, &q in q) *a -= c * q);
5555
coef[i] = c;
5656
}
5757
let nrm = a.norm_l2();
@@ -88,7 +88,7 @@ impl<A: Scalar + Lapack> Orthogonalizer for MGS<A> {
8888
// Linearly dependent
8989
return AppendResult::Dependent(coef);
9090
}
91-
azip!((a in &mut *a) *a = *a / A::from_real(nrm));
91+
azip!((a in &mut *a) *a /= A::from_real(nrm));
9292
self.q.push(a.to_owned());
9393
AppendResult::Added(coef)
9494
}

src/lapack/cholesky.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Cholesky decomposition
22
3-
use lapacke;
4-
53
use crate::error::*;
64
use crate::layout::MatrixLayout;
75
use crate::types::*;

src/lapack/eig.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Eigenvalue decomposition for general matrices
22
3-
use lapacke;
43
use num_traits::Zero;
54

65
use crate::error::*;

src/lapack/eigh.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Eigenvalue decomposition for Hermite matrices
22
3-
use lapacke;
43
use num_traits::Zero;
54

65
use crate::error::*;

src/lapack/least_squares.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Least squares
22
3-
use lapacke;
43
use ndarray::{ErrorKind, ShapeError};
54
use num_traits::Zero;
65

src/lapack/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Define traits wrapping LAPACK routines
22
3+
#![allow(clippy::missing_safety_doc)]
4+
35
pub mod cholesky;
46
pub mod eig;
57
pub mod eigh;

src/lapack/opnorm.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Operator norms of matrices
22
3-
use lapacke;
43
use lapacke::Layout::ColumnMajor as cm;
54

65
use crate::layout::MatrixLayout;

src/lapack/qr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! QR decomposition
22
3-
use lapacke;
43
use num_traits::Zero;
54
use std::cmp::min;
65

src/lapack/solve.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Solve linear problem using LU decomposition
22
3-
use lapacke;
43
use num_traits::Zero;
54

65
use crate::error::*;

src/lapack/solveh.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
//!
33
//! See also [the manual of dsytrf](http://www.netlib.org/lapack/lapack-3.1.1/html/dsytrf.f.html)
44
5-
use lapacke;
6-
75
use crate::error::*;
86
use crate::layout::MatrixLayout;
97
use crate::types::*;

src/lapack/svd.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Singular-value decomposition
22
3-
use lapacke;
43
use num_traits::Zero;
54

65
use crate::error::*;
@@ -79,7 +78,7 @@ macro_rules! impl_svd {
7978
into_result(
8079
info,
8180
SVDOutput {
82-
s: s,
81+
s,
8382
u: if calc_u { Some(u) } else { None },
8483
vt: if calc_vt { Some(vt) } else { None },
8584
},

src/lapack/svddc.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use lapacke;
21
use num_traits::Zero;
32

43
use crate::error::*;
@@ -49,7 +48,7 @@ macro_rules! impl_svdd {
4948
into_result(
5049
info,
5150
SVDOutput {
52-
s: s,
51+
s,
5352
u: if jobz == UVTFlag::None { None } else { Some(u) },
5453
vt: if jobz == UVTFlag::None {
5554
None

src/lapack/triangular.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Implement linear solver and inverse matrix
22
3-
use lapacke;
4-
53
use super::{into_result, Transpose, UPLO};
64

75
use crate::error::*;

src/lapack/tridiagonal.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Implement linear solver using LU decomposition
22
//! for tridiagonal matrix
33
4-
use lapacke;
54
use num_traits::Zero;
65

76
use super::NormType;

src/layout.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Memory layout of matrices
22
3-
use lapacke;
43
use ndarray::*;
54

65
use super::error::*;
@@ -47,6 +46,10 @@ impl MatrixLayout {
4746
}
4847
}
4948

49+
pub fn is_empty(&self) -> bool {
50+
self.len() == 0
51+
}
52+
5053
pub fn lapacke_layout(&self) -> lapacke::Layout {
5154
match *self {
5255
MatrixLayout::C(_) => lapacke::Layout::RowMajor,

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838
//! - [Random matrix generators](generate/index.html)
3939
//! - [Scalar trait](types/trait.Scalar.html)
4040
41+
#![allow(
42+
clippy::module_inception,
43+
clippy::many_single_char_names,
44+
clippy::type_complexity,
45+
clippy::ptr_arg
46+
)]
47+
4148
#[macro_use]
4249
extern crate ndarray;
4350

src/lobpcg/lobpcg.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ fn sorted_eig<S: Data<Elem = A>, A: Scalar + Lapack>(
4646

4747
Ok(match order {
4848
Order::Largest => (
49-
vals.slice_move(s![n-size..; -1])
50-
.mapv(|x| Scalar::from_real(x)),
49+
vals.slice_move(s![n-size..; -1]).mapv(Scalar::from_real),
5150
vecs.slice_move(s![.., n-size..; -1]),
5251
),
5352
Order::Smallest => (
54-
vals.slice_move(s![..size]).mapv(|x| Scalar::from_real(x)),
53+
vals.slice_move(s![..size]).mapv(Scalar::from_real),
5554
vecs.slice_move(s![.., ..size]),
5655
),
5756
})
@@ -62,7 +61,7 @@ fn ndarray_mask<A: Scalar>(matrix: ArrayView2<A>, mask: &[bool]) -> Array2<A> {
6261
assert_eq!(mask.len(), matrix.ncols());
6362

6463
let indices = (0..mask.len())
65-
.zip(mask.into_iter())
64+
.zip(mask.iter())
6665
.filter(|(_, b)| **b)
6766
.map(|(a, _)| a)
6867
.collect::<Vec<usize>>();
@@ -435,7 +434,7 @@ pub fn lobpcg<
435434

436435
// retrieve best result and convert norm into `A`
437436
let (vals, vecs, rnorm) = best_result.unwrap();
438-
let rnorm = rnorm.into_iter().map(|x| Scalar::from_real(x)).collect();
437+
let rnorm = rnorm.into_iter().map(Scalar::from_real).collect();
439438

440439
match final_norm {
441440
Ok(_) => LobpcgResult::Ok(vals, vecs, rnorm),

src/lobpcg/svd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl<A: Float + Scalar + ScalarOperand + Lapack + PartialOrd + Default> Truncate
160160
match res {
161161
LobpcgResult::Ok(vals, vecs, _) | LobpcgResult::Err(vals, vecs, _, _) => {
162162
Ok(TruncatedSvdResult {
163-
problem: self.problem.clone(),
163+
problem: self.problem,
164164
eigvals: vals,
165165
eigvecs: vecs,
166166
ngm: n > m,

src/norm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ where
6565
for mut v in m.axis_iter_mut(Axis(axis as usize)) {
6666
let n = v.norm();
6767
ms.push(n);
68-
v.map_inplace(|x| *x = *x / A::from_real(n))
68+
v.map_inplace(|x| *x /= A::from_real(n))
6969
}
7070
(m, ms)
7171
}

src/solve.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,7 @@ where
274274
{
275275
fn factorize_into(mut self) -> Result<LUFactorized<S>> {
276276
let ipiv = unsafe { A::lu(self.layout()?, self.as_allocated_mut()?)? };
277-
Ok(LUFactorized {
278-
a: self,
279-
ipiv: ipiv,
280-
})
277+
Ok(LUFactorized { a: self, ipiv })
281278
}
282279
}
283280

@@ -289,7 +286,7 @@ where
289286
fn factorize(&self) -> Result<LUFactorized<OwnedRepr<A>>> {
290287
let mut a: Array2<A> = replicate(self);
291288
let ipiv = unsafe { A::lu(a.layout()?, a.as_allocated_mut()?)? };
292-
Ok(LUFactorized { a: a, ipiv: ipiv })
289+
Ok(LUFactorized { a, ipiv })
293290
}
294291
}
295292

src/solveh.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,7 @@ where
166166
{
167167
fn factorizeh_into(mut self) -> Result<BKFactorized<S>> {
168168
let ipiv = unsafe { A::bk(self.square_layout()?, UPLO::Upper, self.as_allocated_mut()?)? };
169-
Ok(BKFactorized {
170-
a: self,
171-
ipiv: ipiv,
172-
})
169+
Ok(BKFactorized { a: self, ipiv })
173170
}
174171
}
175172

@@ -181,7 +178,7 @@ where
181178
fn factorizeh(&self) -> Result<BKFactorized<OwnedRepr<A>>> {
182179
let mut a: Array2<A> = replicate(self);
183180
let ipiv = unsafe { A::bk(a.square_layout()?, UPLO::Upper, a.as_allocated_mut()?)? };
184-
Ok(BKFactorized { a: a, ipiv: ipiv })
181+
Ok(BKFactorized { a, ipiv })
185182
}
186183
}
187184

@@ -326,8 +323,8 @@ where
326323
// 1x1 block at k, must be real.
327324
let elem = unsafe { a.uget((k, k)) }.re();
328325
debug_assert_eq!(elem.im(), Zero::zero());
329-
sign = sign * elem.signum();
330-
ln_det = ln_det + elem.abs().ln();
326+
sign *= elem.signum();
327+
ln_det += elem.abs().ln();
331328
} else {
332329
// 2x2 block at k..k+2.
333330

@@ -347,8 +344,8 @@ where
347344

348345
// Determinant of 2x2 block.
349346
let block_det = upper_diag * lower_diag - off_diag.square();
350-
sign = sign * block_det.signum();
351-
ln_det = ln_det + block_det.abs().ln();
347+
sign *= block_det.signum();
348+
ln_det += block_det.abs().ln();
352349

353350
// Skip the k+1 ipiv value.
354351
ipiv_enum.next();

src/tridiagonal.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,9 @@ where
665665
let (du2, anom, ipiv) = unsafe { A::lu_tridiagonal(&mut self)? };
666666
Ok(LUFactorizedTridiagonal {
667667
a: self,
668-
du2: du2,
669-
anom: anom,
670-
ipiv: ipiv,
668+
du2,
669+
anom,
670+
ipiv,
671671
})
672672
}
673673
}

0 commit comments

Comments
 (0)