Skip to content

Clippy check #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,11 @@ jobs:
with:
command: fmt
args: -- --check

clippy:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- uses: actions-rs/cargo@v1
with:
command: clippy
4 changes: 2 additions & 2 deletions src/cholesky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ where
fn factorizec_into(self, uplo: UPLO) -> Result<CholeskyFactorized<S>> {
Ok(CholeskyFactorized {
factor: self.cholesky_into(uplo)?,
uplo: uplo,
uplo,
})
}
}
Expand All @@ -311,7 +311,7 @@ where
fn factorizec(&self, uplo: UPLO) -> Result<CholeskyFactorized<OwnedRepr<A>>> {
Ok(CholeskyFactorized {
factor: self.cholesky(uplo)?,
uplo: uplo,
uplo,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/diagonal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ where
S: DataMut<Elem = A>,
{
for (val, d) in a.iter_mut().zip(self.diag.iter()) {
*val = *val * *d;
*val *= *d;
}
}
}
2 changes: 1 addition & 1 deletion src/krylov/householder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ where
A: Scalar + Lapack,
S: DataMut<Elem = A>,
{
assert!(x.len() > 0);
assert!(!x.is_empty());
let norm = x.norm_l2();
let alpha = -x[0].mul_real(norm / x[0].abs());
x[0] -= alpha;
Expand Down
4 changes: 2 additions & 2 deletions src/krylov/mgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<A: Scalar + Lapack> Orthogonalizer for MGS<A> {
for i in 0..self.len() {
let q = &self.q[i];
let c = q.inner(&a);
azip!((a in &mut *a, &q in q) *a = *a - c * q);
azip!((a in &mut *a, &q in q) *a -= c * q);
coef[i] = c;
}
let nrm = a.norm_l2();
Expand Down Expand Up @@ -88,7 +88,7 @@ impl<A: Scalar + Lapack> Orthogonalizer for MGS<A> {
// Linearly dependent
return AppendResult::Dependent(coef);
}
azip!((a in &mut *a) *a = *a / A::from_real(nrm));
azip!((a in &mut *a) *a /= A::from_real(nrm));
self.q.push(a.to_owned());
AppendResult::Added(coef)
}
Expand Down
2 changes: 0 additions & 2 deletions src/lapack/cholesky.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Cholesky decomposition

use lapacke;

use crate::error::*;
use crate::layout::MatrixLayout;
use crate::types::*;
Expand Down
1 change: 0 additions & 1 deletion src/lapack/eig.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Eigenvalue decomposition for general matrices

use lapacke;
use num_traits::Zero;

use crate::error::*;
Expand Down
1 change: 0 additions & 1 deletion src/lapack/eigh.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Eigenvalue decomposition for Hermite matrices

use lapacke;
use num_traits::Zero;

use crate::error::*;
Expand Down
1 change: 0 additions & 1 deletion src/lapack/least_squares.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Least squares

use lapacke;
use ndarray::{ErrorKind, ShapeError};
use num_traits::Zero;

Expand Down
2 changes: 2 additions & 0 deletions src/lapack/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Define traits wrapping LAPACK routines

#![allow(clippy::missing_safety_doc)]

pub mod cholesky;
pub mod eig;
pub mod eigh;
Expand Down
1 change: 0 additions & 1 deletion src/lapack/opnorm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Operator norms of matrices

use lapacke;
use lapacke::Layout::ColumnMajor as cm;

use crate::layout::MatrixLayout;
Expand Down
1 change: 0 additions & 1 deletion src/lapack/qr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! QR decomposition

use lapacke;
use num_traits::Zero;
use std::cmp::min;

Expand Down
1 change: 0 additions & 1 deletion src/lapack/solve.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Solve linear problem using LU decomposition

use lapacke;
use num_traits::Zero;

use crate::error::*;
Expand Down
2 changes: 0 additions & 2 deletions src/lapack/solveh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//!
//! See also [the manual of dsytrf](http://www.netlib.org/lapack/lapack-3.1.1/html/dsytrf.f.html)

use lapacke;

use crate::error::*;
use crate::layout::MatrixLayout;
use crate::types::*;
Expand Down
3 changes: 1 addition & 2 deletions src/lapack/svd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Singular-value decomposition

use lapacke;
use num_traits::Zero;

use crate::error::*;
Expand Down Expand Up @@ -79,7 +78,7 @@ macro_rules! impl_svd {
into_result(
info,
SVDOutput {
s: s,
s,
u: if calc_u { Some(u) } else { None },
vt: if calc_vt { Some(vt) } else { None },
},
Expand Down
3 changes: 1 addition & 2 deletions src/lapack/svddc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use lapacke;
use num_traits::Zero;

use crate::error::*;
Expand Down Expand Up @@ -49,7 +48,7 @@ macro_rules! impl_svdd {
into_result(
info,
SVDOutput {
s: s,
s,
u: if jobz == UVTFlag::None { None } else { Some(u) },
vt: if jobz == UVTFlag::None {
None
Expand Down
2 changes: 0 additions & 2 deletions src/lapack/triangular.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Implement linear solver and inverse matrix

use lapacke;

use super::{into_result, Transpose, UPLO};

use crate::error::*;
Expand Down
1 change: 0 additions & 1 deletion src/lapack/tridiagonal.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Implement linear solver using LU decomposition
//! for tridiagonal matrix

use lapacke;
use num_traits::Zero;

use super::NormType;
Expand Down
5 changes: 4 additions & 1 deletion src/layout.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Memory layout of matrices

use lapacke;
use ndarray::*;

use super::error::*;
Expand Down Expand Up @@ -47,6 +46,10 @@ impl MatrixLayout {
}
}

pub fn is_empty(&self) -> bool {
self.len() == 0
}

pub fn lapacke_layout(&self) -> lapacke::Layout {
match *self {
MatrixLayout::C(_) => lapacke::Layout::RowMajor,
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
//! - [Random matrix generators](generate/index.html)
//! - [Scalar trait](types/trait.Scalar.html)

#![allow(
clippy::module_inception,
clippy::many_single_char_names,
clippy::type_complexity,
clippy::ptr_arg
)]

#[macro_use]
extern crate ndarray;

Expand Down
9 changes: 4 additions & 5 deletions src/lobpcg/lobpcg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ fn sorted_eig<S: Data<Elem = A>, A: Scalar + Lapack>(

Ok(match order {
Order::Largest => (
vals.slice_move(s![n-size..; -1])
.mapv(|x| Scalar::from_real(x)),
vals.slice_move(s![n-size..; -1]).mapv(Scalar::from_real),
vecs.slice_move(s![.., n-size..; -1]),
),
Order::Smallest => (
vals.slice_move(s![..size]).mapv(|x| Scalar::from_real(x)),
vals.slice_move(s![..size]).mapv(Scalar::from_real),
vecs.slice_move(s![.., ..size]),
),
})
Expand All @@ -62,7 +61,7 @@ fn ndarray_mask<A: Scalar>(matrix: ArrayView2<A>, mask: &[bool]) -> Array2<A> {
assert_eq!(mask.len(), matrix.ncols());

let indices = (0..mask.len())
.zip(mask.into_iter())
.zip(mask.iter())
.filter(|(_, b)| **b)
.map(|(a, _)| a)
.collect::<Vec<usize>>();
Expand Down Expand Up @@ -435,7 +434,7 @@ pub fn lobpcg<

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

match final_norm {
Ok(_) => LobpcgResult::Ok(vals, vecs, rnorm),
Expand Down
2 changes: 1 addition & 1 deletion src/lobpcg/svd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl<A: Float + Scalar + ScalarOperand + Lapack + PartialOrd + Default> Truncate
match res {
LobpcgResult::Ok(vals, vecs, _) | LobpcgResult::Err(vals, vecs, _, _) => {
Ok(TruncatedSvdResult {
problem: self.problem.clone(),
problem: self.problem,
eigvals: vals,
eigvecs: vecs,
ngm: n > m,
Expand Down
2 changes: 1 addition & 1 deletion src/norm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ where
for mut v in m.axis_iter_mut(Axis(axis as usize)) {
let n = v.norm();
ms.push(n);
v.map_inplace(|x| *x = *x / A::from_real(n))
v.map_inplace(|x| *x /= A::from_real(n))
}
(m, ms)
}
7 changes: 2 additions & 5 deletions src/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,7 @@ where
{
fn factorize_into(mut self) -> Result<LUFactorized<S>> {
let ipiv = unsafe { A::lu(self.layout()?, self.as_allocated_mut()?)? };
Ok(LUFactorized {
a: self,
ipiv: ipiv,
})
Ok(LUFactorized { a: self, ipiv })
}
}

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

Expand Down
15 changes: 6 additions & 9 deletions src/solveh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ where
{
fn factorizeh_into(mut self) -> Result<BKFactorized<S>> {
let ipiv = unsafe { A::bk(self.square_layout()?, UPLO::Upper, self.as_allocated_mut()?)? };
Ok(BKFactorized {
a: self,
ipiv: ipiv,
})
Ok(BKFactorized { a: self, ipiv })
}
}

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

Expand Down Expand Up @@ -326,8 +323,8 @@ where
// 1x1 block at k, must be real.
let elem = unsafe { a.uget((k, k)) }.re();
debug_assert_eq!(elem.im(), Zero::zero());
sign = sign * elem.signum();
ln_det = ln_det + elem.abs().ln();
sign *= elem.signum();
ln_det += elem.abs().ln();
} else {
// 2x2 block at k..k+2.

Expand All @@ -347,8 +344,8 @@ where

// Determinant of 2x2 block.
let block_det = upper_diag * lower_diag - off_diag.square();
sign = sign * block_det.signum();
ln_det = ln_det + block_det.abs().ln();
sign *= block_det.signum();
ln_det += block_det.abs().ln();

// Skip the k+1 ipiv value.
ipiv_enum.next();
Expand Down
6 changes: 3 additions & 3 deletions src/tridiagonal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,9 @@ where
let (du2, anom, ipiv) = unsafe { A::lu_tridiagonal(&mut self)? };
Ok(LUFactorizedTridiagonal {
a: self,
du2: du2,
anom: anom,
ipiv: ipiv,
du2,
anom,
ipiv,
})
}
}
Expand Down