Skip to content

Commit b729220

Browse files
committed
Format in default settings
1 parent 6379b5b commit b729220

32 files changed

+497
-110
lines changed

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();

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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ where
2929
let (n, _) = layout.size();
3030
Ok((
3131
ArrayBase::from(s),
32-
ArrayBase::from(t).into_shape((n as usize, n as usize)).unwrap(),
32+
ArrayBase::from(t)
33+
.into_shape((n as usize, n as usize))
34+
.unwrap(),
3335
))
3436
}
3537
}

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>,

src/krylov/householder.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ impl<A: Scalar + Lapack> Householder<A> {
7171
S: DataMut<Elem = A>,
7272
{
7373
assert!(k < self.v.len());
74-
assert_eq!(a.len(), self.dim, "Input array size mismaches to the dimension");
74+
assert_eq!(
75+
a.len(),
76+
self.dim,
77+
"Input array size mismaches to the dimension"
78+
);
7579
reflect(&self.v[k].slice(s![k..]), &mut a.slice_mut(s![k..]));
7680
}
7781

src/lapack/cholesky.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ pub trait Cholesky_: Sized {
1818
/// **Warning: Only the portion of `a` corresponding to `UPLO` is written.**
1919
unsafe fn inv_cholesky(l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<()>;
2020
/// Wrapper of `*potrs`
21-
unsafe fn solve_cholesky(l: MatrixLayout, uplo: UPLO, a: &[Self], b: &mut [Self]) -> Result<()>;
21+
unsafe fn solve_cholesky(l: MatrixLayout, uplo: UPLO, a: &[Self], b: &mut [Self])
22+
-> Result<()>;
2223
}
2324

2425
macro_rules! impl_cholesky {
@@ -36,7 +37,12 @@ macro_rules! impl_cholesky {
3637
into_result(info, ())
3738
}
3839

39-
unsafe fn solve_cholesky(l: MatrixLayout, uplo: UPLO, a: &[Self], b: &mut [Self]) -> Result<()> {
40+
unsafe fn solve_cholesky(
41+
l: MatrixLayout,
42+
uplo: UPLO,
43+
a: &[Self],
44+
b: &mut [Self],
45+
) -> Result<()> {
4046
let (n, _) = l.size();
4147
let nrhs = 1;
4248
let ldb = 1;

src/lapack/eig.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ use super::into_result;
1111

1212
/// Wraps `*geev` for real/complex
1313
pub trait Eig_: Scalar {
14-
unsafe fn eig(calc_v: bool, l: MatrixLayout, a: &mut [Self]) -> Result<(Vec<Self::Complex>, Vec<Self::Complex>)>;
14+
unsafe fn eig(
15+
calc_v: bool,
16+
l: MatrixLayout,
17+
a: &mut [Self],
18+
) -> Result<(Vec<Self::Complex>, Vec<Self::Complex>)>;
1519
}
1620

1721
macro_rules! impl_eig_complex {

src/lapack/eigh.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ use super::{into_result, UPLO};
1111

1212
/// Wraps `*syev` for real and `*heev` for complex
1313
pub trait Eigh_: Scalar {
14-
unsafe fn eigh(calc_eigenvec: bool, l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<Vec<Self::Real>>;
14+
unsafe fn eigh(
15+
calc_eigenvec: bool,
16+
l: MatrixLayout,
17+
uplo: UPLO,
18+
a: &mut [Self],
19+
) -> Result<Vec<Self::Real>>;
1520
unsafe fn eigh_generalized(
1621
calc_eigenvec: bool,
1722
l: MatrixLayout,
@@ -24,7 +29,12 @@ pub trait Eigh_: Scalar {
2429
macro_rules! impl_eigh {
2530
($scalar:ty, $ev:path, $evg:path) => {
2631
impl Eigh_ for $scalar {
27-
unsafe fn eigh(calc_v: bool, l: MatrixLayout, uplo: UPLO, mut a: &mut [Self]) -> Result<Vec<Self::Real>> {
32+
unsafe fn eigh(
33+
calc_v: bool,
34+
l: MatrixLayout,
35+
uplo: UPLO,
36+
mut a: &mut [Self],
37+
) -> Result<Vec<Self::Real>> {
2838
let (n, _) = l.size();
2939
let jobz = if calc_v { b'V' } else { b'N' };
3040
let mut w = vec![Self::Real::zero(); n as usize];

src/lapack/opnorm.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ macro_rules! impl_opnorm {
1818
unsafe fn opnorm(t: NormType, l: MatrixLayout, a: &[Self]) -> Self::Real {
1919
match l {
2020
MatrixLayout::F((col, lda)) => $lange(cm, t as u8, lda, col, a, lda),
21-
MatrixLayout::C((row, lda)) => $lange(cm, t.transpose() as u8, lda, row, a, lda),
21+
MatrixLayout::C((row, lda)) => {
22+
$lange(cm, t.transpose() as u8, lda, row, a, lda)
23+
}
2224
}
2325
}
2426
}

src/lapack/solve.rs

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ pub trait Solve_: Scalar + Sized {
2626
///
2727
/// `anorm` should be the 1-norm of the matrix `a`.
2828
unsafe fn rcond(l: MatrixLayout, a: &[Self], anorm: Self::Real) -> Result<Self::Real>;
29-
unsafe fn solve(l: MatrixLayout, t: Transpose, a: &[Self], p: &Pivot, b: &mut [Self]) -> Result<()>;
29+
unsafe fn solve(
30+
l: MatrixLayout,
31+
t: Transpose,
32+
a: &[Self],
33+
p: &Pivot,
34+
b: &mut [Self],
35+
) -> Result<()>;
3036
}
3137

3238
macro_rules! impl_solve {
@@ -61,18 +67,58 @@ macro_rules! impl_solve {
6167
into_result(info, rcond)
6268
}
6369

64-
unsafe fn solve(l: MatrixLayout, t: Transpose, a: &[Self], ipiv: &Pivot, b: &mut [Self]) -> Result<()> {
70+
unsafe fn solve(
71+
l: MatrixLayout,
72+
t: Transpose,
73+
a: &[Self],
74+
ipiv: &Pivot,
75+
b: &mut [Self],
76+
) -> Result<()> {
6577
let (n, _) = l.size();
6678
let nrhs = 1;
6779
let ldb = 1;
68-
let info = $getrs(l.lapacke_layout(), t as u8, n, nrhs, a, l.lda(), ipiv, b, ldb);
80+
let info = $getrs(
81+
l.lapacke_layout(),
82+
t as u8,
83+
n,
84+
nrhs,
85+
a,
86+
l.lda(),
87+
ipiv,
88+
b,
89+
ldb,
90+
);
6991
into_result(info, ())
7092
}
7193
}
7294
};
7395
} // impl_solve!
7496

75-
impl_solve!(f64, lapacke::dgetrf, lapacke::dgetri, lapacke::dgecon, lapacke::dgetrs);
76-
impl_solve!(f32, lapacke::sgetrf, lapacke::sgetri, lapacke::sgecon, lapacke::sgetrs);
77-
impl_solve!(c64, lapacke::zgetrf, lapacke::zgetri, lapacke::zgecon, lapacke::zgetrs);
78-
impl_solve!(c32, lapacke::cgetrf, lapacke::cgetri, lapacke::cgecon, lapacke::cgetrs);
97+
impl_solve!(
98+
f64,
99+
lapacke::dgetrf,
100+
lapacke::dgetri,
101+
lapacke::dgecon,
102+
lapacke::dgetrs
103+
);
104+
impl_solve!(
105+
f32,
106+
lapacke::sgetrf,
107+
lapacke::sgetri,
108+
lapacke::sgecon,
109+
lapacke::sgetrs
110+
);
111+
impl_solve!(
112+
c64,
113+
lapacke::zgetrf,
114+
lapacke::zgetri,
115+
lapacke::zgecon,
116+
lapacke::zgetrs
117+
);
118+
impl_solve!(
119+
c32,
120+
lapacke::cgetrf,
121+
lapacke::cgetri,
122+
lapacke::cgecon,
123+
lapacke::cgetrs
124+
);

src/lapack/solveh.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ pub trait Solveh_: Sized {
1616
/// Wrapper of `*sytri` and `*hetri`
1717
unsafe fn invh(l: MatrixLayout, uplo: UPLO, a: &mut [Self], ipiv: &Pivot) -> Result<()>;
1818
/// Wrapper of `*sytrs` and `*hetrs`
19-
unsafe fn solveh(l: MatrixLayout, uplo: UPLO, a: &[Self], ipiv: &Pivot, b: &mut [Self]) -> Result<()>;
19+
unsafe fn solveh(
20+
l: MatrixLayout,
21+
uplo: UPLO,
22+
a: &[Self],
23+
ipiv: &Pivot,
24+
b: &mut [Self],
25+
) -> Result<()>;
2026
}
2127

2228
macro_rules! impl_solveh {
@@ -34,20 +40,41 @@ macro_rules! impl_solveh {
3440
}
3541
}
3642

37-
unsafe fn invh(l: MatrixLayout, uplo: UPLO, a: &mut [Self], ipiv: &Pivot) -> Result<()> {
43+
unsafe fn invh(
44+
l: MatrixLayout,
45+
uplo: UPLO,
46+
a: &mut [Self],
47+
ipiv: &Pivot,
48+
) -> Result<()> {
3849
let (n, _) = l.size();
3950
let info = $tri(l.lapacke_layout(), uplo as u8, n, a, l.lda(), ipiv);
4051
into_result(info, ())
4152
}
4253

43-
unsafe fn solveh(l: MatrixLayout, uplo: UPLO, a: &[Self], ipiv: &Pivot, b: &mut [Self]) -> Result<()> {
54+
unsafe fn solveh(
55+
l: MatrixLayout,
56+
uplo: UPLO,
57+
a: &[Self],
58+
ipiv: &Pivot,
59+
b: &mut [Self],
60+
) -> Result<()> {
4461
let (n, _) = l.size();
4562
let nrhs = 1;
4663
let ldb = match l {
4764
MatrixLayout::C(_) => 1,
4865
MatrixLayout::F(_) => n,
4966
};
50-
let info = $trs(l.lapacke_layout(), uplo as u8, n, nrhs, a, l.lda(), ipiv, b, ldb);
67+
let info = $trs(
68+
l.lapacke_layout(),
69+
uplo as u8,
70+
n,
71+
nrhs,
72+
a,
73+
l.lda(),
74+
ipiv,
75+
b,
76+
ldb,
77+
);
5178
into_result(info, ())
5279
}
5380
}

src/lapack/svd.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,23 @@ pub struct SVDOutput<A: Scalar> {
2929

3030
/// Wraps `*gesvd`
3131
pub trait SVD_: Scalar {
32-
unsafe fn svd(l: MatrixLayout, calc_u: bool, calc_vt: bool, a: &mut [Self]) -> Result<SVDOutput<Self>>;
32+
unsafe fn svd(
33+
l: MatrixLayout,
34+
calc_u: bool,
35+
calc_vt: bool,
36+
a: &mut [Self],
37+
) -> Result<SVDOutput<Self>>;
3338
}
3439

3540
macro_rules! impl_svd {
3641
($scalar:ty, $gesvd:path) => {
3742
impl SVD_ for $scalar {
38-
unsafe fn svd(l: MatrixLayout, calc_u: bool, calc_vt: bool, mut a: &mut [Self]) -> Result<SVDOutput<Self>> {
43+
unsafe fn svd(
44+
l: MatrixLayout,
45+
calc_u: bool,
46+
calc_vt: bool,
47+
mut a: &mut [Self],
48+
) -> Result<SVDOutput<Self>> {
3949
let (m, n) = l.size();
4050
let k = ::std::cmp::min(n, m);
4151
let lda = l.lda();

0 commit comments

Comments
 (0)