Skip to content

Commit e39a17f

Browse files
authored
Merge pull request #194 from rust-ndarray/format
cargo-fmt --check on CI
2 parents 55b46e9 + b729220 commit e39a17f

37 files changed

+706
-190
lines changed

.github/workflows/rust.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,12 @@ jobs:
5555
with:
5656
command: test
5757
args: --features=openblas --no-default-features
58+
59+
check-format:
60+
runs-on: ubuntu-18.04
61+
steps:
62+
- uses: actions/checkout@v1
63+
- uses: actions-rs/cargo@v1
64+
with:
65+
command: fmt
66+
args: -- --check

examples/eig.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ fn main() {
99
let a_c: Array2<c64> = a.map(|f| c64::new(*f, 0.0));
1010
let av = a_c.dot(&vecs);
1111
println!("AV = \n{:?}", av);
12-
}
12+
}

examples/truncated_svd.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ fn main() {
88
let a = arr2(&[[3., 2., 2.], [2., 3., -2.]]);
99

1010
// calculate the truncated singular value decomposition for 2 singular values
11-
let result = TruncatedSvd::new(a, TruncatedOrder::Largest).decompose(2).unwrap();
11+
let result = TruncatedSvd::new(a, TruncatedOrder::Largest)
12+
.decompose(2)
13+
.unwrap();
1214

1315
// acquire singular values, left-singular vectors and right-singular vectors
1416
let (u, sigma, v_t) = result.values_vectors();

rustfmt.toml

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/cholesky.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ where
166166
A: Scalar + Lapack,
167167
S: Data<Elem = A>,
168168
{
169-
fn solvec_inplace<'a, Sb>(&self, b: &'a mut ArrayBase<Sb, Ix1>) -> Result<&'a mut ArrayBase<Sb, Ix1>>
169+
fn solvec_inplace<'a, Sb>(
170+
&self,
171+
b: &'a mut ArrayBase<Sb, Ix1>,
172+
) -> Result<&'a mut ArrayBase<Sb, Ix1>>
170173
where
171174
Sb: DataMut<Elem = A>,
172175
{
@@ -327,7 +330,10 @@ pub trait SolveC<A: Scalar> {
327330
/// Solves a system of linear equations `A * x = b` with Hermitian (or real
328331
/// symmetric) positive definite matrix `A`, where `A` is `self`, `b` is
329332
/// the argument, and `x` is the successful result.
330-
fn solvec_into<S: DataMut<Elem = A>>(&self, mut b: ArrayBase<S, Ix1>) -> Result<ArrayBase<S, Ix1>> {
333+
fn solvec_into<S: DataMut<Elem = A>>(
334+
&self,
335+
mut b: ArrayBase<S, Ix1>,
336+
) -> Result<ArrayBase<S, Ix1>> {
331337
self.solvec_inplace(&mut b)?;
332338
Ok(b)
333339
}
@@ -346,7 +352,10 @@ where
346352
A: Scalar + Lapack,
347353
S: Data<Elem = A>,
348354
{
349-
fn solvec_inplace<'a, Sb>(&self, b: &'a mut ArrayBase<Sb, Ix1>) -> Result<&'a mut ArrayBase<Sb, Ix1>>
355+
fn solvec_inplace<'a, Sb>(
356+
&self,
357+
b: &'a mut ArrayBase<Sb, Ix1>,
358+
) -> Result<&'a mut ArrayBase<Sb, Ix1>>
350359
where
351360
Sb: DataMut<Elem = A>,
352361
{

src/convert.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ where
9393
} else {
9494
ArrayBase::from_shape_vec(a.dim().f(), a.into_raw_vec()).unwrap()
9595
};
96-
assert_eq!(new.strides(), strides.as_slice(), "Custom stride is not supported");
96+
assert_eq!(
97+
new.strides(),
98+
strides.as_slice(),
99+
"Custom stride is not supported"
100+
);
97101
new
98102
}
99103

src/eig.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! Eigenvalue decomposition for non-symmetric square matrices
22
3-
use ndarray::*;
43
use crate::error::*;
54
use crate::layout::*;
65
use crate::types::*;
6+
use ndarray::*;
77

88
/// Eigenvalue decomposition of general matrix reference
99
pub trait Eig {
@@ -27,7 +27,12 @@ where
2727
let layout = a.square_layout()?;
2828
let (s, t) = unsafe { A::eig(true, layout, a.as_allocated_mut()?)? };
2929
let (n, _) = layout.size();
30-
Ok((ArrayBase::from(s), ArrayBase::from(t).into_shape((n as usize, n as usize)).unwrap()))
30+
Ok((
31+
ArrayBase::from(s),
32+
ArrayBase::from(t)
33+
.into_shape((n as usize, n as usize))
34+
.unwrap(),
35+
))
3136
}
3237
}
3338

@@ -49,4 +54,4 @@ where
4954
let (s, _) = unsafe { A::eig(true, a.square_layout()?, a.as_allocated_mut()?)? };
5055
Ok(ArrayBase::from(s))
5156
}
52-
}
57+
}

src/error.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@ pub enum LinalgError {
2424
impl fmt::Display for LinalgError {
2525
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2626
match self {
27-
LinalgError::NotSquare { rows, cols } => write!(f, "Not square: rows({}) != cols({})", rows, cols),
28-
LinalgError::Lapack { return_code } => write!(f, "LAPACK: return_code = {}", return_code),
29-
LinalgError::InvalidStride { s0, s1 } => write!(f, "invalid stride: s0={}, s1={}", s0, s1),
27+
LinalgError::NotSquare { rows, cols } => {
28+
write!(f, "Not square: rows({}) != cols({})", rows, cols)
29+
}
30+
LinalgError::Lapack { return_code } => {
31+
write!(f, "LAPACK: return_code = {}", return_code)
32+
}
33+
LinalgError::InvalidStride { s0, s1 } => {
34+
write!(f, "invalid stride: s0={}, s1={}", s0, s1)
35+
}
3036
LinalgError::MemoryNotCont => write!(f, "Memory is not contiguous"),
3137
LinalgError::Shape(err) => write!(f, "Shape Error: {}", err),
3238
}

src/inner.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ where
2424
assert_eq!(self.len(), rhs.len());
2525
Zip::from(self)
2626
.and(rhs)
27-
.fold_while(A::zero(), |acc, s, r| FoldWhile::Continue(acc + s.conj() * *r))
27+
.fold_while(A::zero(), |acc, s, r| {
28+
FoldWhile::Continue(acc + s.conj() * *r)
29+
})
2830
.into_inner()
2931
}
3032
}

src/krylov/arnoldi.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ where
9797
}
9898

9999
/// Utility to execute Arnoldi iteration with Householder reflection
100-
pub fn arnoldi_householder<A, S>(a: impl LinearOperator<Elem = A>, v: ArrayBase<S, Ix1>, tol: A::Real) -> (Q<A>, H<A>)
100+
pub fn arnoldi_householder<A, S>(
101+
a: impl LinearOperator<Elem = A>,
102+
v: ArrayBase<S, Ix1>,
103+
tol: A::Real,
104+
) -> (Q<A>, H<A>)
101105
where
102106
A: Scalar + Lapack,
103107
S: DataMut<Elem = A>,
@@ -107,7 +111,11 @@ where
107111
}
108112

109113
/// Utility to execute Arnoldi iteration with modified Gram-Schmit orthogonalizer
110-
pub fn arnoldi_mgs<A, S>(a: impl LinearOperator<Elem = A>, v: ArrayBase<S, Ix1>, tol: A::Real) -> (Q<A>, H<A>)
114+
pub fn arnoldi_mgs<A, S>(
115+
a: impl LinearOperator<Elem = A>,
116+
v: ArrayBase<S, Ix1>,
117+
tol: A::Real,
118+
) -> (Q<A>, H<A>)
111119
where
112120
A: Scalar + Lapack,
113121
S: DataMut<Elem = A>,

0 commit comments

Comments
 (0)