Skip to content

Commit 6f1f379

Browse files
authored
Merge pull request #109 from termoshtt/format
Format using rustfmt 0.6
2 parents 3712c93 + 931ecf3 commit 6f1f379

Some content is hidden

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

45 files changed

+582
-551
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

rustfmt.toml

Lines changed: 49 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,56 @@
1-
verbose = false
2-
disable_all_formatting = false
3-
skip_children = false
41
max_width = 120
5-
error_on_line_overflow = true
2+
hard_tabs = false
63
tab_spaces = 4
7-
fn_call_width = 60
8-
struct_lit_width = 18
9-
struct_variant_width = 35
10-
force_explicit_abi = true
114
newline_style = "Unix"
12-
fn_brace_style = "SameLineWhere"
13-
item_brace_style = "SameLineWhere"
14-
control_style = "Rfc"
15-
control_brace_style = "AlwaysSameLine"
16-
impl_empty_single_line = true
17-
trailing_comma = "Vertical"
18-
fn_empty_single_line = true
5+
use_small_heuristics = true
6+
indent_style = "Block"
7+
wrap_comments = false
8+
comment_width = 100
9+
normalize_comments = false
10+
format_strings = false
11+
empty_item_single_line = true
12+
struct_lit_single_line = true
1913
fn_single_line = false
20-
fn_return_indent = "WithArgs"
21-
fn_args_paren_newline = false
22-
fn_args_density = "Tall"
23-
fn_args_layout = "Block"
24-
array_layout = "Block"
25-
array_width = 60
26-
type_punctuation_density = "Wide"
27-
where_style = "Rfc"
28-
where_density = "CompressedIfEmpty"
29-
where_layout = "Vertical"
30-
where_pred_indent = "Visual"
31-
generics_indent = "Block"
32-
struct_lit_style = "Block"
33-
struct_lit_multiline_style = "PreferSingle"
34-
fn_call_style = "Block"
35-
report_todo = "Never"
36-
report_fixme = "Never"
37-
chain_indent = "Block"
38-
chain_one_line_max = 60
39-
chain_split_single_child = false
14+
where_single_line = false
15+
imports_indent = "Visual"
16+
imports_layout = "Mixed"
17+
merge_imports = false
4018
reorder_imports = true
41-
reorder_imports_in_group = true
42-
reorder_imported_names = true
43-
single_line_if_else_max_width = 50
44-
format_strings = false
45-
force_format_strings = false
46-
take_source_hints = false
47-
hard_tabs = false
48-
wrap_comments = false
49-
comment_width = 80
50-
normalize_comments = true
51-
wrap_match_arms = true
52-
match_block_trailing_comma = false
53-
indent_match_arms = true
54-
closure_block_indent_threshold = 7
55-
space_before_type_annotation = false
56-
space_after_type_annotation_colon = true
57-
space_before_struct_lit_field_colon = false
58-
space_after_struct_lit_field_colon = true
59-
space_before_bound = false
60-
space_after_bound_colon = true
19+
reorder_modules = true
20+
reorder_impl_items = false
21+
type_punctuation_density = "Wide"
22+
space_before_colon = false
23+
space_after_colon = true
6124
spaces_around_ranges = false
62-
spaces_within_angle_brackets = false
63-
spaces_within_square_brackets = false
64-
spaces_within_parens = false
65-
use_try_shorthand = true
66-
write_mode = "Replace"
67-
condense_wildcard_suffixes = false
25+
spaces_within_parens_and_brackets = false
26+
binop_separator = "Front"
27+
remove_blank_lines_at_start_or_end_of_block = true
6828
combine_control_expr = true
29+
struct_field_align_threshold = 0
30+
match_arm_blocks = true
31+
force_multiline_blocks = false
32+
fn_args_density = "Tall"
33+
brace_style = "SameLineWhere"
34+
control_brace_style = "AlwaysSameLine"
35+
trailing_semicolon = true
36+
trailing_comma = "Vertical"
37+
match_block_trailing_comma = false
38+
blank_lines_upper_bound = 1
39+
blank_lines_lower_bound = 0
40+
merge_derives = true
41+
use_try_shorthand = false
42+
condense_wildcard_suffixes = false
43+
force_explicit_abi = true
44+
use_field_init_shorthand = false
45+
write_mode = "Overwrite"
46+
color = "Auto"
47+
unstable_features = false
48+
disable_all_formatting = false
49+
skip_children = false
50+
hide_parse_errors = false
51+
error_on_line_overflow = false
52+
error_on_unformatted = false
53+
report_todo = "Never"
54+
report_fixme = "Never"
55+
ignore = []
56+
verbose_diff = false

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)