Skip to content

Commit 07cf1a4

Browse files
committed
Format all
1 parent a0b8526 commit 07cf1a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+525
-490
lines changed

examples/eigh.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
extern crate ndarray;
32
extern crate ndarray_linalg;
43

examples/solve.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
extern crate ndarray;
32
extern crate ndarray_linalg;
43

examples/solveh.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
extern crate ndarray;
32
extern crate ndarray_linalg;
43

src/assert.rs

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@ use super::types::*;
88
/// check two values are close in terms of the relative torrence
99
pub fn rclose<A: Scalar>(test: A, truth: A, rtol: A::Real) -> Result<A::Real, A::Real> {
1010
let dev = (test - truth).abs() / truth.abs();
11-
if dev < rtol { Ok(dev) } else { Err(dev) }
11+
if dev < rtol {
12+
Ok(dev)
13+
} else {
14+
Err(dev)
15+
}
1216
}
1317

1418
/// check two values are close in terms of the absolute torrence
1519
pub fn aclose<A: Scalar>(test: A, truth: A, atol: A::Real) -> Result<A::Real, A::Real> {
1620
let dev = (test - truth).abs();
17-
if dev < atol { Ok(dev) } else { Err(dev) }
21+
if dev < atol {
22+
Ok(dev)
23+
} else {
24+
Err(dev)
25+
}
1826
}
1927

2028
/// check two arrays are close in maximum norm
@@ -30,7 +38,11 @@ where
3038
D: Dimension,
3139
{
3240
let tol = (test - truth).norm_max();
33-
if tol < atol { Ok(tol) } else { Err(tol) }
41+
if tol < atol {
42+
Ok(tol)
43+
} else {
44+
Err(tol)
45+
}
3446
}
3547

3648
/// check two arrays are close in L1 norm
@@ -46,7 +58,11 @@ where
4658
D: Dimension,
4759
{
4860
let tol = (test - truth).norm_l1() / truth.norm_l1();
49-
if tol < rtol { Ok(tol) } else { Err(tol) }
61+
if tol < rtol {
62+
Ok(tol)
63+
} else {
64+
Err(tol)
65+
}
5066
}
5167

5268
/// check two arrays are close in L2 norm
@@ -62,21 +78,26 @@ where
6278
D: Dimension,
6379
{
6480
let tol = (test - truth).norm_l2() / truth.norm_l2();
65-
if tol < rtol { Ok(tol) } else { Err(tol) }
81+
if tol < rtol {
82+
Ok(tol)
83+
} else {
84+
Err(tol)
85+
}
6686
}
6787

6888
macro_rules! generate_assert {
6989
($assert:ident, $close:path) => {
70-
#[macro_export]
71-
macro_rules! $assert {
72-
($test:expr, $truth:expr, $tol:expr) => {
73-
$crate::$close($test, $truth, $tol).unwrap();
90+
#[macro_export]
91+
macro_rules! $assert {
92+
($test: expr,$truth: expr,$tol: expr) => {
93+
$crate::$close($test, $truth, $tol).unwrap();
94+
};
95+
($test: expr,$truth: expr,$tol: expr; $comment: expr) => {
96+
$crate::$close($test, $truth, $tol).expect($comment);
97+
};
98+
}
7499
};
75-
($test:expr, $truth:expr, $tol:expr; $comment:expr) => {
76-
$crate::$close($test, $truth, $tol).expect($comment);
77-
};
78-
}
79-
}} // generate_assert!
100+
} // generate_assert!
80101

81102
generate_assert!(assert_rclose, rclose);
82103
generate_assert!(assert_aclose, aclose);

src/cholesky.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ pub trait DeterminantC {
408408
fn ln_detc(&self) -> Self::Output;
409409
}
410410

411-
412411
/// Determinant of Hermitian (or real symmetric) positive definite matrix
413412
pub trait DeterminantCInto {
414413
type Output;

src/convert.rs

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

src/eigh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
33
use ndarray::*;
44

5-
use super::UPLO;
65
use super::diagonal::*;
76
use super::error::*;
87
use super::layout::*;
98
use super::operator::*;
109
use super::types::*;
10+
use super::UPLO;
1111

1212
/// Eigenvalue decomposition of Hermite matrix reference
1313
pub trait Eigh {

src/lapack_traits/cholesky.rs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use error::*;
66
use layout::MatrixLayout;
77
use types::*;
88

9-
use super::{UPLO, into_result};
9+
use super::{into_result, UPLO};
1010

1111
pub trait Cholesky_: Sized {
1212
/// Cholesky: wrapper of `*potrf`
@@ -23,28 +23,29 @@ pub trait Cholesky_: Sized {
2323

2424
macro_rules! impl_cholesky {
2525
($scalar:ty, $trf:path, $tri:path, $trs:path) => {
26-
impl Cholesky_ for $scalar {
27-
unsafe fn cholesky(l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<()> {
28-
let (n, _) = l.size();
29-
let info = $trf(l.lapacke_layout(), uplo as u8, n, a, n);
30-
into_result(info, ())
31-
}
32-
33-
unsafe fn inv_cholesky(l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<()> {
34-
let (n, _) = l.size();
35-
let info = $tri(l.lapacke_layout(), uplo as u8, n, a, l.lda());
36-
into_result(info, ())
37-
}
38-
39-
unsafe fn solve_cholesky(l: MatrixLayout, uplo: UPLO, a: &[Self], b: &mut [Self]) -> Result<()> {
40-
let (n, _) = l.size();
41-
let nrhs = 1;
42-
let ldb = 1;
43-
let info = $trs(l.lapacke_layout(), uplo as u8, n, nrhs, a, l.lda(), b, ldb);
44-
into_result(info, ())
45-
}
46-
}
47-
}} // end macro_rules
26+
impl Cholesky_ for $scalar {
27+
unsafe fn cholesky(l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<()> {
28+
let (n, _) = l.size();
29+
let info = $trf(l.lapacke_layout(), uplo as u8, n, a, n);
30+
into_result(info, ())
31+
}
32+
33+
unsafe fn inv_cholesky(l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<()> {
34+
let (n, _) = l.size();
35+
let info = $tri(l.lapacke_layout(), uplo as u8, n, a, l.lda());
36+
into_result(info, ())
37+
}
38+
39+
unsafe fn solve_cholesky(l: MatrixLayout, uplo: UPLO, a: &[Self], b: &mut [Self]) -> Result<()> {
40+
let (n, _) = l.size();
41+
let nrhs = 1;
42+
let ldb = 1;
43+
let info = $trs(l.lapacke_layout(), uplo as u8, n, nrhs, a, l.lda(), b, ldb);
44+
into_result(info, ())
45+
}
46+
}
47+
};
48+
} // end macro_rules
4849

4950
impl_cholesky!(f64, lapacke::dpotrf, lapacke::dpotri, lapacke::dpotrs);
5051
impl_cholesky!(f32, lapacke::spotrf, lapacke::spotri, lapacke::spotrs);

src/lapack_traits/eigh.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use error::*;
77
use layout::MatrixLayout;
88
use types::*;
99

10-
use super::{UPLO, into_result};
10+
use super::{into_result, UPLO};
1111

1212
/// Wraps `*syev` for real and `*heev` for complex
1313
pub trait Eigh_: AssociatedReal {
@@ -16,16 +16,17 @@ pub trait Eigh_: AssociatedReal {
1616

1717
macro_rules! impl_eigh {
1818
($scalar:ty, $ev:path) => {
19-
impl Eigh_ for $scalar {
20-
unsafe fn eigh(calc_v: bool, l: MatrixLayout, uplo: UPLO, mut a: &mut [Self]) -> Result<Vec<Self::Real>> {
21-
let (n, _) = l.size();
22-
let jobz = if calc_v { b'V' } else { b'N' };
23-
let mut w = vec![Self::Real::zero(); n as usize];
24-
let info = $ev(l.lapacke_layout(), jobz, uplo as u8, n, &mut a, n, &mut w);
25-
into_result(info, w)
26-
}
27-
}
28-
}} // impl_eigh!
19+
impl Eigh_ for $scalar {
20+
unsafe fn eigh(calc_v: bool, l: MatrixLayout, uplo: UPLO, mut a: &mut [Self]) -> Result<Vec<Self::Real>> {
21+
let (n, _) = l.size();
22+
let jobz = if calc_v { b'V' } else { b'N' };
23+
let mut w = vec![Self::Real::zero(); n as usize];
24+
let info = $ev(l.lapacke_layout(), jobz, uplo as u8, n, &mut a, n, &mut w);
25+
into_result(info, w)
26+
}
27+
}
28+
};
29+
} // impl_eigh!
2930

3031
impl_eigh!(f64, lapacke::dsyev);
3132
impl_eigh!(f32, lapacke::ssyev);

src/lapack_traits/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//! Define traits wrapping LAPACK routines
22
3+
pub mod cholesky;
4+
pub mod eigh;
35
pub mod opnorm;
46
pub mod qr;
5-
pub mod svd;
67
pub mod solve;
78
pub mod solveh;
8-
pub mod cholesky;
9-
pub mod eigh;
9+
pub mod svd;
1010
pub mod triangular;
1111

1212
pub use self::cholesky::*;
@@ -23,10 +23,7 @@ use super::types::*;
2323

2424
pub type Pivot = Vec<i32>;
2525

26-
pub trait LapackScalar
27-
: OperatorNorm_ + QR_ + SVD_ + Solve_ + Solveh_ + Cholesky_ + Eigh_ + Triangular_
28-
{
29-
}
26+
pub trait LapackScalar: OperatorNorm_ + QR_ + SVD_ + Solve_ + Solveh_ + Cholesky_ + Eigh_ + Triangular_ {}
3027

3128
impl LapackScalar for f32 {}
3229
impl LapackScalar for f64 {}

0 commit comments

Comments
 (0)