diff --git a/benches/core/matrix.rs b/benches/core/matrix.rs index ac983ff4..7b4f85bd 100644 --- a/benches/core/matrix.rs +++ b/benches/core/matrix.rs @@ -50,11 +50,13 @@ fn mat_div_scalar(b: &mut criterion::Criterion) { let a = DMatrix::from_row_slice(1000, 1000, &vec![2.0; 1000000]); let n = 42.0; - b.bench_function("mat_div_scalar", move |bh| bh.iter(|| { - let mut aa = a.clone(); - let mut b = aa.slice_mut((0, 0), (1000, 1000)); - b /= n - })); + b.bench_function("mat_div_scalar", move |bh| { + bh.iter(|| { + let mut aa = a.clone(); + let mut b = aa.slice_mut((0, 0), (1000, 1000)); + b /= n + }) + }); } fn mat100_add_mat100(bench: &mut criterion::Criterion) { @@ -138,9 +140,11 @@ fn copy_from(bench: &mut criterion::Criterion) { let a = DMatrix::::new_random(1000, 1000); let mut b = DMatrix::::new_random(1000, 1000); - bench.bench_function("copy_from", move |bh| bh.iter(|| { - b.copy_from(&a); - })); + bench.bench_function("copy_from", move |bh| { + bh.iter(|| { + b.copy_from(&a); + }) + }); } fn axpy(bench: &mut criterion::Criterion) { @@ -148,9 +152,11 @@ fn axpy(bench: &mut criterion::Criterion) { let mut y = DVector::::from_element(100000, 3.0); let a = 42.0; - bench.bench_function("axpy", move |bh| bh.iter(|| { - y.axpy(a, &x, 1.0); - })); + bench.bench_function("axpy", move |bh| { + bh.iter(|| { + y.axpy(a, &x, 1.0); + }) + }); } fn tr_mul_to(bench: &mut criterion::Criterion) { @@ -166,60 +172,57 @@ fn mat_mul_mat(bench: &mut criterion::Criterion) { let b = DMatrix::::new_random(100, 100); let mut ab = DMatrix::::from_element(100, 100, 0.0); - bench.bench_function("mat_mul_mat", move |bh| bh.iter(|| { - test::black_box(a.mul_to(&b, &mut ab)); - })); + bench.bench_function("mat_mul_mat", move |bh| { + bh.iter(|| { + test::black_box(a.mul_to(&b, &mut ab)); + }) + }); } fn mat100_from_fn(bench: &mut criterion::Criterion) { - bench.bench_function("mat100_from_fn", move |bh| bh.iter(|| DMatrix::from_fn(100, 100, |a, b| a + b))); + bench.bench_function("mat100_from_fn", move |bh| { + bh.iter(|| DMatrix::from_fn(100, 100, |a, b| a + b)) + }); } fn mat500_from_fn(bench: &mut criterion::Criterion) { - bench.bench_function("mat500_from_fn", move |bh| bh.iter(|| DMatrix::from_fn(500, 500, |a, b| a + b))); + bench.bench_function("mat500_from_fn", move |bh| { + bh.iter(|| DMatrix::from_fn(500, 500, |a, b| a + b)) + }); } -criterion_group!(matrix, +criterion_group!( + matrix, mat2_mul_m, mat3_mul_m, mat4_mul_m, - mat2_tr_mul_m, mat3_tr_mul_m, mat4_tr_mul_m, - mat2_add_m, mat3_add_m, mat4_add_m, - mat2_sub_m, mat3_sub_m, mat4_sub_m, - mat2_mul_v, mat3_mul_v, mat4_mul_v, - mat2_tr_mul_v, mat3_tr_mul_v, mat4_tr_mul_v, - mat2_mul_s, mat3_mul_s, mat4_mul_s, - mat2_div_s, mat3_div_s, mat4_div_s, - mat2_inv, mat3_inv, mat4_inv, - mat2_transpose, mat3_transpose, mat4_transpose, - mat_div_scalar, mat100_add_mat100, mat4_mul_mat4, diff --git a/benches/core/vector.rs b/benches/core/vector.rs index fd44aedc..2806d034 100644 --- a/benches/core/vector.rs +++ b/benches/core/vector.rs @@ -55,7 +55,9 @@ fn vec10000_axpy_f64(bh: &mut criterion::Criterion) { let b = DVector::new_random(10000); let n = rng.gen::(); - bh.bench_function("vec10000_axpy_f64", move |bh| bh.iter(|| a.axpy(n, &b, 1.0))); + bh.bench_function("vec10000_axpy_f64", move |bh| { + bh.iter(|| a.axpy(n, &b, 1.0)) + }); } fn vec10000_axpy_beta_f64(bh: &mut criterion::Criterion) { @@ -66,7 +68,9 @@ fn vec10000_axpy_beta_f64(bh: &mut criterion::Criterion) { let n = rng.gen::(); let beta = rng.gen::(); - bh.bench_function("vec10000_axpy_beta_f64", move |bh| bh.iter(|| a.axpy(n, &b, beta))); + bh.bench_function("vec10000_axpy_beta_f64", move |bh| { + bh.iter(|| a.axpy(n, &b, beta)) + }); } fn vec10000_axpy_f64_slice(bh: &mut criterion::Criterion) { @@ -76,12 +80,14 @@ fn vec10000_axpy_f64_slice(bh: &mut criterion::Criterion) { let b = DVector::new_random(10000); let n = rng.gen::(); - bh.bench_function("vec10000_axpy_f64_slice", move |bh| bh.iter(|| { - let mut a = a.fixed_rows_mut::(0); - let b = b.fixed_rows::(0); + bh.bench_function("vec10000_axpy_f64_slice", move |bh| { + bh.iter(|| { + let mut a = a.fixed_rows_mut::(0); + let b = b.fixed_rows::(0); - a.axpy(n, &b, 1.0) - })); + a.axpy(n, &b, 1.0) + }) + }); } fn vec10000_axpy_f64_static(bh: &mut criterion::Criterion) { @@ -92,7 +98,9 @@ fn vec10000_axpy_f64_static(bh: &mut criterion::Criterion) { let n = rng.gen::(); // NOTE: for some reasons, it is much faster if the arument are boxed (Box::new(VectorN...)). - bh.bench_function("vec10000_axpy_f64_static", move |bh| bh.iter(|| a.axpy(n, &b, 1.0))); + bh.bench_function("vec10000_axpy_f64_static", move |bh| { + bh.iter(|| a.axpy(n, &b, 1.0)) + }); } fn vec10000_axpy_f32(bh: &mut criterion::Criterion) { @@ -102,7 +110,9 @@ fn vec10000_axpy_f32(bh: &mut criterion::Criterion) { let b = DVector::new_random(10000); let n = rng.gen::(); - bh.bench_function("vec10000_axpy_f32", move |bh| bh.iter(|| a.axpy(n, &b, 1.0))); + bh.bench_function("vec10000_axpy_f32", move |bh| { + bh.iter(|| a.axpy(n, &b, 1.0)) + }); } fn vec10000_axpy_beta_f32(bh: &mut criterion::Criterion) { @@ -113,51 +123,43 @@ fn vec10000_axpy_beta_f32(bh: &mut criterion::Criterion) { let n = rng.gen::(); let beta = rng.gen::(); - bh.bench_function("vec10000_axpy_beta_f32", move |bh| bh.iter(|| a.axpy(n, &b, beta))); + bh.bench_function("vec10000_axpy_beta_f32", move |bh| { + bh.iter(|| a.axpy(n, &b, beta)) + }); } -criterion_group!(vector, +criterion_group!( + vector, vec2_add_v_f32, vec3_add_v_f32, vec4_add_v_f32, - vec2_add_v_f64, vec3_add_v_f64, vec4_add_v_f64, - vec2_sub_v, vec3_sub_v, vec4_sub_v, - vec2_mul_s, vec3_mul_s, vec4_mul_s, - vec2_div_s, vec3_div_s, vec4_div_s, - vec2_dot_f32, vec3_dot_f32, vec4_dot_f32, - vec2_dot_f64, vec3_dot_f64, vec4_dot_f64, - vec3_cross, - vec2_norm, vec3_norm, vec4_norm, - vec2_normalize, vec3_normalize, vec4_normalize, - vec10000_dot_f64, vec10000_dot_f32, - vec10000_axpy_f64, vec10000_axpy_beta_f64, vec10000_axpy_f64_slice, diff --git a/benches/geometry/quaternion.rs b/benches/geometry/quaternion.rs index 326872f3..37c29c01 100644 --- a/benches/geometry/quaternion.rs +++ b/benches/geometry/quaternion.rs @@ -26,7 +26,8 @@ bench_unop!(unit_quaternion_inv, UnitQuaternion, inverse); // bench_unop_self!(quaternion_conjugate, Quaternion, conjugate); // bench_unop!(quaternion_normalize, Quaternion, normalize); -criterion_group!(quaternion, +criterion_group!( + quaternion, quaternion_add_q, quaternion_sub_q, quaternion_mul_q, diff --git a/benches/linalg/bidiagonal.rs b/benches/linalg/bidiagonal.rs index ed126205..ad875264 100644 --- a/benches/linalg/bidiagonal.rs +++ b/benches/linalg/bidiagonal.rs @@ -6,70 +6,89 @@ mod macros; // Without unpack. fn bidiagonalize_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); - bh.bench_function("bidiagonalize_100x100", move |bh| bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))); + bh.bench_function("bidiagonalize_100x100", move |bh| { + bh.iter(|| test::black_box(Bidiagonal::new(m.clone()))) + }); } fn bidiagonalize_100x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 500); - bh.bench_function("bidiagonalize_100x500", move |bh| bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))); + bh.bench_function("bidiagonalize_100x500", move |bh| { + bh.iter(|| test::black_box(Bidiagonal::new(m.clone()))) + }); } fn bidiagonalize_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.bench_function("bidiagonalize_4x4", move |bh| bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))); + bh.bench_function("bidiagonalize_4x4", move |bh| { + bh.iter(|| test::black_box(Bidiagonal::new(m.clone()))) + }); } fn bidiagonalize_500x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 100); - bh.bench_function("bidiagonalize_500x100", move |bh| bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))); + bh.bench_function("bidiagonalize_500x100", move |bh| { + bh.iter(|| test::black_box(Bidiagonal::new(m.clone()))) + }); } fn bidiagonalize_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); - bh.bench_function("bidiagonalize_500x500", move |bh| bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))); + bh.bench_function("bidiagonalize_500x500", move |bh| { + bh.iter(|| test::black_box(Bidiagonal::new(m.clone()))) + }); } // With unpack. fn bidiagonalize_unpack_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); - bh.bench_function("bidiagonalize_unpack_100x100", move |bh| bh.iter(|| { - let bidiag = Bidiagonal::new(m.clone()); - let _ = bidiag.unpack(); - })); + bh.bench_function("bidiagonalize_unpack_100x100", move |bh| { + bh.iter(|| { + let bidiag = Bidiagonal::new(m.clone()); + let _ = bidiag.unpack(); + }) + }); } fn bidiagonalize_unpack_100x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 500); - bh.bench_function("bidiagonalize_unpack_100x500", move |bh| bh.iter(|| { - let bidiag = Bidiagonal::new(m.clone()); - let _ = bidiag.unpack(); - })); + bh.bench_function("bidiagonalize_unpack_100x500", move |bh| { + bh.iter(|| { + let bidiag = Bidiagonal::new(m.clone()); + let _ = bidiag.unpack(); + }) + }); } fn bidiagonalize_unpack_500x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 100); - bh.bench_function("bidiagonalize_unpack_500x100", move |bh| bh.iter(|| { - let bidiag = Bidiagonal::new(m.clone()); - let _ = bidiag.unpack(); - })); + bh.bench_function("bidiagonalize_unpack_500x100", move |bh| { + bh.iter(|| { + let bidiag = Bidiagonal::new(m.clone()); + let _ = bidiag.unpack(); + }) + }); } fn bidiagonalize_unpack_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); - bh.bench_function("bidiagonalize_unpack_500x500", move |bh| bh.iter(|| { - let bidiag = Bidiagonal::new(m.clone()); - let _ = bidiag.unpack(); - })); + bh.bench_function("bidiagonalize_unpack_500x500", move |bh| { + bh.iter(|| { + let bidiag = Bidiagonal::new(m.clone()); + let _ = bidiag.unpack(); + }) + }); } -criterion_group!(bidiagonal, +criterion_group!( + bidiagonal, bidiagonalize_100x100, bidiagonalize_100x500, bidiagonalize_4x4, bidiagonalize_500x100, -// bidiagonalize_500x500, // too long + // bidiagonalize_500x500, // too long bidiagonalize_unpack_100x100, bidiagonalize_unpack_100x500, bidiagonalize_unpack_500x100, -// bidiagonalize_unpack_500x500 // too long -); \ No newline at end of file + // bidiagonalize_unpack_500x500 // too long +); diff --git a/benches/linalg/cholesky.rs b/benches/linalg/cholesky.rs index 40ca9821..a03888f5 100644 --- a/benches/linalg/cholesky.rs +++ b/benches/linalg/cholesky.rs @@ -4,14 +4,18 @@ fn cholesky_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let m = &m * m.transpose(); - bh.bench_function("cholesky_100x100", move |bh| bh.iter(|| test::black_box(Cholesky::new(m.clone())))); + bh.bench_function("cholesky_100x100", move |bh| { + bh.iter(|| test::black_box(Cholesky::new(m.clone()))) + }); } fn cholesky_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let m = &m * m.transpose(); - bh.bench_function("cholesky_500x500", move |bh| bh.iter(|| test::black_box(Cholesky::new(m.clone())))); + bh.bench_function("cholesky_500x500", move |bh| { + bh.iter(|| test::black_box(Cholesky::new(m.clone()))) + }); } // With unpack. @@ -19,19 +23,23 @@ fn cholesky_decompose_unpack_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let m = &m * m.transpose(); - bh.bench_function("cholesky_decompose_unpack_100x100", move |bh| bh.iter(|| { - let chol = Cholesky::new(m.clone()).unwrap(); - let _ = chol.unpack(); - })); + bh.bench_function("cholesky_decompose_unpack_100x100", move |bh| { + bh.iter(|| { + let chol = Cholesky::new(m.clone()).unwrap(); + let _ = chol.unpack(); + }) + }); } fn cholesky_decompose_unpack_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let m = &m * m.transpose(); - bh.bench_function("cholesky_decompose_unpack_500x500", move |bh| bh.iter(|| { - let chol = Cholesky::new(m.clone()).unwrap(); - let _ = chol.unpack(); - })); + bh.bench_function("cholesky_decompose_unpack_500x500", move |bh| { + bh.iter(|| { + let chol = Cholesky::new(m.clone()).unwrap(); + let _ = chol.unpack(); + }) + }); } fn cholesky_solve_10x10(bh: &mut criterion::Criterion) { @@ -40,9 +48,11 @@ fn cholesky_solve_10x10(bh: &mut criterion::Criterion) { let v = DVector::::new_random(10); let chol = Cholesky::new(m.clone()).unwrap(); - bh.bench_function("cholesky_solve_10x10", move |bh| bh.iter(|| { - let _ = chol.solve(&v); - })); + bh.bench_function("cholesky_solve_10x10", move |bh| { + bh.iter(|| { + let _ = chol.solve(&v); + }) + }); } fn cholesky_solve_100x100(bh: &mut criterion::Criterion) { @@ -51,9 +61,11 @@ fn cholesky_solve_100x100(bh: &mut criterion::Criterion) { let v = DVector::::new_random(100); let chol = Cholesky::new(m.clone()).unwrap(); - bh.bench_function("cholesky_solve_100x100", move |bh| bh.iter(|| { - let _ = chol.solve(&v); - })); + bh.bench_function("cholesky_solve_100x100", move |bh| { + bh.iter(|| { + let _ = chol.solve(&v); + }) + }); } fn cholesky_solve_500x500(bh: &mut criterion::Criterion) { @@ -62,20 +74,23 @@ fn cholesky_solve_500x500(bh: &mut criterion::Criterion) { let v = DVector::::new_random(500); let chol = Cholesky::new(m.clone()).unwrap(); - bh.bench_function("cholesky_solve_500x500", move |bh| bh.iter(|| { - let _ = chol.solve(&v); - })); + bh.bench_function("cholesky_solve_500x500", move |bh| { + bh.iter(|| { + let _ = chol.solve(&v); + }) + }); } - fn cholesky_inverse_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let m = &m * m.transpose(); let chol = Cholesky::new(m.clone()).unwrap(); - bh.bench_function("cholesky_inverse_10x10", move |bh| bh.iter(|| { - let _ = chol.inverse(); - })); + bh.bench_function("cholesky_inverse_10x10", move |bh| { + bh.iter(|| { + let _ = chol.inverse(); + }) + }); } fn cholesky_inverse_100x100(bh: &mut criterion::Criterion) { @@ -83,9 +98,11 @@ fn cholesky_inverse_100x100(bh: &mut criterion::Criterion) { let m = &m * m.transpose(); let chol = Cholesky::new(m.clone()).unwrap(); - bh.bench_function("cholesky_inverse_100x100", move |bh| bh.iter(|| { - let _ = chol.inverse(); - })); + bh.bench_function("cholesky_inverse_100x100", move |bh| { + bh.iter(|| { + let _ = chol.inverse(); + }) + }); } fn cholesky_inverse_500x500(bh: &mut criterion::Criterion) { @@ -93,12 +110,15 @@ fn cholesky_inverse_500x500(bh: &mut criterion::Criterion) { let m = &m * m.transpose(); let chol = Cholesky::new(m.clone()).unwrap(); - bh.bench_function("cholesky_inverse_500x500", move |bh| bh.iter(|| { - let _ = chol.inverse(); - })); + bh.bench_function("cholesky_inverse_500x500", move |bh| { + bh.iter(|| { + let _ = chol.inverse(); + }) + }); } -criterion_group!(cholesky, +criterion_group!( + cholesky, cholesky_100x100, cholesky_500x500, cholesky_decompose_unpack_100x100, @@ -109,4 +129,4 @@ criterion_group!(cholesky, cholesky_inverse_10x10, cholesky_inverse_100x100, cholesky_inverse_500x500 -); \ No newline at end of file +); diff --git a/benches/linalg/full_piv_lu.rs b/benches/linalg/full_piv_lu.rs index 6c7b1fa6..dfd176da 100644 --- a/benches/linalg/full_piv_lu.rs +++ b/benches/linalg/full_piv_lu.rs @@ -3,103 +3,127 @@ use na::{DMatrix, DVector, FullPivLU}; // Without unpack. fn full_piv_lu_decompose_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); - bh.bench_function("full_piv_lu_decompose_10x10", move |bh| bh.iter(|| test::black_box(FullPivLU::new(m.clone())))); + bh.bench_function("full_piv_lu_decompose_10x10", move |bh| { + bh.iter(|| test::black_box(FullPivLU::new(m.clone()))) + }); } fn full_piv_lu_decompose_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); - bh.bench_function("full_piv_lu_decompose_100x100", move |bh| bh.iter(|| test::black_box(FullPivLU::new(m.clone())))); + bh.bench_function("full_piv_lu_decompose_100x100", move |bh| { + bh.iter(|| test::black_box(FullPivLU::new(m.clone()))) + }); } fn full_piv_lu_decompose_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); - bh.bench_function("full_piv_lu_decompose_500x500", move |bh| bh.iter(|| test::black_box(FullPivLU::new(m.clone())))); + bh.bench_function("full_piv_lu_decompose_500x500", move |bh| { + bh.iter(|| test::black_box(FullPivLU::new(m.clone()))) + }); } fn full_piv_lu_solve_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let lu = FullPivLU::new(m.clone()); - bh.bench_function("full_piv_lu_solve_10x10", move |bh| bh.iter(|| { - let mut b = DVector::::from_element(10, 1.0); - lu.solve(&mut b); - })); + bh.bench_function("full_piv_lu_solve_10x10", move |bh| { + bh.iter(|| { + let mut b = DVector::::from_element(10, 1.0); + lu.solve(&mut b); + }) + }); } fn full_piv_lu_solve_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let lu = FullPivLU::new(m.clone()); - bh.bench_function("full_piv_lu_solve_100x100", move |bh| bh.iter(|| { - let mut b = DVector::::from_element(100, 1.0); - lu.solve(&mut b); - })); + bh.bench_function("full_piv_lu_solve_100x100", move |bh| { + bh.iter(|| { + let mut b = DVector::::from_element(100, 1.0); + lu.solve(&mut b); + }) + }); } fn full_piv_lu_solve_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let lu = FullPivLU::new(m.clone()); - bh.bench_function("full_piv_lu_solve_500x500", move |bh| bh.iter(|| { - let mut b = DVector::::from_element(500, 1.0); - lu.solve(&mut b); - })); + bh.bench_function("full_piv_lu_solve_500x500", move |bh| { + bh.iter(|| { + let mut b = DVector::::from_element(500, 1.0); + lu.solve(&mut b); + }) + }); } fn full_piv_lu_inverse_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let lu = FullPivLU::new(m.clone()); - bh.bench_function("full_piv_lu_inverse_10x10", move |bh| bh.iter(|| test::black_box(lu.try_inverse()))); + bh.bench_function("full_piv_lu_inverse_10x10", move |bh| { + bh.iter(|| test::black_box(lu.try_inverse())) + }); } fn full_piv_lu_inverse_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let lu = FullPivLU::new(m.clone()); - bh.bench_function("full_piv_lu_inverse_100x100", move |bh| bh.iter(|| test::black_box(lu.try_inverse()))); + bh.bench_function("full_piv_lu_inverse_100x100", move |bh| { + bh.iter(|| test::black_box(lu.try_inverse())) + }); } fn full_piv_lu_inverse_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let lu = FullPivLU::new(m.clone()); - bh.bench_function("full_piv_lu_inverse_500x500", move |bh| bh.iter(|| test::black_box(lu.try_inverse()))); + bh.bench_function("full_piv_lu_inverse_500x500", move |bh| { + bh.iter(|| test::black_box(lu.try_inverse())) + }); } fn full_piv_lu_determinant_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let lu = FullPivLU::new(m.clone()); - bh.bench_function("full_piv_lu_determinant_10x10", move |bh| bh.iter(|| test::black_box(lu.determinant()))); + bh.bench_function("full_piv_lu_determinant_10x10", move |bh| { + bh.iter(|| test::black_box(lu.determinant())) + }); } - fn full_piv_lu_determinant_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let lu = FullPivLU::new(m.clone()); - bh.bench_function("full_piv_lu_determinant_100x100", move |bh| bh.iter(|| test::black_box(lu.determinant()))); + bh.bench_function("full_piv_lu_determinant_100x100", move |bh| { + bh.iter(|| test::black_box(lu.determinant())) + }); } fn full_piv_lu_determinant_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let lu = FullPivLU::new(m.clone()); - bh.bench_function("full_piv_lu_determinant_500x500", move |bh| bh.iter(|| test::black_box(lu.determinant()))); + bh.bench_function("full_piv_lu_determinant_500x500", move |bh| { + bh.iter(|| test::black_box(lu.determinant())) + }); } -criterion_group!(full_piv_lu, +criterion_group!( + full_piv_lu, full_piv_lu_decompose_10x10, full_piv_lu_decompose_100x100, -// full_piv_lu_decompose_500x500, + // full_piv_lu_decompose_500x500, full_piv_lu_solve_10x10, full_piv_lu_solve_100x100, -// full_piv_lu_solve_500x500, + // full_piv_lu_solve_500x500, full_piv_lu_inverse_10x10, full_piv_lu_inverse_100x100, -// full_piv_lu_inverse_500x500, + // full_piv_lu_inverse_500x500, full_piv_lu_determinant_10x10, full_piv_lu_determinant_100x100, -// full_piv_lu_determinant_500x500 -); \ No newline at end of file + // full_piv_lu_determinant_500x500 +); diff --git a/benches/linalg/hessenberg.rs b/benches/linalg/hessenberg.rs index 3340c3ef..a989616c 100644 --- a/benches/linalg/hessenberg.rs +++ b/benches/linalg/hessenberg.rs @@ -6,55 +6,70 @@ mod macros; // Without unpack. fn hessenberg_decompose_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.bench_function("hessenberg_decompose_4x4", move |bh| bh.iter(|| test::black_box(Hessenberg::new(m.clone())))); + bh.bench_function("hessenberg_decompose_4x4", move |bh| { + bh.iter(|| test::black_box(Hessenberg::new(m.clone()))) + }); } fn hessenberg_decompose_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); - bh.bench_function("hessenberg_decompose_100x100", move |bh| bh.iter(|| test::black_box(Hessenberg::new(m.clone())))); + bh.bench_function("hessenberg_decompose_100x100", move |bh| { + bh.iter(|| test::black_box(Hessenberg::new(m.clone()))) + }); } fn hessenberg_decompose_200x200(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(200, 200); - bh.bench_function("hessenberg_decompose_200x200", move |bh| bh.iter(|| test::black_box(Hessenberg::new(m.clone())))); + bh.bench_function("hessenberg_decompose_200x200", move |bh| { + bh.iter(|| test::black_box(Hessenberg::new(m.clone()))) + }); } fn hessenberg_decompose_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); - bh.bench_function("hessenberg_decompose_500x500", move |bh| bh.iter(|| test::black_box(Hessenberg::new(m.clone())))); + bh.bench_function("hessenberg_decompose_500x500", move |bh| { + bh.iter(|| test::black_box(Hessenberg::new(m.clone()))) + }); } // With unpack. fn hessenberg_decompose_unpack_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); - bh.bench_function("hessenberg_decompose_unpack_100x100", move |bh| bh.iter(|| { - let hess = Hessenberg::new(m.clone()); - let _ = hess.unpack(); - })); + bh.bench_function("hessenberg_decompose_unpack_100x100", move |bh| { + bh.iter(|| { + let hess = Hessenberg::new(m.clone()); + let _ = hess.unpack(); + }) + }); } fn hessenberg_decompose_unpack_200x200(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(200, 200); - bh.bench_function("hessenberg_decompose_unpack_200x200", move |bh| bh.iter(|| { - let hess = Hessenberg::new(m.clone()); - let _ = hess.unpack(); - })); + bh.bench_function("hessenberg_decompose_unpack_200x200", move |bh| { + bh.iter(|| { + let hess = Hessenberg::new(m.clone()); + let _ = hess.unpack(); + }) + }); } fn hessenberg_decompose_unpack_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); - bh.bench_function("hessenberg_decompose_unpack_500x500", move |bh| bh.iter(|| { - let hess = Hessenberg::new(m.clone()); - let _ = hess.unpack(); - })); + bh.bench_function("hessenberg_decompose_unpack_500x500", move |bh| { + bh.iter(|| { + let hess = Hessenberg::new(m.clone()); + let _ = hess.unpack(); + }) + }); } -criterion_group!(hessenberg, +criterion_group!( + hessenberg, hessenberg_decompose_4x4, hessenberg_decompose_100x100, hessenberg_decompose_200x200, -// hessenberg_decompose_500x500, + // hessenberg_decompose_500x500, hessenberg_decompose_unpack_100x100, hessenberg_decompose_unpack_200x200, -// hessenberg_decompose_unpack_500x500 -); \ No newline at end of file + // hessenberg_decompose_unpack_500x500 +); diff --git a/benches/linalg/lu.rs b/benches/linalg/lu.rs index e37cfe75..c42cd499 100644 --- a/benches/linalg/lu.rs +++ b/benches/linalg/lu.rs @@ -3,82 +3,104 @@ use na::{DMatrix, DVector, LU}; // Without unpack. fn lu_decompose_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); - bh.bench_function("lu_decompose_10x10", move |bh| bh.iter(|| test::black_box(LU::new(m.clone())))); + bh.bench_function("lu_decompose_10x10", move |bh| { + bh.iter(|| test::black_box(LU::new(m.clone()))) + }); } fn lu_decompose_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); - bh.bench_function("lu_decompose_100x100", move |bh| bh.iter(|| test::black_box(LU::new(m.clone())))); + bh.bench_function("lu_decompose_100x100", move |bh| { + bh.iter(|| test::black_box(LU::new(m.clone()))) + }); } fn lu_decompose_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); - bh.bench_function("lu_decompose_500x500", move |bh| bh.iter(|| test::black_box(LU::new(m.clone())))); + bh.bench_function("lu_decompose_500x500", move |bh| { + bh.iter(|| test::black_box(LU::new(m.clone()))) + }); } fn lu_solve_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let lu = LU::new(m.clone()); - bh.bench_function("lu_solve_10x10", move |bh| bh.iter(|| { - let mut b = DVector::::from_element(10, 1.0); - lu.solve(&mut b); - })); + bh.bench_function("lu_solve_10x10", move |bh| { + bh.iter(|| { + let mut b = DVector::::from_element(10, 1.0); + lu.solve(&mut b); + }) + }); } fn lu_solve_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let lu = LU::new(m.clone()); - bh.bench_function("lu_solve_100x100", move |bh| bh.iter(|| { - let mut b = DVector::::from_element(100, 1.0); - lu.solve(&mut b); - })); + bh.bench_function("lu_solve_100x100", move |bh| { + bh.iter(|| { + let mut b = DVector::::from_element(100, 1.0); + lu.solve(&mut b); + }) + }); } fn lu_solve_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let lu = LU::new(m.clone()); - bh.bench_function("", move |bh| bh.iter(|| { - let mut b = DVector::::from_element(500, 1.0); - lu.solve(&mut b); - })); + bh.bench_function("", move |bh| { + bh.iter(|| { + let mut b = DVector::::from_element(500, 1.0); + lu.solve(&mut b); + }) + }); } fn lu_inverse_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let lu = LU::new(m.clone()); - bh.bench_function("lu_inverse_10x10", move |bh| bh.iter(|| test::black_box(lu.try_inverse()))); + bh.bench_function("lu_inverse_10x10", move |bh| { + bh.iter(|| test::black_box(lu.try_inverse())) + }); } fn lu_inverse_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let lu = LU::new(m.clone()); - bh.bench_function("lu_inverse_100x100", move |bh| bh.iter(|| test::black_box(lu.try_inverse()))); + bh.bench_function("lu_inverse_100x100", move |bh| { + bh.iter(|| test::black_box(lu.try_inverse())) + }); } fn lu_inverse_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let lu = LU::new(m.clone()); - bh.bench_function("lu_inverse_500x500", move |bh| bh.iter(|| test::black_box(lu.try_inverse()))); + bh.bench_function("lu_inverse_500x500", move |bh| { + bh.iter(|| test::black_box(lu.try_inverse())) + }); } fn lu_determinant_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let lu = LU::new(m.clone()); - bh.bench_function("lu_determinant_10x10", move |bh| bh.iter(|| test::black_box(lu.determinant()))); + bh.bench_function("lu_determinant_10x10", move |bh| { + bh.iter(|| test::black_box(lu.determinant())) + }); } fn lu_determinant_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let lu = LU::new(m.clone()); - bh.bench_function("lu_determinant_100x100", move |bh| bh.iter(|| test::black_box(lu.determinant()))); + bh.bench_function("lu_determinant_100x100", move |bh| { + bh.iter(|| test::black_box(lu.determinant())) + }); } fn lu_determinant_500x500(bh: &mut criterion::Criterion) { @@ -88,15 +110,16 @@ fn lu_determinant_500x500(bh: &mut criterion::Criterion) { bh.bench_function("", move |bh| bh.iter(|| test::black_box(lu.determinant()))); } -criterion_group!(lu, +criterion_group!( + lu, lu_decompose_10x10, lu_decompose_100x100, -// lu_decompose_500x500, + // lu_decompose_500x500, lu_solve_10x10, lu_solve_100x100, lu_inverse_10x10, lu_inverse_100x100, -// lu_inverse_500x500, + // lu_inverse_500x500, lu_determinant_10x10, lu_determinant_100x100 -); \ No newline at end of file +); diff --git a/benches/linalg/mod.rs b/benches/linalg/mod.rs index a6e7a8ef..cbd4df4a 100644 --- a/benches/linalg/mod.rs +++ b/benches/linalg/mod.rs @@ -19,4 +19,4 @@ mod schur; mod solve; mod svd; mod symmetric_eigen; -// mod eigen; \ No newline at end of file +// mod eigen; diff --git a/benches/linalg/qr.rs b/benches/linalg/qr.rs index 8283c5e9..d896f978 100644 --- a/benches/linalg/qr.rs +++ b/benches/linalg/qr.rs @@ -6,128 +6,158 @@ mod macros; // Without unpack. fn qr_decompose_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); - bh.bench_function("qr_decompose_100x100", move |bh| bh.iter(|| test::black_box(QR::new(m.clone())))); + bh.bench_function("qr_decompose_100x100", move |bh| { + bh.iter(|| test::black_box(QR::new(m.clone()))) + }); } fn qr_decompose_100x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 500); - bh.bench_function("qr_decompose_100x500", move |bh| bh.iter(|| test::black_box(QR::new(m.clone())))); + bh.bench_function("qr_decompose_100x500", move |bh| { + bh.iter(|| test::black_box(QR::new(m.clone()))) + }); } fn qr_decompose_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.bench_function("qr_decompose_4x4", move |bh| bh.iter(|| test::black_box(QR::new(m.clone())))); + bh.bench_function("qr_decompose_4x4", move |bh| { + bh.iter(|| test::black_box(QR::new(m.clone()))) + }); } fn qr_decompose_500x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 100); - bh.bench_function("qr_decompose_500x100", move |bh| bh.iter(|| test::black_box(QR::new(m.clone())))); + bh.bench_function("qr_decompose_500x100", move |bh| { + bh.iter(|| test::black_box(QR::new(m.clone()))) + }); } fn qr_decompose_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); - bh.bench_function("qr_decompose_500x500", move |bh| bh.iter(|| test::black_box(QR::new(m.clone())))); + bh.bench_function("qr_decompose_500x500", move |bh| { + bh.iter(|| test::black_box(QR::new(m.clone()))) + }); } // With unpack. fn qr_decompose_unpack_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); - bh.bench_function("qr_decompose_unpack_100x100", move |bh| bh.iter(|| { - let qr = QR::new(m.clone()); - let _ = qr.unpack(); - })); + bh.bench_function("qr_decompose_unpack_100x100", move |bh| { + bh.iter(|| { + let qr = QR::new(m.clone()); + let _ = qr.unpack(); + }) + }); } fn qr_decompose_unpack_100x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 500); - bh.bench_function("qr_decompose_unpack_100x500", move |bh| bh.iter(|| { - let qr = QR::new(m.clone()); - let _ = qr.unpack(); - })); + bh.bench_function("qr_decompose_unpack_100x500", move |bh| { + bh.iter(|| { + let qr = QR::new(m.clone()); + let _ = qr.unpack(); + }) + }); } fn qr_decompose_unpack_500x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 100); - bh.bench_function("qr_decompose_unpack_500x100", move |bh| bh.iter(|| { - let qr = QR::new(m.clone()); - let _ = qr.unpack(); - })); + bh.bench_function("qr_decompose_unpack_500x100", move |bh| { + bh.iter(|| { + let qr = QR::new(m.clone()); + let _ = qr.unpack(); + }) + }); } fn qr_decompose_unpack_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); - bh.bench_function("qr_decompose_unpack_500x500", move |bh| bh.iter(|| { - let qr = QR::new(m.clone()); - let _ = qr.unpack(); - })); + bh.bench_function("qr_decompose_unpack_500x500", move |bh| { + bh.iter(|| { + let qr = QR::new(m.clone()); + let _ = qr.unpack(); + }) + }); } fn qr_solve_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let qr = QR::new(m.clone()); - bh.bench_function("qr_solve_10x10", move |bh| bh.iter(|| { - let mut b = DVector::::from_element(10, 1.0); - qr.solve(&mut b); - })); + bh.bench_function("qr_solve_10x10", move |bh| { + bh.iter(|| { + let mut b = DVector::::from_element(10, 1.0); + qr.solve(&mut b); + }) + }); } fn qr_solve_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let qr = QR::new(m.clone()); - bh.bench_function("qr_solve_100x100", move |bh| bh.iter(|| { - let mut b = DVector::::from_element(100, 1.0); - qr.solve(&mut b); - })); + bh.bench_function("qr_solve_100x100", move |bh| { + bh.iter(|| { + let mut b = DVector::::from_element(100, 1.0); + qr.solve(&mut b); + }) + }); } fn qr_solve_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let qr = QR::new(m.clone()); - bh.bench_function("qr_solve_500x500", move |bh| bh.iter(|| { - let mut b = DVector::::from_element(500, 1.0); - qr.solve(&mut b); - })); + bh.bench_function("qr_solve_500x500", move |bh| { + bh.iter(|| { + let mut b = DVector::::from_element(500, 1.0); + qr.solve(&mut b); + }) + }); } fn qr_inverse_10x10(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(10, 10); let qr = QR::new(m.clone()); - bh.bench_function("qr_inverse_10x10", move |bh| bh.iter(|| test::black_box(qr.try_inverse()))); + bh.bench_function("qr_inverse_10x10", move |bh| { + bh.iter(|| test::black_box(qr.try_inverse())) + }); } fn qr_inverse_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let qr = QR::new(m.clone()); - bh.bench_function("qr_inverse_100x100", move |bh| bh.iter(|| test::black_box(qr.try_inverse()))); + bh.bench_function("qr_inverse_100x100", move |bh| { + bh.iter(|| test::black_box(qr.try_inverse())) + }); } fn qr_inverse_500x500(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(500, 500); let qr = QR::new(m.clone()); - bh.bench_function("qr_inverse_500x500", move |bh| bh.iter(|| test::black_box(qr.try_inverse()))); + bh.bench_function("qr_inverse_500x500", move |bh| { + bh.iter(|| test::black_box(qr.try_inverse())) + }); } - -criterion_group!(qr, +criterion_group!( + qr, qr_decompose_100x100, qr_decompose_100x500, qr_decompose_4x4, qr_decompose_500x100, -// qr_decompose_500x500, + // qr_decompose_500x500, qr_decompose_unpack_100x100, qr_decompose_unpack_100x500, qr_decompose_unpack_500x100, -// qr_decompose_unpack_500x500, + // qr_decompose_unpack_500x500, qr_solve_10x10, qr_solve_100x100, -// qr_solve_500x500, + // qr_solve_500x500, qr_inverse_10x10, qr_inverse_100x100, -// qr_inverse_500x500 -); \ No newline at end of file + // qr_inverse_500x500 +); diff --git a/benches/linalg/schur.rs b/benches/linalg/schur.rs index ffabc539..e4193a25 100644 --- a/benches/linalg/schur.rs +++ b/benches/linalg/schur.rs @@ -2,45 +2,62 @@ use na::{Matrix4, Schur}; fn schur_decompose_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.bench_function("schur_decompose_4x4", move |bh| bh.iter(|| test::black_box(Schur::new(m.clone())))); + bh.bench_function("schur_decompose_4x4", move |bh| { + bh.iter(|| test::black_box(Schur::new(m.clone()))) + }); } fn schur_decompose_10x10(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(10, 10); - bh.bench_function("schur_decompose_10x10", move |bh| bh.iter(|| test::black_box(Schur::new(m.clone())))); + bh.bench_function("schur_decompose_10x10", move |bh| { + bh.iter(|| test::black_box(Schur::new(m.clone()))) + }); } fn schur_decompose_100x100(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(100, 100); - bh.bench_function("schur_decompose_100x100", move |bh| bh.iter(|| test::black_box(Schur::new(m.clone())))); + bh.bench_function("schur_decompose_100x100", move |bh| { + bh.iter(|| test::black_box(Schur::new(m.clone()))) + }); } fn schur_decompose_200x200(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(200, 200); - bh.bench_function("schur_decompose_200x200", move |bh| bh.iter(|| test::black_box(Schur::new(m.clone())))); + bh.bench_function("schur_decompose_200x200", move |bh| { + bh.iter(|| test::black_box(Schur::new(m.clone()))) + }); } fn eigenvalues_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.bench_function("eigenvalues_4x4", move |bh| bh.iter(|| test::black_box(m.complex_eigenvalues()))); + bh.bench_function("eigenvalues_4x4", move |bh| { + bh.iter(|| test::black_box(m.complex_eigenvalues())) + }); } fn eigenvalues_10x10(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(10, 10); - bh.bench_function("eigenvalues_10x10", move |bh| bh.iter(|| test::black_box(m.complex_eigenvalues()))); + bh.bench_function("eigenvalues_10x10", move |bh| { + bh.iter(|| test::black_box(m.complex_eigenvalues())) + }); } fn eigenvalues_100x100(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(100, 100); - bh.bench_function("eigenvalues_100x100", move |bh| bh.iter(|| test::black_box(m.complex_eigenvalues()))); + bh.bench_function("eigenvalues_100x100", move |bh| { + bh.iter(|| test::black_box(m.complex_eigenvalues())) + }); } fn eigenvalues_200x200(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(200, 200); - bh.bench_function("eigenvalues_200x200", move |bh| bh.iter(|| test::black_box(m.complex_eigenvalues()))); + bh.bench_function("eigenvalues_200x200", move |bh| { + bh.iter(|| test::black_box(m.complex_eigenvalues())) + }); } -criterion_group!(schur, +criterion_group!( + schur, schur_decompose_4x4, schur_decompose_10x10, schur_decompose_100x100, @@ -49,4 +66,4 @@ criterion_group!(schur, eigenvalues_10x10, eigenvalues_100x100, eigenvalues_200x200 -); \ No newline at end of file +); diff --git a/benches/linalg/solve.rs b/benches/linalg/solve.rs index 51c6db59..82545cd1 100644 --- a/benches/linalg/solve.rs +++ b/benches/linalg/solve.rs @@ -4,76 +4,92 @@ fn solve_l_triangular_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let v = DVector::::new_random(100); - bh.bench_function("solve_l_triangular_100x100", move |bh| bh.iter(|| { - let _ = m.solve_lower_triangular(&v); - })); + bh.bench_function("solve_l_triangular_100x100", move |bh| { + bh.iter(|| { + let _ = m.solve_lower_triangular(&v); + }) + }); } fn solve_l_triangular_1000x1000(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(1000, 1000); let v = DVector::::new_random(1000); - bh.bench_function("solve_l_triangular_1000x1000", move |bh| bh.iter(|| { - let _ = m.solve_lower_triangular(&v); - })); + bh.bench_function("solve_l_triangular_1000x1000", move |bh| { + bh.iter(|| { + let _ = m.solve_lower_triangular(&v); + }) + }); } fn tr_solve_l_triangular_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let v = DVector::::new_random(100); - bh.bench_function("tr_solve_l_triangular_100x100", move |bh| bh.iter(|| { - let _ = m.tr_solve_lower_triangular(&v); - })); + bh.bench_function("tr_solve_l_triangular_100x100", move |bh| { + bh.iter(|| { + let _ = m.tr_solve_lower_triangular(&v); + }) + }); } fn tr_solve_l_triangular_1000x1000(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(1000, 1000); let v = DVector::::new_random(1000); - bh.bench_function("tr_solve_l_triangular_1000x1000", move |bh| bh.iter(|| { - let _ = m.tr_solve_lower_triangular(&v); - })); + bh.bench_function("tr_solve_l_triangular_1000x1000", move |bh| { + bh.iter(|| { + let _ = m.tr_solve_lower_triangular(&v); + }) + }); } fn solve_u_triangular_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let v = DVector::::new_random(100); - bh.bench_function("solve_u_triangular_100x100", move |bh| bh.iter(|| { - let _ = m.solve_upper_triangular(&v); - })); + bh.bench_function("solve_u_triangular_100x100", move |bh| { + bh.iter(|| { + let _ = m.solve_upper_triangular(&v); + }) + }); } fn solve_u_triangular_1000x1000(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(1000, 1000); let v = DVector::::new_random(1000); - bh.bench_function("solve_u_triangular_1000x1000", move |bh| bh.iter(|| { - let _ = m.solve_upper_triangular(&v); - })); + bh.bench_function("solve_u_triangular_1000x1000", move |bh| { + bh.iter(|| { + let _ = m.solve_upper_triangular(&v); + }) + }); } fn tr_solve_u_triangular_100x100(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(100, 100); let v = DVector::::new_random(100); - bh.bench_function("tr_solve_u_triangular_100x100", move |bh| bh.iter(|| { - let _ = m.tr_solve_upper_triangular(&v); - })); + bh.bench_function("tr_solve_u_triangular_100x100", move |bh| { + bh.iter(|| { + let _ = m.tr_solve_upper_triangular(&v); + }) + }); } fn tr_solve_u_triangular_1000x1000(bh: &mut criterion::Criterion) { let m = DMatrix::::new_random(1000, 1000); let v = DVector::::new_random(1000); - bh.bench_function("tr_solve_u_triangular_1000x1000", move |bh| bh.iter(|| { - let _ = m.tr_solve_upper_triangular(&v); - })); + bh.bench_function("tr_solve_u_triangular_1000x1000", move |bh| { + bh.iter(|| { + let _ = m.tr_solve_upper_triangular(&v); + }) + }); } - -criterion_group!(solve, +criterion_group!( + solve, solve_l_triangular_100x100, solve_l_triangular_1000x1000, tr_solve_l_triangular_100x100, @@ -82,4 +98,4 @@ criterion_group!(solve, solve_u_triangular_1000x1000, tr_solve_u_triangular_100x100, tr_solve_u_triangular_1000x1000 -); \ No newline at end of file +); diff --git a/benches/linalg/svd.rs b/benches/linalg/svd.rs index 6804147c..aec18fd8 100644 --- a/benches/linalg/svd.rs +++ b/benches/linalg/svd.rs @@ -2,86 +2,118 @@ use na::{Matrix4, SVD}; fn svd_decompose_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.bench_function("svd_decompose_4x4", move |bh| bh.iter(|| test::black_box(SVD::new(m.clone(), true, true)))); + bh.bench_function("svd_decompose_4x4", move |bh| { + bh.iter(|| test::black_box(SVD::new(m.clone(), true, true))) + }); } fn svd_decompose_10x10(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(10, 10); - bh.bench_function("svd_decompose_10x10", move |bh| bh.iter(|| test::black_box(SVD::new(m.clone(), true, true)))); + bh.bench_function("svd_decompose_10x10", move |bh| { + bh.iter(|| test::black_box(SVD::new(m.clone(), true, true))) + }); } fn svd_decompose_100x100(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(100, 100); - bh.bench_function("svd_decompose_100x100", move |bh| bh.iter(|| test::black_box(SVD::new(m.clone(), true, true)))); + bh.bench_function("svd_decompose_100x100", move |bh| { + bh.iter(|| test::black_box(SVD::new(m.clone(), true, true))) + }); } fn svd_decompose_200x200(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(200, 200); - bh.bench_function("svd_decompose_200x200", move |bh| bh.iter(|| test::black_box(SVD::new(m.clone(), true, true)))); + bh.bench_function("svd_decompose_200x200", move |bh| { + bh.iter(|| test::black_box(SVD::new(m.clone(), true, true))) + }); } fn rank_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.bench_function("rank_4x4", move |bh| bh.iter(|| test::black_box(m.rank(1.0e-10)))); + bh.bench_function("rank_4x4", move |bh| { + bh.iter(|| test::black_box(m.rank(1.0e-10))) + }); } fn rank_10x10(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(10, 10); - bh.bench_function("rank_10x10", move |bh| bh.iter(|| test::black_box(m.rank(1.0e-10)))); + bh.bench_function("rank_10x10", move |bh| { + bh.iter(|| test::black_box(m.rank(1.0e-10))) + }); } fn rank_100x100(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(100, 100); - bh.bench_function("rank_100x100", move |bh| bh.iter(|| test::black_box(m.rank(1.0e-10)))); + bh.bench_function("rank_100x100", move |bh| { + bh.iter(|| test::black_box(m.rank(1.0e-10))) + }); } fn rank_200x200(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(200, 200); - bh.bench_function("rank_200x200", move |bh| bh.iter(|| test::black_box(m.rank(1.0e-10)))); + bh.bench_function("rank_200x200", move |bh| { + bh.iter(|| test::black_box(m.rank(1.0e-10))) + }); } fn singular_values_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.bench_function("singular_values_4x4", move |bh| bh.iter(|| test::black_box(m.singular_values()))); + bh.bench_function("singular_values_4x4", move |bh| { + bh.iter(|| test::black_box(m.singular_values())) + }); } fn singular_values_10x10(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(10, 10); - bh.bench_function("singular_values_10x10", move |bh| bh.iter(|| test::black_box(m.singular_values()))); + bh.bench_function("singular_values_10x10", move |bh| { + bh.iter(|| test::black_box(m.singular_values())) + }); } fn singular_values_100x100(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(100, 100); - bh.bench_function("singular_values_100x100", move |bh| bh.iter(|| test::black_box(m.singular_values()))); + bh.bench_function("singular_values_100x100", move |bh| { + bh.iter(|| test::black_box(m.singular_values())) + }); } fn singular_values_200x200(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(200, 200); - bh.bench_function("singular_values_200x200", move |bh| bh.iter(|| test::black_box(m.singular_values()))); + bh.bench_function("singular_values_200x200", move |bh| { + bh.iter(|| test::black_box(m.singular_values())) + }); } fn pseudo_inverse_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.bench_function("pseudo_inverse_4x4", move |bh| bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10)))); + bh.bench_function("pseudo_inverse_4x4", move |bh| { + bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10))) + }); } fn pseudo_inverse_10x10(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(10, 10); - bh.bench_function("pseudo_inverse_10x10", move |bh| bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10)))); + bh.bench_function("pseudo_inverse_10x10", move |bh| { + bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10))) + }); } fn pseudo_inverse_100x100(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(100, 100); - bh.bench_function("pseudo_inverse_100x100", move |bh| bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10)))); + bh.bench_function("pseudo_inverse_100x100", move |bh| { + bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10))) + }); } fn pseudo_inverse_200x200(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(200, 200); - bh.bench_function("pseudo_inverse_200x200", move |bh| bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10)))); + bh.bench_function("pseudo_inverse_200x200", move |bh| { + bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10))) + }); } - -criterion_group!(svd, +criterion_group!( + svd, svd_decompose_4x4, svd_decompose_10x10, svd_decompose_100x100, @@ -98,4 +130,4 @@ criterion_group!(svd, pseudo_inverse_10x10, pseudo_inverse_100x100, pseudo_inverse_200x200 -); \ No newline at end of file +); diff --git a/benches/linalg/symmetric_eigen.rs b/benches/linalg/symmetric_eigen.rs index 822ea30e..3b52ba5c 100644 --- a/benches/linalg/symmetric_eigen.rs +++ b/benches/linalg/symmetric_eigen.rs @@ -2,25 +2,34 @@ use na::{Matrix4, SymmetricEigen}; fn symmetric_eigen_decompose_4x4(bh: &mut criterion::Criterion) { let m = Matrix4::::new_random(); - bh.bench_function("symmetric_eigen_decompose_4x4", move |bh| bh.iter(|| test::black_box(SymmetricEigen::new(m.clone())))); + bh.bench_function("symmetric_eigen_decompose_4x4", move |bh| { + bh.iter(|| test::black_box(SymmetricEigen::new(m.clone()))) + }); } fn symmetric_eigen_decompose_10x10(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(10, 10); - bh.bench_function("symmetric_eigen_decompose_10x10", move |bh| bh.iter(|| test::black_box(SymmetricEigen::new(m.clone())))); + bh.bench_function("symmetric_eigen_decompose_10x10", move |bh| { + bh.iter(|| test::black_box(SymmetricEigen::new(m.clone()))) + }); } fn symmetric_eigen_decompose_100x100(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(100, 100); - bh.bench_function("symmetric_eigen_decompose_100x100", move |bh| bh.iter(|| test::black_box(SymmetricEigen::new(m.clone())))); + bh.bench_function("symmetric_eigen_decompose_100x100", move |bh| { + bh.iter(|| test::black_box(SymmetricEigen::new(m.clone()))) + }); } fn symmetric_eigen_decompose_200x200(bh: &mut criterion::Criterion) { let m = crate::reproductible_dmatrix(200, 200); - bh.bench_function("symmetric_eigen_decompose_200x200", move |bh| bh.iter(|| test::black_box(SymmetricEigen::new(m.clone())))); + bh.bench_function("symmetric_eigen_decompose_200x200", move |bh| { + bh.iter(|| test::black_box(SymmetricEigen::new(m.clone()))) + }); } -criterion_group!(symmetric_eigen, +criterion_group!( + symmetric_eigen, symmetric_eigen_decompose_4x4, symmetric_eigen_decompose_10x10, symmetric_eigen_decompose_100x100, diff --git a/examples/dimensional_genericity.rs b/examples/dimensional_genericity.rs index d13052df..00c40f14 100644 --- a/examples/dimensional_genericity.rs +++ b/examples/dimensional_genericity.rs @@ -20,7 +20,9 @@ where /// Reflects a 2D vector wrt. the 2D line with normal `plane_normal`. fn reflect_wrt_hyperplane2(plane_normal: &Unit>, vector: &Vector2) -> Vector2 -where N: RealField { +where + N: RealField, +{ let n = plane_normal.as_ref(); // Get the underlying Vector2 vector - n * (n.dot(vector) * na::convert(2.0)) } @@ -28,7 +30,9 @@ where N: RealField { /// Reflects a 3D vector wrt. the 3D plane with normal `plane_normal`. /// /!\ This is an exact replicate of `reflect_wrt_hyperplane2, but for 3D. fn reflect_wrt_hyperplane3(plane_normal: &Unit>, vector: &Vector3) -> Vector3 -where N: RealField { +where + N: RealField, +{ let n = plane_normal.as_ref(); // Get the underlying Vector3 vector - n * (n.dot(vector) * na::convert(2.0)) } diff --git a/nalgebra-glm/src/common.rs b/nalgebra-glm/src/common.rs index eda9f295..1a5c0c2a 100644 --- a/nalgebra-glm/src/common.rs +++ b/nalgebra-glm/src/common.rs @@ -1,6 +1,6 @@ +use core::mem; use na::{self, DefaultAllocator, RealField}; use num::FromPrimitive; -use core::mem; use crate::aliases::{TMat, TVec}; use crate::traits::{Alloc, Dimension, Number}; @@ -22,7 +22,9 @@ use crate::traits::{Alloc, Dimension, Number}; /// /// * [`sign`](fn.sign.html) pub fn abs(x: &TMat) -> TMat -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.abs() } @@ -44,7 +46,9 @@ where DefaultAllocator: Alloc { /// * [`round`](fn.round.html) /// * [`trunc`](fn.trunc.html) pub fn ceil(x: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.map(|x| x.ceil()) } @@ -94,7 +98,9 @@ pub fn clamp_scalar(x: N, min_val: N, max_val: N) -> N { /// * [`clamp_scalar`](fn.clamp_scalar.html) /// * [`clamp_vec`](fn.clamp_vec.html) pub fn clamp(x: &TVec, min_val: N, max_val: N) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.map(|x| na::clamp(x, min_val, max_val)) } @@ -167,7 +173,9 @@ pub fn float_bits_to_int(v: f32) -> i32 { /// * [`uint_bits_to_float`](fn.uint_bits_to_float.html) /// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html) pub fn float_bits_to_int_vec(v: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ v.map(float_bits_to_int) } @@ -202,7 +210,9 @@ pub fn float_bits_to_uint(v: f32) -> u32 { /// * [`uint_bits_to_float`](fn.uint_bits_to_float.html) /// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html) pub fn float_bits_to_uint_vec(v: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ v.map(float_bits_to_uint) } @@ -223,7 +233,9 @@ where DefaultAllocator: Alloc { /// * [`round`](fn.round.html) /// * [`trunc`](fn.trunc.html) pub fn floor(x: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.map(|x| x.floor()) } @@ -250,7 +262,9 @@ where DefaultAllocator: Alloc { /// * [`round`](fn.round.html) /// * [`trunc`](fn.trunc.html) pub fn fract(x: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.map(|x| x.fract()) } @@ -293,7 +307,9 @@ pub fn int_bits_to_float(v: i32) -> f32 { /// * [`uint_bits_to_float`](fn.uint_bits_to_float.html) /// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html) pub fn int_bits_to_float_vec(v: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ v.map(int_bits_to_float) } @@ -352,7 +368,9 @@ pub fn mix_scalar(x: N, y: N, a: N) -> N { /// * [`mix_scalar`](fn.mix_scalar.html) /// * [`mix_vec`](fn.mix_vec.html) pub fn mix(x: &TVec, y: &TVec, a: N) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x * (N::one() - a) + y * a } @@ -425,7 +443,9 @@ pub fn lerp_scalar(x: N, y: N, a: N) -> N { /// * [`lerp_scalar`](fn.lerp_scalar.html) /// * [`lerp_vec`](fn.lerp_vec.html) pub fn lerp(x: &TVec, y: &TVec, a: N) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ mix(x, y, a) } @@ -468,7 +488,9 @@ where /// /// * [`modf`](fn.modf.html) pub fn modf_vec(x: &TVec, y: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.zip_map(y, |x, y| x % y) } @@ -500,7 +522,9 @@ pub fn modf(x: N, i: N) -> N { /// * [`fract`](fn.fract.html) /// * [`trunc`](fn.trunc.html) pub fn round(x: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.map(|x| x.round()) } @@ -524,7 +548,9 @@ where DefaultAllocator: Alloc { /// * [`abs`](fn.abs.html) /// pub fn sign(x: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.map(|x| if x.is_zero() { N::zero() } else { x.signum() }) } @@ -550,13 +576,17 @@ pub fn step_scalar(edge: N, x: N) -> N { /// Returns 0.0 if `x[i] < edge`, otherwise it returns 1.0. pub fn step(edge: N, x: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.map(|x| step_scalar(edge, x)) } /// Returns 0.0 if `x[i] < edge[i]`, otherwise it returns 1.0. pub fn step_vec(edge: &TVec, x: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ edge.zip_map(x, step_scalar) } @@ -577,7 +607,9 @@ where DefaultAllocator: Alloc { /// * [`fract`](fn.fract.html) /// * [`round`](fn.round.html) pub fn trunc(x: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.map(|x| x.trunc()) } @@ -612,6 +644,8 @@ pub fn uint_bits_to_float_scalar(v: u32) -> f32 { /// * [`int_bits_to_float_vec`](fn.int_bits_to_float_vec.html) /// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html) pub fn uint_bits_to_float(v: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ v.map(uint_bits_to_float_scalar) } diff --git a/nalgebra-glm/src/exponential.rs b/nalgebra-glm/src/exponential.rs index fd54fb34..5830704a 100644 --- a/nalgebra-glm/src/exponential.rs +++ b/nalgebra-glm/src/exponential.rs @@ -1,6 +1,6 @@ use crate::aliases::TVec; -use na::{DefaultAllocator, RealField}; use crate::traits::{Alloc, Dimension}; +use na::{DefaultAllocator, RealField}; /// Component-wise exponential. /// @@ -8,7 +8,9 @@ use crate::traits::{Alloc, Dimension}; /// /// * [`exp2`](fn.exp2.html) pub fn exp(v: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ v.map(|x| x.exp()) } @@ -18,7 +20,9 @@ where DefaultAllocator: Alloc { /// /// * [`exp`](fn.exp.html) pub fn exp2(v: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ v.map(|x| x.exp2()) } @@ -28,7 +32,9 @@ where DefaultAllocator: Alloc { /// /// * [`sqrt`](fn.sqrt.html) pub fn inversesqrt(v: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ v.map(|x| N::one() / x.sqrt()) } @@ -38,7 +44,9 @@ where DefaultAllocator: Alloc { /// /// * [`log2`](fn.log2.html) pub fn log(v: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ v.map(|x| x.ln()) } @@ -48,13 +56,17 @@ where DefaultAllocator: Alloc { /// /// * [`log`](fn.log.html) pub fn log2(v: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ v.map(|x| x.log2()) } /// Component-wise power. pub fn pow(base: &TVec, exponent: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ base.zip_map(exponent, |b, e| b.powf(e)) } @@ -67,6 +79,8 @@ where DefaultAllocator: Alloc { /// * [`inversesqrt`](fn.inversesqrt.html) /// * [`pow`](fn.pow.html) pub fn sqrt(v: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ v.map(|x| x.sqrt()) } diff --git a/nalgebra-glm/src/ext/matrix_clip_space.rs b/nalgebra-glm/src/ext/matrix_clip_space.rs index 6b279024..260c5196 100644 --- a/nalgebra-glm/src/ext/matrix_clip_space.rs +++ b/nalgebra-glm/src/ext/matrix_clip_space.rs @@ -1,5 +1,5 @@ use crate::aliases::TMat4; -use na::{RealField}; +use na::RealField; //pub fn frustum(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { // unimplemented!() @@ -90,13 +90,20 @@ pub fn ortho_lh(left: N, right: N, bottom: N, top: N, znear: N, zf /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_lh_no(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { - let two : N = crate::convert(2.0); - let mut mat : TMat4 = TMat4::::identity(); +pub fn ortho_lh_no( + left: N, + right: N, + bottom: N, + top: N, + znear: N, + zfar: N, +) -> TMat4 { + let two: N = crate::convert(2.0); + let mut mat: TMat4 = TMat4::::identity(); mat[(0, 0)] = two / (right - left); mat[(0, 3)] = -(right + left) / (right - left); - mat[(1, 1)] = two / (top-bottom); + mat[(1, 1)] = two / (top - bottom); mat[(1, 3)] = -(top + bottom) / (top - bottom); mat[(2, 2)] = two / (zfar - znear); mat[(2, 3)] = -(zfar + znear) / (zfar - znear); @@ -115,17 +122,24 @@ pub fn ortho_lh_no(left: N, right: N, bottom: N, top: N, znear: N, /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_lh_zo(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { - let one : N = N::one(); - let two : N = crate::convert(2.0); - let mut mat : TMat4 = TMat4::::identity(); +pub fn ortho_lh_zo( + left: N, + right: N, + bottom: N, + top: N, + znear: N, + zfar: N, +) -> TMat4 { + let one: N = N::one(); + let two: N = crate::convert(2.0); + let mut mat: TMat4 = TMat4::::identity(); mat[(0, 0)] = two / (right - left); - mat[(0, 3)] = - (right + left) / (right - left); + mat[(0, 3)] = -(right + left) / (right - left); mat[(1, 1)] = two / (top - bottom); - mat[(1, 3)] = - (top + bottom) / (top - bottom); + mat[(1, 3)] = -(top + bottom) / (top - bottom); mat[(2, 2)] = one / (zfar - znear); - mat[(2, 3)] = - znear / (zfar - znear); + mat[(2, 3)] = -znear / (zfar - znear); mat } @@ -171,16 +185,23 @@ pub fn ortho_rh(left: N, right: N, bottom: N, top: N, znear: N, zf /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_rh_no(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { - let two : N = crate::convert(2.0); - let mut mat : TMat4 = TMat4::::identity(); +pub fn ortho_rh_no( + left: N, + right: N, + bottom: N, + top: N, + znear: N, + zfar: N, +) -> TMat4 { + let two: N = crate::convert(2.0); + let mut mat: TMat4 = TMat4::::identity(); mat[(0, 0)] = two / (right - left); - mat[(0, 3)] = - (right + left) / (right - left); - mat[(1, 1)] = two/(top-bottom); - mat[(1, 3)] = - (top + bottom) / (top - bottom); - mat[(2, 2)] = - two / (zfar - znear); - mat[(2, 3)] = - (zfar + znear) / (zfar - znear); + mat[(0, 3)] = -(right + left) / (right - left); + mat[(1, 1)] = two / (top - bottom); + mat[(1, 3)] = -(top + bottom) / (top - bottom); + mat[(2, 2)] = -two / (zfar - znear); + mat[(2, 3)] = -(zfar + znear) / (zfar - znear); mat } @@ -196,17 +217,24 @@ pub fn ortho_rh_no(left: N, right: N, bottom: N, top: N, znear: N, /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_rh_zo(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { - let one : N = N::one(); - let two : N = crate::convert(2.0); - let mut mat : TMat4 = TMat4::::identity(); +pub fn ortho_rh_zo( + left: N, + right: N, + bottom: N, + top: N, + znear: N, + zfar: N, +) -> TMat4 { + let one: N = N::one(); + let two: N = crate::convert(2.0); + let mut mat: TMat4 = TMat4::::identity(); mat[(0, 0)] = two / (right - left); - mat[(0, 3)] = - (right + left) / (right - left); - mat[(1, 1)] = two/(top-bottom); - mat[(1, 3)] = - (top + bottom) / (top - bottom); - mat[(2, 2)] = - one / (zfar - znear); - mat[(2, 3)] = - znear / (zfar - znear); + mat[(0, 3)] = -(right + left) / (right - left); + mat[(1, 1)] = two / (top - bottom); + mat[(1, 3)] = -(top + bottom) / (top - bottom); + mat[(2, 2)] = -one / (zfar - znear); + mat[(2, 3)] = -znear / (zfar - znear); mat } @@ -264,19 +292,16 @@ pub fn perspective_fov_lh(fov: N, width: N, height: N, near: N, fa /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_lh_no(fov: N, width: N, height: N, near: N, far: N) -> TMat4 { - assert!( - width > N::zero(), - "The width must be greater than zero" - ); - assert!( - height > N::zero(), - "The height must be greater than zero." - ); - assert!( - fov > N::zero(), - "The fov must be greater than zero" - ); +pub fn perspective_fov_lh_no( + fov: N, + width: N, + height: N, + near: N, + far: N, +) -> TMat4 { + assert!(width > N::zero(), "The width must be greater than zero"); + assert!(height > N::zero(), "The height must be greater than zero."); + assert!(fov > N::zero(), "The fov must be greater than zero"); let mut mat = TMat4::zeros(); @@ -287,7 +312,7 @@ pub fn perspective_fov_lh_no(fov: N, width: N, height: N, near: N, mat[(0, 0)] = w; mat[(1, 1)] = h; mat[(2, 2)] = (far + near) / (far - near); - mat[(2, 3)] = - (far * near * crate::convert(2.0)) / (far - near); + mat[(2, 3)] = -(far * near * crate::convert(2.0)) / (far - near); mat[(3, 2)] = N::one(); mat @@ -303,19 +328,16 @@ pub fn perspective_fov_lh_no(fov: N, width: N, height: N, near: N, /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_lh_zo(fov: N, width: N, height: N, near: N, far: N) -> TMat4 { - assert!( - width > N::zero(), - "The width must be greater than zero" - ); - assert!( - height > N::zero(), - "The height must be greater than zero." - ); - assert!( - fov > N::zero(), - "The fov must be greater than zero" - ); +pub fn perspective_fov_lh_zo( + fov: N, + width: N, + height: N, + near: N, + far: N, +) -> TMat4 { + assert!(width > N::zero(), "The width must be greater than zero"); + assert!(height > N::zero(), "The height must be greater than zero."); + assert!(fov > N::zero(), "The fov must be greater than zero"); let mut mat = TMat4::zeros(); @@ -370,19 +392,16 @@ pub fn perspective_fov_rh(fov: N, width: N, height: N, near: N, fa /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_rh_no(fov: N, width: N, height: N, near: N, far: N) -> TMat4 { - assert!( - width > N::zero(), - "The width must be greater than zero" - ); - assert!( - height > N::zero(), - "The height must be greater than zero." - ); - assert!( - fov > N::zero(), - "The fov must be greater than zero" - ); +pub fn perspective_fov_rh_no( + fov: N, + width: N, + height: N, + near: N, + far: N, +) -> TMat4 { + assert!(width > N::zero(), "The width must be greater than zero"); + assert!(height > N::zero(), "The height must be greater than zero."); + assert!(fov > N::zero(), "The fov must be greater than zero"); let mut mat = TMat4::zeros(); @@ -392,8 +411,8 @@ pub fn perspective_fov_rh_no(fov: N, width: N, height: N, near: N, mat[(0, 0)] = w; mat[(1, 1)] = h; - mat[(2, 2)] = - (far + near) / (far - near); - mat[(2, 3)] = - (far * near * crate::convert(2.0)) / (far - near); + mat[(2, 2)] = -(far + near) / (far - near); + mat[(2, 3)] = -(far * near * crate::convert(2.0)) / (far - near); mat[(3, 2)] = -N::one(); mat @@ -409,19 +428,16 @@ pub fn perspective_fov_rh_no(fov: N, width: N, height: N, near: N, /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_rh_zo(fov: N, width: N, height: N, near: N, far: N) -> TMat4 { - assert!( - width > N::zero(), - "The width must be greater than zero" - ); - assert!( - height > N::zero(), - "The height must be greater than zero." - ); - assert!( - fov > N::zero(), - "The fov must be greater than zero" - ); +pub fn perspective_fov_rh_zo( + fov: N, + width: N, + height: N, + near: N, + far: N, +) -> TMat4 { + assert!(width > N::zero(), "The width must be greater than zero"); + assert!(height > N::zero(), "The height must be greater than zero."); + assert!(fov > N::zero(), "The fov must be greater than zero"); let mut mat = TMat4::zeros(); @@ -518,8 +534,8 @@ pub fn perspective_lh_no(aspect: N, fovy: N, near: N, far: N) -> T ); let one = N::one(); - let two: N = crate::convert( 2.0); - let mut mat : TMat4 = TMat4::zeros(); + let two: N = crate::convert(2.0); + let mut mat: TMat4 = TMat4::zeros(); let tan_half_fovy = (fovy / two).tan(); @@ -554,7 +570,7 @@ pub fn perspective_lh_zo(aspect: N, fovy: N, near: N, far: N) -> T ); let one = N::one(); - let two: N = crate::convert( 2.0); + let two: N = crate::convert(2.0); let mut mat: TMat4 = TMat4::zeros(); let tan_half_fovy = (fovy / two).tan(); @@ -620,15 +636,15 @@ pub fn perspective_rh_no(aspect: N, fovy: N, near: N, far: N) -> T ); let negone = -N::one(); - let one = N::one(); - let two: N = crate::convert( 2.0); + let one = N::one(); + let two: N = crate::convert(2.0); let mut mat = TMat4::zeros(); let tan_half_fovy = (fovy / two).tan(); mat[(0, 0)] = one / (aspect * tan_half_fovy); mat[(1, 1)] = one / tan_half_fovy; - mat[(2, 2)] = - (far + near) / (far - near); + mat[(2, 2)] = -(far + near) / (far - near); mat[(2, 3)] = -(two * far * near) / (far - near); mat[(3, 2)] = negone; @@ -657,8 +673,8 @@ pub fn perspective_rh_zo(aspect: N, fovy: N, near: N, far: N) -> T ); let negone = -N::one(); - let one = N::one(); - let two = crate::convert( 2.0); + let one = N::one(); + let two = crate::convert(2.0); let mut mat = TMat4::zeros(); let tan_half_fovy = (fovy / two).tan(); @@ -793,4 +809,4 @@ pub fn reversed_infinite_perspective_rh_zo(aspect: N, fovy: N, nea // //pub fn tweaked_infinite_perspective_ep(fovy: N, aspect: N, near: N, ep: N) -> TMat4 { // unimplemented!() -//} \ No newline at end of file +//} diff --git a/nalgebra-glm/src/ext/matrix_projection.rs b/nalgebra-glm/src/ext/matrix_projection.rs index 3048b77c..93c8d664 100644 --- a/nalgebra-glm/src/ext/matrix_projection.rs +++ b/nalgebra-glm/src/ext/matrix_projection.rs @@ -9,7 +9,11 @@ use crate::aliases::{TMat4, TVec2, TVec3, TVec4}; /// * `center` - Specify the center of a picking region in window coordinates. /// * `delta` - Specify the width and height, respectively, of the picking region in window coordinates. /// * `viewport` - Rendering viewport. -pub fn pick_matrix(center: &TVec2, delta: &TVec2, viewport: &TVec4) -> TMat4 { +pub fn pick_matrix( + center: &TVec2, + delta: &TVec2, + viewport: &TVec4, +) -> TMat4 { let shift = TVec3::new( (viewport.z - (center.x - viewport.x) * na::convert(2.0)) / delta.x, (viewport.w - (center.y - viewport.y) * na::convert(2.0)) / delta.y, @@ -46,8 +50,7 @@ pub fn project( model: &TMat4, proj: &TMat4, viewport: TVec4, -) -> TVec3 -{ +) -> TVec3 { project_no(obj, model, proj, viewport) } @@ -74,8 +77,7 @@ pub fn project_no( model: &TMat4, proj: &TMat4, viewport: TVec4, -) -> TVec3 -{ +) -> TVec3 { let proj = project_zo(obj, model, proj, viewport); TVec3::new(proj.x, proj.y, proj.z * na::convert(0.5) + na::convert(0.5)) } @@ -103,8 +105,7 @@ pub fn project_zo( model: &TMat4, proj: &TMat4, viewport: TVec4, -) -> TVec3 -{ +) -> TVec3 { let normalized = proj * model * TVec4::new(obj.x, obj.y, obj.z, N::one()); let scale = N::one() / normalized.w; @@ -137,8 +138,7 @@ pub fn unproject( model: &TMat4, proj: &TMat4, viewport: TVec4, -) -> TVec3 -{ +) -> TVec3 { unproject_no(win, model, proj, viewport) } @@ -165,8 +165,7 @@ pub fn unproject_no( model: &TMat4, proj: &TMat4, viewport: TVec4, -) -> TVec3 -{ +) -> TVec3 { let _2: N = na::convert(2.0); let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros); let pt = TVec4::new( @@ -203,8 +202,7 @@ pub fn unproject_zo( model: &TMat4, proj: &TMat4, viewport: TVec4, -) -> TVec3 -{ +) -> TVec3 { let _2: N = na::convert(2.0); let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros); let pt = TVec4::new( diff --git a/nalgebra-glm/src/ext/matrix_transform.rs b/nalgebra-glm/src/ext/matrix_transform.rs index c7f6b72d..df0696a4 100644 --- a/nalgebra-glm/src/ext/matrix_transform.rs +++ b/nalgebra-glm/src/ext/matrix_transform.rs @@ -5,7 +5,9 @@ use crate::traits::{Alloc, Dimension, Number}; /// The identity matrix. pub fn identity() -> TMat -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ TMat::::identity() } diff --git a/nalgebra-glm/src/geometric.rs b/nalgebra-glm/src/geometric.rs index 7c1e1987..a4b0b988 100644 --- a/nalgebra-glm/src/geometric.rs +++ b/nalgebra-glm/src/geometric.rs @@ -14,13 +14,17 @@ pub fn cross(x: &TVec3, y: &TVec3) -> TVec3 { /// /// * [`distance2`](fn.distance2.html) pub fn distance(p0: &TVec, p1: &TVec) -> N -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ (p1 - p0).norm() } /// The dot product of two vectors. pub fn dot(x: &TVec, y: &TVec) -> N -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.dot(y) } @@ -50,7 +54,9 @@ where /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) pub fn length(x: &TVec) -> N -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.norm() } @@ -64,26 +70,34 @@ where DefaultAllocator: Alloc { /// * [`magnitude2`](fn.magnitude2.html) /// * [`nalgebra::norm`](../nalgebra/fn.norm.html) pub fn magnitude(x: &TVec) -> N -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.norm() } /// Normalizes a vector. pub fn normalize(x: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.normalize() } /// For the incident vector `i` and surface orientation `n`, returns the reflection direction : `result = i - 2.0 * dot(n, i) * n`. pub fn reflect_vec(i: &TVec, n: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ let _2 = N::one() + N::one(); i - n * (n.dot(i) * _2) } /// For the incident vector `i` and surface normal `n`, and the ratio of indices of refraction `eta`, return the refraction vector. pub fn refract_vec(i: &TVec, n: &TVec, eta: N) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ let ni = n.dot(i); let k = N::one() - eta * eta * (N::one() - ni * ni); diff --git a/nalgebra-glm/src/gtc/matrix_access.rs b/nalgebra-glm/src/gtc/matrix_access.rs index f61d9782..2713b8be 100644 --- a/nalgebra-glm/src/gtc/matrix_access.rs +++ b/nalgebra-glm/src/gtc/matrix_access.rs @@ -10,10 +10,7 @@ use crate::traits::{Alloc, Dimension}; /// * [`row`](fn.row.html) /// * [`set_column`](fn.set_column.html) /// * [`set_row`](fn.set_row.html) -pub fn column( - m: &TMat, - index: usize, -) -> TVec +pub fn column(m: &TMat, index: usize) -> TVec where DefaultAllocator: Alloc, { @@ -48,7 +45,9 @@ where /// * [`set_column`](fn.set_column.html) /// * [`set_row`](fn.set_row.html) pub fn row(m: &TMat, index: usize) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ m.row(index).into_owned().transpose() } diff --git a/nalgebra-glm/src/gtc/matrix_inverse.rs b/nalgebra-glm/src/gtc/matrix_inverse.rs index eab0b995..feab0daa 100644 --- a/nalgebra-glm/src/gtc/matrix_inverse.rs +++ b/nalgebra-glm/src/gtc/matrix_inverse.rs @@ -5,14 +5,18 @@ use crate::traits::{Alloc, Dimension}; /// Fast matrix inverse for affine matrix. pub fn affine_inverse(m: TMat) -> TMat -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ // FIXME: this should be optimized. m.try_inverse().unwrap_or_else(TMat::<_, D, D>::zeros) } /// Compute the transpose of the inverse of a matrix. pub fn inverse_transpose(m: TMat) -> TMat -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ m.try_inverse() .unwrap_or_else(TMat::<_, D, D>::zeros) .transpose() diff --git a/nalgebra-glm/src/gtc/type_ptr.rs b/nalgebra-glm/src/gtc/type_ptr.rs index 6de096ca..f8c6698b 100644 --- a/nalgebra-glm/src/gtc/type_ptr.rs +++ b/nalgebra-glm/src/gtc/type_ptr.rs @@ -76,7 +76,12 @@ pub fn mat2_to_mat3(m: &TMat2) -> TMat3 { /// Converts a 3x3 matrix to a 2x2 matrix. pub fn mat3_to_mat2(m: &TMat3) -> TMat2 { - TMat2::new(m.m11.inlined_clone(), m.m12.inlined_clone(), m.m21.inlined_clone(), m.m22.inlined_clone()) + TMat2::new( + m.m11.inlined_clone(), + m.m12.inlined_clone(), + m.m21.inlined_clone(), + m.m22.inlined_clone(), + ) } /// Converts a 3x3 matrix to a 4x4 matrix. @@ -92,9 +97,15 @@ pub fn mat3_to_mat4(m: &TMat3) -> TMat4 { /// Converts a 4x4 matrix to a 3x3 matrix. pub fn mat4_to_mat3(m: &TMat4) -> TMat3 { TMat3::new( - m.m11.inlined_clone(), m.m12.inlined_clone(), m.m13.inlined_clone(), - m.m21.inlined_clone(), m.m22.inlined_clone(), m.m23.inlined_clone(), - m.m31.inlined_clone(), m.m32.inlined_clone(), m.m33.inlined_clone(), + m.m11.inlined_clone(), + m.m12.inlined_clone(), + m.m13.inlined_clone(), + m.m21.inlined_clone(), + m.m22.inlined_clone(), + m.m23.inlined_clone(), + m.m31.inlined_clone(), + m.m32.inlined_clone(), + m.m33.inlined_clone(), ) } @@ -110,7 +121,12 @@ pub fn mat2_to_mat4(m: &TMat2) -> TMat4 { /// Converts a 4x4 matrix to a 2x2 matrix. pub fn mat4_to_mat2(m: &TMat4) -> TMat2 { - TMat2::new(m.m11.inlined_clone(), m.m12.inlined_clone(), m.m21.inlined_clone(), m.m22.inlined_clone()) + TMat2::new( + m.m11.inlined_clone(), + m.m12.inlined_clone(), + m.m21.inlined_clone(), + m.m22.inlined_clone(), + ) } /// Creates a quaternion from a slice arranged as `[x, y, z, w]`. @@ -297,7 +313,11 @@ pub fn vec3_to_vec3(v: &TVec3) -> TVec3 { /// * [`vec3_to_vec2`](fn.vec3_to_vec2.html) /// * [`vec3_to_vec4`](fn.vec3_to_vec4.html) pub fn vec4_to_vec3(v: &TVec4) -> TVec3 { - TVec3::new(v.x.inlined_clone(), v.y.inlined_clone(), v.z.inlined_clone()) + TVec3::new( + v.x.inlined_clone(), + v.y.inlined_clone(), + v.z.inlined_clone(), + ) } /// Creates a 3D vector from another vector. @@ -386,12 +406,16 @@ pub fn make_vec4(ptr: &[N]) -> TVec4 { /// Converts a matrix or vector to a slice arranged in column-major order. pub fn value_ptr(x: &TMat) -> &[N] -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.as_slice() } /// Converts a matrix or vector to a mutable slice arranged in column-major order. pub fn value_ptr_mut(x: &mut TMat) -> &mut [N] -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.as_mut_slice() } diff --git a/nalgebra-glm/src/gtx/norm.rs b/nalgebra-glm/src/gtx/norm.rs index 9332c010..f6fabe97 100644 --- a/nalgebra-glm/src/gtx/norm.rs +++ b/nalgebra-glm/src/gtx/norm.rs @@ -9,7 +9,9 @@ use crate::traits::{Alloc, Dimension}; /// /// * [`distance`](fn.distance.html) pub fn distance2(p0: &TVec, p1: &TVec) -> N -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ (p1 - p0).norm_squared() } @@ -21,7 +23,9 @@ where DefaultAllocator: Alloc { /// * [`l2_distance`](fn.l2_distance.html) /// * [`l2_norm`](fn.l2_norm.html) pub fn l1_distance(x: &TVec, y: &TVec) -> N -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ l1_norm(&(y - x)) } @@ -36,7 +40,9 @@ where DefaultAllocator: Alloc { /// * [`l2_distance`](fn.l2_distance.html) /// * [`l2_norm`](fn.l2_norm.html) pub fn l1_norm(v: &TVec) -> N -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ crate::comp_add(&v.abs()) } @@ -55,7 +61,9 @@ where DefaultAllocator: Alloc { /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) pub fn l2_distance(x: &TVec, y: &TVec) -> N -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ l2_norm(&(y - x)) } @@ -76,7 +84,9 @@ where DefaultAllocator: Alloc { /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) pub fn l2_norm(x: &TVec) -> N -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.norm() } @@ -92,7 +102,9 @@ where DefaultAllocator: Alloc { /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) pub fn length2(x: &TVec) -> N -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.norm_squared() } @@ -108,7 +120,9 @@ where DefaultAllocator: Alloc { /// * [`magnitude`](fn.magnitude.html) /// * [`nalgebra::norm_squared`](../nalgebra/fn.norm_squared.html) pub fn magnitude2(x: &TVec) -> N -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.norm_squared() } diff --git a/nalgebra-glm/src/gtx/normalize_dot.rs b/nalgebra-glm/src/gtx/normalize_dot.rs index 06ce6978..23e6a73f 100644 --- a/nalgebra-glm/src/gtx/normalize_dot.rs +++ b/nalgebra-glm/src/gtx/normalize_dot.rs @@ -11,7 +11,9 @@ use crate::traits::{Alloc, Dimension}; /// /// * [`normalize_dot`](fn.normalize_dot.html`) pub fn fast_normalize_dot(x: &TVec, y: &TVec) -> N -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ // XXX: improve those. x.normalize().dot(&y.normalize()) } @@ -22,7 +24,9 @@ where DefaultAllocator: Alloc { /// /// * [`fast_normalize_dot`](fn.fast_normalize_dot.html`) pub fn normalize_dot(x: &TVec, y: &TVec) -> N -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ // XXX: improve those. x.normalize().dot(&y.normalize()) } diff --git a/nalgebra-glm/src/gtx/vector_angle.rs b/nalgebra-glm/src/gtx/vector_angle.rs index 8753ccd0..e71abafb 100644 --- a/nalgebra-glm/src/gtx/vector_angle.rs +++ b/nalgebra-glm/src/gtx/vector_angle.rs @@ -5,7 +5,9 @@ use crate::traits::{Alloc, Dimension}; /// The angle between two vectors. pub fn angle(x: &TVec, y: &TVec) -> N -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.angle(y) } diff --git a/nalgebra-glm/src/gtx/vector_query.rs b/nalgebra-glm/src/gtx/vector_query.rs index 2a127f00..687d9530 100644 --- a/nalgebra-glm/src/gtx/vector_query.rs +++ b/nalgebra-glm/src/gtx/vector_query.rs @@ -22,11 +22,7 @@ pub fn are_collinear2d(v0: &TVec2, v1: &TVec2, epsilon: N) -> b } /// Returns `true` if two vectors are orthogonal (up to an epsilon). -pub fn are_orthogonal( - v0: &TVec, - v1: &TVec, - epsilon: N, -) -> bool +pub fn are_orthogonal(v0: &TVec, v1: &TVec, epsilon: N) -> bool where DefaultAllocator: Alloc, { @@ -40,18 +36,24 @@ where /// Returns `true` if all the components of `v` are zero (up to an epsilon). pub fn is_comp_null(v: &TVec, epsilon: N) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ v.map(|x| abs_diff_eq!(x, N::zero(), epsilon = epsilon)) } /// Returns `true` if `v` has a magnitude of 1 (up to an epsilon). pub fn is_normalized(v: &TVec, epsilon: N) -> bool -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ abs_diff_eq!(v.norm_squared(), N::one(), epsilon = epsilon * epsilon) } /// Returns `true` if `v` is zero (up to an epsilon). pub fn is_null(v: &TVec, epsilon: N) -> bool -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ abs_diff_eq!(*v, TVec::::zeros(), epsilon = epsilon) } diff --git a/nalgebra-glm/src/matrix.rs b/nalgebra-glm/src/matrix.rs index a4c4efe9..ea887cf2 100644 --- a/nalgebra-glm/src/matrix.rs +++ b/nalgebra-glm/src/matrix.rs @@ -5,13 +5,17 @@ use crate::traits::{Alloc, Dimension, Number}; /// The determinant of the matrix `m`. pub fn determinant(m: &TMat) -> N -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ m.determinant() } /// The inverse of the matrix `m`. pub fn inverse(m: &TMat) -> TMat -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ m.clone() .try_inverse() .unwrap_or_else(TMat::::zeros) @@ -41,6 +45,8 @@ where /// The transpose of the matrix `m`. pub fn transpose(x: &TMat) -> TMat -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.transpose() } diff --git a/nalgebra-glm/src/traits.rs b/nalgebra-glm/src/traits.rs index 0857484e..24d41083 100644 --- a/nalgebra-glm/src/traits.rs +++ b/nalgebra-glm/src/traits.rs @@ -71,7 +71,8 @@ pub trait Alloc: { } -impl Alloc for T where T: Allocator +impl Alloc for T where + T: Allocator + Allocator + Allocator + Allocator diff --git a/nalgebra-glm/src/trigonometric.rs b/nalgebra-glm/src/trigonometric.rs index 139a48da..adf1a211 100644 --- a/nalgebra-glm/src/trigonometric.rs +++ b/nalgebra-glm/src/trigonometric.rs @@ -5,90 +5,120 @@ use crate::traits::{Alloc, Dimension}; /// Component-wise arc-cosinus. pub fn acos(x: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.map(|e| e.acos()) } /// Component-wise hyperbolic arc-cosinus. pub fn acosh(x: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.map(|e| e.acosh()) } /// Component-wise arc-sinus. pub fn asin(x: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.map(|e| e.asin()) } /// Component-wise hyperbolic arc-sinus. pub fn asinh(x: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.map(|e| e.asinh()) } /// Component-wise arc-tangent of `y / x`. pub fn atan2(y: &TVec, x: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ y.zip_map(x, |y, x| y.atan2(x)) } /// Component-wise arc-tangent. pub fn atan(y_over_x: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ y_over_x.map(|e| e.atan()) } /// Component-wise hyperbolic arc-tangent. pub fn atanh(x: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.map(|e| e.atanh()) } /// Component-wise cosinus. pub fn cos(angle: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ angle.map(|e| e.cos()) } /// Component-wise hyperbolic cosinus. pub fn cosh(angle: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ angle.map(|e| e.cosh()) } /// Component-wise conversion from radians to degrees. pub fn degrees(radians: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ radians.map(|e| e * na::convert(180.0) / N::pi()) } /// Component-wise conversion fro degrees to radians. pub fn radians(degrees: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ degrees.map(|e| e * N::pi() / na::convert(180.0)) } /// Component-wise sinus. pub fn sin(angle: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ angle.map(|e| e.sin()) } /// Component-wise hyperbolic sinus. pub fn sinh(angle: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ angle.map(|e| e.sinh()) } /// Component-wise tangent. pub fn tan(angle: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ angle.map(|e| e.tan()) } /// Component-wise hyperbolic tangent. pub fn tanh(angle: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ angle.map(|e| e.tanh()) } diff --git a/nalgebra-glm/src/vector_relational.rs b/nalgebra-glm/src/vector_relational.rs index 844936fe..be17d247 100644 --- a/nalgebra-glm/src/vector_relational.rs +++ b/nalgebra-glm/src/vector_relational.rs @@ -21,7 +21,9 @@ use crate::traits::{Alloc, Dimension, Number}; /// * [`any`](fn.any.html) /// * [`not`](fn.not.html) pub fn all(v: &TVec) -> bool -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ v.iter().all(|x| *x) } @@ -46,7 +48,9 @@ where DefaultAllocator: Alloc { /// * [`all`](fn.all.html) /// * [`not`](fn.not.html) pub fn any(v: &TVec) -> bool -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ v.iter().any(|x| *x) } @@ -70,7 +74,9 @@ where DefaultAllocator: Alloc { /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) pub fn equal(x: &TVec, y: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.zip_map(y, |x, y| x == y) } @@ -94,7 +100,9 @@ where DefaultAllocator: Alloc { /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) pub fn greater_than(x: &TVec, y: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.zip_map(y, |x, y| x > y) } @@ -117,10 +125,7 @@ where DefaultAllocator: Alloc { /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) -pub fn greater_than_equal( - x: &TVec, - y: &TVec, -) -> TVec +pub fn greater_than_equal(x: &TVec, y: &TVec) -> TVec where DefaultAllocator: Alloc, { @@ -147,7 +152,9 @@ where /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) pub fn less_than(x: &TVec, y: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.zip_map(y, |x, y| x < y) } @@ -171,7 +178,9 @@ where DefaultAllocator: Alloc { /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) pub fn less_than_equal(x: &TVec, y: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.zip_map(y, |x, y| x <= y) } @@ -196,7 +205,9 @@ where DefaultAllocator: Alloc { /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not_equal`](fn.not_equal.html) pub fn not(v: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ v.map(|x| !x) } @@ -220,6 +231,8 @@ where DefaultAllocator: Alloc { /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not`](fn.not.html) pub fn not_equal(x: &TVec, y: &TVec) -> TVec -where DefaultAllocator: Alloc { +where + DefaultAllocator: Alloc, +{ x.zip_map(y, |x, y| x != y) } diff --git a/nalgebra-glm/tests/lib.rs b/nalgebra-glm/tests/lib.rs index ce95c64f..38f13fd8 100644 --- a/nalgebra-glm/tests/lib.rs +++ b/nalgebra-glm/tests/lib.rs @@ -1,36 +1,36 @@ extern crate nalgebra as na; extern crate nalgebra_glm as glm; -use na::Perspective3; -use na::Orthographic3; use glm::Mat4; use glm::Vec4; +use na::Orthographic3; +use na::Perspective3; #[test] -pub fn orthographic_glm_nalgebra_same() -{ - let na_mat : Mat4 = Orthographic3::new(-100.0f32,100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32).into_inner(); - let gl_mat : Mat4 = glm::ortho(-100.0f32,100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32); +pub fn orthographic_glm_nalgebra_same() { + let na_mat: Mat4 = + Orthographic3::new(-100.0f32, 100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32).into_inner(); + let gl_mat: Mat4 = glm::ortho(-100.0f32, 100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32); assert_eq!(na_mat, gl_mat); } #[test] -pub fn perspective_glm_nalgebra_same() -{ - let na_mat : Mat4 = Perspective3::new(16.0f32/9.0f32, 3.14f32/2.0f32, 0.1f32, 100.0f32).into_inner(); - let gl_mat : Mat4 = glm::perspective(16.0f32/9.0f32, 3.14f32/2.0f32, 0.1f32, 100.0f32); +pub fn perspective_glm_nalgebra_same() { + let na_mat: Mat4 = + Perspective3::new(16.0f32 / 9.0f32, 3.14f32 / 2.0f32, 0.1f32, 100.0f32).into_inner(); + let gl_mat: Mat4 = glm::perspective(16.0f32 / 9.0f32, 3.14f32 / 2.0f32, 0.1f32, 100.0f32); assert_eq!(na_mat, gl_mat); } #[test] -pub fn orthographic_glm_nalgebra_project_same() -{ - let point = Vec4::new(1.0,0.0,-20.0,1.0); +pub fn orthographic_glm_nalgebra_project_same() { + let point = Vec4::new(1.0, 0.0, -20.0, 1.0); - let na_mat : Mat4 = Orthographic3::new(-100.0f32,100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32).into_inner(); - let gl_mat : Mat4 = glm::ortho(-100.0f32,100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32); + let na_mat: Mat4 = + Orthographic3::new(-100.0f32, 100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32).into_inner(); + let gl_mat: Mat4 = glm::ortho(-100.0f32, 100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32); let na_pt = na_mat * point; let gl_pt = gl_mat * point; @@ -40,12 +40,12 @@ pub fn orthographic_glm_nalgebra_project_same() } #[test] -pub fn perspective_glm_nalgebra_project_same() -{ - let point = Vec4::new(1.0,0.0,-20.0,1.0); +pub fn perspective_glm_nalgebra_project_same() { + let point = Vec4::new(1.0, 0.0, -20.0, 1.0); - let na_mat : Mat4 = Perspective3::new(16.0f32/9.0f32, 3.14f32/2.0f32, 0.1f32, 100.0f32).into_inner(); - let gl_mat : Mat4 = glm::perspective(16.0f32/9.0f32, 3.14f32/2.0f32, 0.1f32, 100.0f32); + let na_mat: Mat4 = + Perspective3::new(16.0f32 / 9.0f32, 3.14f32 / 2.0f32, 0.1f32, 100.0f32).into_inner(); + let gl_mat: Mat4 = glm::perspective(16.0f32 / 9.0f32, 3.14f32 / 2.0f32, 0.1f32, 100.0f32); let na_pt = na_mat * point; let gl_pt = gl_mat * point; diff --git a/nalgebra-lapack/src/cholesky.rs b/nalgebra-lapack/src/cholesky.rs index e25223fa..669fa671 100644 --- a/nalgebra-lapack/src/cholesky.rs +++ b/nalgebra-lapack/src/cholesky.rs @@ -15,21 +15,18 @@ use lapack; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound( - serialize = "DefaultAllocator: Allocator, - MatrixN: Serialize" - )) + serde(bound(serialize = "DefaultAllocator: Allocator, + MatrixN: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound( - deserialize = "DefaultAllocator: Allocator, - MatrixN: Deserialize<'de>" - )) + serde(bound(deserialize = "DefaultAllocator: Allocator, + MatrixN: Deserialize<'de>")) )] #[derive(Clone, Debug)] pub struct Cholesky -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { l: MatrixN, } @@ -38,10 +35,12 @@ impl Copy for Cholesky where DefaultAllocator: Allocator, MatrixN: Copy, -{} +{ +} impl Cholesky -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// Computes the cholesky decomposition of the given symmetric-definite-positive square /// matrix. @@ -117,7 +116,9 @@ where DefaultAllocator: Allocator /// Solves in-place the symmetric-definite-positive linear system `self * x = b`, where `x` is /// the unknown to be determined. pub fn solve_mut(&self, b: &mut MatrixMN) -> bool - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { let dim = self.l.nrows(); assert!( diff --git a/nalgebra-lapack/src/eigen.rs b/nalgebra-lapack/src/eigen.rs index 9df43087..8164c844 100644 --- a/nalgebra-lapack/src/eigen.rs +++ b/nalgebra-lapack/src/eigen.rs @@ -34,7 +34,8 @@ use lapack; )] #[derive(Clone, Debug)] pub struct Eigen -where DefaultAllocator: Allocator + Allocator +where + DefaultAllocator: Allocator + Allocator, { /// The eigenvalues of the decomposed matrix. pub eigenvalues: VectorN, @@ -53,7 +54,8 @@ where } impl Eigen -where DefaultAllocator: Allocator + Allocator +where + DefaultAllocator: Allocator + Allocator, { /// Computes the eigenvalues and eigenvectors of the square matrix `m`. /// @@ -62,8 +64,7 @@ where DefaultAllocator: Allocator + Allocator mut m: MatrixN, left_eigenvectors: bool, eigenvectors: bool, - ) -> Option> - { + ) -> Option> { assert!( m.is_square(), "Unable to compute the eigenvalue decomposition of a non-square matrix." @@ -229,7 +230,9 @@ where DefaultAllocator: Allocator + Allocator /// /// Panics if the eigenvalue computation does not converge. pub fn complex_eigenvalues(mut m: MatrixN) -> VectorN, D> - where DefaultAllocator: Allocator, D> { + where + DefaultAllocator: Allocator, D>, + { assert!( m.is_square(), "Unable to compute the eigenvalue decomposition of a non-square matrix." diff --git a/nalgebra-lapack/src/hessenberg.rs b/nalgebra-lapack/src/hessenberg.rs index 81e72966..b20df55e 100644 --- a/nalgebra-lapack/src/hessenberg.rs +++ b/nalgebra-lapack/src/hessenberg.rs @@ -1,11 +1,11 @@ use num::Zero; use num_complex::Complex; +use crate::ComplexHelper; use na::allocator::Allocator; use na::dimension::{DimDiff, DimSub, U1}; use na::storage::Storage; use na::{DefaultAllocator, Matrix, MatrixN, Scalar, VectorN}; -use crate::ComplexHelper; use lapack; @@ -13,25 +13,22 @@ use lapack; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound( - serialize = "DefaultAllocator: Allocator + + serde(bound(serialize = "DefaultAllocator: Allocator + Allocator>, MatrixN: Serialize, - VectorN>: Serialize" - )) + VectorN>: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound( - deserialize = "DefaultAllocator: Allocator + + serde(bound(deserialize = "DefaultAllocator: Allocator + Allocator>, MatrixN: Deserialize<'de>, - VectorN>: Deserialize<'de>" - )) + VectorN>: Deserialize<'de>")) )] #[derive(Clone, Debug)] pub struct Hessenberg> -where DefaultAllocator: Allocator + Allocator> +where + DefaultAllocator: Allocator + Allocator>, { h: MatrixN, tau: VectorN>, @@ -42,10 +39,12 @@ where DefaultAllocator: Allocator + Allocator>, MatrixN: Copy, VectorN>: Copy, -{} +{ +} impl> Hessenberg -where DefaultAllocator: Allocator + Allocator> +where + DefaultAllocator: Allocator + Allocator>, { /// Computes the hessenberg decomposition of the matrix `m`. pub fn new(mut m: MatrixN) -> Self { @@ -97,7 +96,8 @@ where DefaultAllocator: Allocator + Allocator> } impl> Hessenberg -where DefaultAllocator: Allocator + Allocator> +where + DefaultAllocator: Allocator + Allocator>, { /// Computes the matrices `(Q, H)` of this decomposition. #[inline] diff --git a/nalgebra-lapack/src/lu.rs b/nalgebra-lapack/src/lu.rs index fb4296da..0ff185d5 100644 --- a/nalgebra-lapack/src/lu.rs +++ b/nalgebra-lapack/src/lu.rs @@ -1,11 +1,11 @@ use num::{One, Zero}; use num_complex::Complex; +use crate::ComplexHelper; use na::allocator::Allocator; use na::dimension::{Dim, DimMin, DimMinimum, U1}; use na::storage::Storage; use na::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Scalar, VectorN}; -use crate::ComplexHelper; use lapack; @@ -20,25 +20,22 @@ use lapack; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound( - serialize = "DefaultAllocator: Allocator + + serde(bound(serialize = "DefaultAllocator: Allocator + Allocator>, MatrixMN: Serialize, - PermutationSequence>: Serialize" - )) + PermutationSequence>: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound( - deserialize = "DefaultAllocator: Allocator + + serde(bound(deserialize = "DefaultAllocator: Allocator + Allocator>, MatrixMN: Deserialize<'de>, - PermutationSequence>: Deserialize<'de>" - )) + PermutationSequence>: Deserialize<'de>")) )] #[derive(Clone, Debug)] pub struct LU, C: Dim> -where DefaultAllocator: Allocator> + Allocator +where + DefaultAllocator: Allocator> + Allocator, { lu: MatrixMN, p: VectorN>, @@ -49,7 +46,8 @@ where DefaultAllocator: Allocator + Allocator>, MatrixMN: Copy, VectorN>: Copy, -{} +{ +} impl LU where @@ -133,7 +131,9 @@ where /// Applies the permutation matrix to a given matrix or vector in-place. #[inline] pub fn permute(&self, rhs: &mut MatrixMN) - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { let (nrows, ncols) = rhs.shape(); N::xlaswp( @@ -148,7 +148,9 @@ where } fn generic_solve_mut(&self, trans: u8, b: &mut MatrixMN) -> bool - where DefaultAllocator: Allocator + Allocator { + where + DefaultAllocator: Allocator + Allocator, + { let dim = self.lu.nrows(); assert!( @@ -236,7 +238,9 @@ where /// /// Returns `false` if no solution was found (the decomposed matrix is singular). pub fn solve_mut(&self, b: &mut MatrixMN) -> bool - where DefaultAllocator: Allocator + Allocator { + where + DefaultAllocator: Allocator + Allocator, + { self.generic_solve_mut(b'N', b) } @@ -245,7 +249,9 @@ where /// /// Returns `false` if no solution was found (the decomposed matrix is singular). pub fn solve_transpose_mut(&self, b: &mut MatrixMN) -> bool - where DefaultAllocator: Allocator + Allocator { + where + DefaultAllocator: Allocator + Allocator, + { self.generic_solve_mut(b'T', b) } @@ -253,10 +259,7 @@ where /// be determined. /// /// Returns `false` if no solution was found (the decomposed matrix is singular). - pub fn solve_adjoint_mut( - &self, - b: &mut MatrixMN, - ) -> bool + pub fn solve_adjoint_mut(&self, b: &mut MatrixMN) -> bool where DefaultAllocator: Allocator + Allocator, { diff --git a/nalgebra-lapack/src/qr.rs b/nalgebra-lapack/src/qr.rs index d9d28910..ac8ad672 100644 --- a/nalgebra-lapack/src/qr.rs +++ b/nalgebra-lapack/src/qr.rs @@ -4,11 +4,11 @@ use serde::{Deserialize, Serialize}; use num::Zero; use num_complex::Complex; +use crate::ComplexHelper; use na::allocator::Allocator; use na::dimension::{Dim, DimMin, DimMinimum, U1}; use na::storage::Storage; use na::{DefaultAllocator, Matrix, MatrixMN, Scalar, VectorN}; -use crate::ComplexHelper; use lapack; @@ -16,25 +16,22 @@ use lapack; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound( - serialize = "DefaultAllocator: Allocator + + serde(bound(serialize = "DefaultAllocator: Allocator + Allocator>, MatrixMN: Serialize, - VectorN>: Serialize" - )) + VectorN>: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound( - deserialize = "DefaultAllocator: Allocator + + serde(bound(deserialize = "DefaultAllocator: Allocator + Allocator>, MatrixMN: Deserialize<'de>, - VectorN>: Deserialize<'de>" - )) + VectorN>: Deserialize<'de>")) )] #[derive(Clone, Debug)] pub struct QR, C: Dim> -where DefaultAllocator: Allocator + Allocator> +where + DefaultAllocator: Allocator + Allocator>, { qr: MatrixMN, tau: VectorN>, @@ -45,13 +42,15 @@ where DefaultAllocator: Allocator + Allocator>, MatrixMN: Copy, VectorN>: Copy, -{} +{ +} impl, C: Dim> QR -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator + Allocator> + Allocator, C> - + Allocator> + + Allocator>, { /// Computes the QR decomposition of the matrix `m`. pub fn new(mut m: MatrixMN) -> Self { @@ -98,10 +97,11 @@ where DefaultAllocator: Allocator } impl, C: Dim> QR -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator + Allocator> + Allocator, C> - + Allocator> + + Allocator>, { /// Retrieves the matrices `(Q, R)` of this decompositions. pub fn unpack( diff --git a/nalgebra-lapack/src/schur.rs b/nalgebra-lapack/src/schur.rs index 50871975..5079efbf 100644 --- a/nalgebra-lapack/src/schur.rs +++ b/nalgebra-lapack/src/schur.rs @@ -34,7 +34,8 @@ use lapack; )] #[derive(Clone, Debug)] pub struct Schur -where DefaultAllocator: Allocator + Allocator +where + DefaultAllocator: Allocator + Allocator, { re: VectorN, im: VectorN, @@ -51,7 +52,8 @@ where } impl Schur -where DefaultAllocator: Allocator + Allocator +where + DefaultAllocator: Allocator + Allocator, { /// Computes the eigenvalues and real Schur form of the matrix `m`. /// @@ -146,7 +148,9 @@ where DefaultAllocator: Allocator + Allocator /// Computes the complex eigenvalues of the decomposed matrix. pub fn complex_eigenvalues(&self) -> VectorN, D> - where DefaultAllocator: Allocator, D> { + where + DefaultAllocator: Allocator, D>, + { let mut out = unsafe { VectorN::new_uninitialized_generic(self.t.data.shape().0, U1) }; for i in 0..out.len() { diff --git a/nalgebra-lapack/src/svd.rs b/nalgebra-lapack/src/svd.rs index 43bb1c20..217e8f52 100644 --- a/nalgebra-lapack/src/svd.rs +++ b/nalgebra-lapack/src/svd.rs @@ -15,29 +15,26 @@ use lapack; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound( - serialize = "DefaultAllocator: Allocator> + + serde(bound(serialize = "DefaultAllocator: Allocator> + Allocator + Allocator, MatrixN: Serialize, MatrixN: Serialize, - VectorN>: Serialize" - )) + VectorN>: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound( - serialize = "DefaultAllocator: Allocator> + + serde(bound(serialize = "DefaultAllocator: Allocator> + Allocator + Allocator, MatrixN: Deserialize<'de>, MatrixN: Deserialize<'de>, - VectorN>: Deserialize<'de>" - )) + VectorN>: Deserialize<'de>")) )] #[derive(Clone, Debug)] pub struct SVD, C: Dim> -where DefaultAllocator: Allocator + Allocator> + Allocator +where + DefaultAllocator: Allocator + Allocator> + Allocator, { /// The left-singular vectors `U` of this SVD. pub u: MatrixN, // FIXME: should be MatrixMN> @@ -53,25 +50,28 @@ where MatrixMN: Copy, MatrixMN: Copy, VectorN>: Copy, -{} +{ +} /// Trait implemented by floats (`f32`, `f64`) and complex floats (`Complex`, `Complex`) /// supported by the Singular Value Decompotition. pub trait SVDScalar, C: Dim>: Scalar -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator + Allocator + Allocator> - + Allocator + + Allocator, { /// Computes the SVD decomposition of `m`. fn compute(m: MatrixMN) -> Option>; } impl, R: DimMin, C: Dim> SVD -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator + Allocator + Allocator> - + Allocator + + Allocator, { /// Computes the Singular Value Decomposition of `matrix`. pub fn new(m: MatrixMN) -> Option { diff --git a/nalgebra-lapack/src/symmetric_eigen.rs b/nalgebra-lapack/src/symmetric_eigen.rs index 3a21c797..93961328 100644 --- a/nalgebra-lapack/src/symmetric_eigen.rs +++ b/nalgebra-lapack/src/symmetric_eigen.rs @@ -32,7 +32,8 @@ use lapack; )] #[derive(Clone, Debug)] pub struct SymmetricEigen -where DefaultAllocator: Allocator + Allocator +where + DefaultAllocator: Allocator + Allocator, { /// The eigenvectors of the decomposed matrix. pub eigenvectors: MatrixN, @@ -50,7 +51,8 @@ where } impl SymmetricEigen -where DefaultAllocator: Allocator + Allocator +where + DefaultAllocator: Allocator + Allocator, { /// Computes the eigenvalues and eigenvectors of the symmetric matrix `m`. /// @@ -79,8 +81,7 @@ where DefaultAllocator: Allocator + Allocator fn do_decompose( mut m: MatrixN, eigenvectors: bool, - ) -> Option<(VectorN, Option>)> - { + ) -> Option<(VectorN, Option>)> { assert!( m.is_square(), "Unable to compute the eigenvalue decomposition of a non-square matrix." diff --git a/nalgebra-lapack/tests/linalg/cholesky.rs b/nalgebra-lapack/tests/linalg/cholesky.rs index 01561532..f811726a 100644 --- a/nalgebra-lapack/tests/linalg/cholesky.rs +++ b/nalgebra-lapack/tests/linalg/cholesky.rs @@ -3,7 +3,7 @@ use std::cmp; use na::{DMatrix, DVector, Matrix3, Matrix4, Matrix4x3, Vector4}; use nl::Cholesky; -quickcheck!{ +quickcheck! { fn cholesky(m: DMatrix) -> bool { if m.len() != 0 { let m = &m * m.transpose(); diff --git a/nalgebra-lapack/tests/linalg/lu.rs b/nalgebra-lapack/tests/linalg/lu.rs index 652d1032..71293436 100644 --- a/nalgebra-lapack/tests/linalg/lu.rs +++ b/nalgebra-lapack/tests/linalg/lu.rs @@ -3,7 +3,7 @@ use std::cmp; use na::{DMatrix, DVector, Matrix3x4, Matrix4, Matrix4x3, Vector4}; use nl::LU; -quickcheck!{ +quickcheck! { fn lup(m: DMatrix) -> bool { if m.len() != 0 { let lup = LU::new(m.clone()); diff --git a/nalgebra-lapack/tests/linalg/qr.rs b/nalgebra-lapack/tests/linalg/qr.rs index ebdb9b34..1d193a86 100644 --- a/nalgebra-lapack/tests/linalg/qr.rs +++ b/nalgebra-lapack/tests/linalg/qr.rs @@ -1,7 +1,7 @@ use na::{DMatrix, Matrix4x3}; use nl::QR; -quickcheck!{ +quickcheck! { fn qr(m: DMatrix) -> bool { let qr = QR::new(m.clone()); let q = qr.q(); diff --git a/nalgebra-lapack/tests/linalg/real_eigensystem.rs b/nalgebra-lapack/tests/linalg/real_eigensystem.rs index f3130a54..a711d882 100644 --- a/nalgebra-lapack/tests/linalg/real_eigensystem.rs +++ b/nalgebra-lapack/tests/linalg/real_eigensystem.rs @@ -3,7 +3,7 @@ use std::cmp; use na::{DMatrix, Matrix4}; use nl::Eigen; -quickcheck!{ +quickcheck! { fn eigensystem(n: usize) -> bool { if n != 0 { let n = cmp::min(n, 25); diff --git a/nalgebra-lapack/tests/linalg/svd.rs b/nalgebra-lapack/tests/linalg/svd.rs index 9f15b83a..20ebd9d5 100644 --- a/nalgebra-lapack/tests/linalg/svd.rs +++ b/nalgebra-lapack/tests/linalg/svd.rs @@ -1,7 +1,7 @@ use na::{DMatrix, Matrix3x4}; use nl::SVD; -quickcheck!{ +quickcheck! { fn svd(m: DMatrix) -> bool { if m.nrows() != 0 && m.ncols() != 0 { let svd = SVD::new(m.clone()).unwrap(); diff --git a/nalgebra-lapack/tests/linalg/symmetric_eigen.rs b/nalgebra-lapack/tests/linalg/symmetric_eigen.rs index 42074ada..1d47f982 100644 --- a/nalgebra-lapack/tests/linalg/symmetric_eigen.rs +++ b/nalgebra-lapack/tests/linalg/symmetric_eigen.rs @@ -3,7 +3,7 @@ use std::cmp; use na::{DMatrix, Matrix4}; use nl::SymmetricEigen; -quickcheck!{ +quickcheck! { fn symmetric_eigen(n: usize) -> bool { let n = cmp::max(1, cmp::min(n, 10)); let m = DMatrix::::new_random(n, n); diff --git a/src/base/alias.rs b/src/base/alias.rs index a8925cf3..e798ea35 100644 --- a/src/base/alias.rs +++ b/src/base/alias.rs @@ -1,9 +1,9 @@ #[cfg(any(feature = "alloc", feature = "std"))] use crate::base::dimension::Dynamic; use crate::base::dimension::{U1, U2, U3, U4, U5, U6}; +use crate::base::storage::Owned; #[cfg(any(feature = "std", feature = "alloc"))] use crate::base::vec_storage::VecStorage; -use crate::base::storage::Owned; use crate::base::Matrix; /* diff --git a/src/base/alias_slice.rs b/src/base/alias_slice.rs index 3a332def..ee55f15b 100644 --- a/src/base/alias_slice.rs +++ b/src/base/alias_slice.rs @@ -179,20 +179,27 @@ pub type VectorSliceN<'a, N, D, RStride = U1, CStride = D> = Matrix>; /// A column vector slice dynamic numbers of rows and columns. -pub type DVectorSlice<'a, N, RStride = U1, CStride = Dynamic> = VectorSliceN<'a, N, Dynamic, RStride, CStride>; +pub type DVectorSlice<'a, N, RStride = U1, CStride = Dynamic> = + VectorSliceN<'a, N, Dynamic, RStride, CStride>; /// A 1D column vector slice. -pub type VectorSlice1<'a, N, RStride = U1, CStride = U1> = VectorSliceN<'a, N, U1, RStride, CStride>; +pub type VectorSlice1<'a, N, RStride = U1, CStride = U1> = + VectorSliceN<'a, N, U1, RStride, CStride>; /// A 2D column vector slice. -pub type VectorSlice2<'a, N, RStride = U1, CStride = U2> = VectorSliceN<'a, N, U2, RStride, CStride>; +pub type VectorSlice2<'a, N, RStride = U1, CStride = U2> = + VectorSliceN<'a, N, U2, RStride, CStride>; /// A 3D column vector slice. -pub type VectorSlice3<'a, N, RStride = U1, CStride = U3> = VectorSliceN<'a, N, U3, RStride, CStride>; +pub type VectorSlice3<'a, N, RStride = U1, CStride = U3> = + VectorSliceN<'a, N, U3, RStride, CStride>; /// A 4D column vector slice. -pub type VectorSlice4<'a, N, RStride = U1, CStride = U4> = VectorSliceN<'a, N, U4, RStride, CStride>; +pub type VectorSlice4<'a, N, RStride = U1, CStride = U4> = + VectorSliceN<'a, N, U4, RStride, CStride>; /// A 5D column vector slice. -pub type VectorSlice5<'a, N, RStride = U1, CStride = U5> = VectorSliceN<'a, N, U5, RStride, CStride>; +pub type VectorSlice5<'a, N, RStride = U1, CStride = U5> = + VectorSliceN<'a, N, U5, RStride, CStride>; /// A 6D column vector slice. -pub type VectorSlice6<'a, N, RStride = U1, CStride = U6> = VectorSliceN<'a, N, U6, RStride, CStride>; +pub type VectorSlice6<'a, N, RStride = U1, CStride = U6> = + VectorSliceN<'a, N, U6, RStride, CStride>; /* * @@ -371,17 +378,24 @@ pub type VectorSliceMutN<'a, N, D, RStride = U1, CStride = D> = Matrix>; /// A mutable column vector slice dynamic numbers of rows and columns. -pub type DVectorSliceMut<'a, N, RStride = U1, CStride = Dynamic> = VectorSliceMutN<'a, N, Dynamic, RStride, CStride>; +pub type DVectorSliceMut<'a, N, RStride = U1, CStride = Dynamic> = + VectorSliceMutN<'a, N, Dynamic, RStride, CStride>; /// A 1D mutable column vector slice. -pub type VectorSliceMut1<'a, N, RStride = U1, CStride = U1> = VectorSliceMutN<'a, N, U1, RStride, CStride>; +pub type VectorSliceMut1<'a, N, RStride = U1, CStride = U1> = + VectorSliceMutN<'a, N, U1, RStride, CStride>; /// A 2D mutable column vector slice. -pub type VectorSliceMut2<'a, N, RStride = U1, CStride = U2> = VectorSliceMutN<'a, N, U2, RStride, CStride>; +pub type VectorSliceMut2<'a, N, RStride = U1, CStride = U2> = + VectorSliceMutN<'a, N, U2, RStride, CStride>; /// A 3D mutable column vector slice. -pub type VectorSliceMut3<'a, N, RStride = U1, CStride = U3> = VectorSliceMutN<'a, N, U3, RStride, CStride>; +pub type VectorSliceMut3<'a, N, RStride = U1, CStride = U3> = + VectorSliceMutN<'a, N, U3, RStride, CStride>; /// A 4D mutable column vector slice. -pub type VectorSliceMut4<'a, N, RStride = U1, CStride = U4> = VectorSliceMutN<'a, N, U4, RStride, CStride>; +pub type VectorSliceMut4<'a, N, RStride = U1, CStride = U4> = + VectorSliceMutN<'a, N, U4, RStride, CStride>; /// A 5D mutable column vector slice. -pub type VectorSliceMut5<'a, N, RStride = U1, CStride = U5> = VectorSliceMutN<'a, N, U5, RStride, CStride>; +pub type VectorSliceMut5<'a, N, RStride = U1, CStride = U5> = + VectorSliceMutN<'a, N, U5, RStride, CStride>; /// A 6D mutable column vector slice. -pub type VectorSliceMut6<'a, N, RStride = U1, CStride = U6> = VectorSliceMutN<'a, N, U6, RStride, CStride>; +pub type VectorSliceMut6<'a, N, RStride = U1, CStride = U6> = + VectorSliceMutN<'a, N, U6, RStride, CStride>; diff --git a/src/base/allocator.rs b/src/base/allocator.rs index 0ad30981..1b2122db 100644 --- a/src/base/allocator.rs +++ b/src/base/allocator.rs @@ -79,7 +79,8 @@ where N: Scalar, DefaultAllocator: Allocator + Allocator, SameShapeC>, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, -{} +{ +} // XXX: Bad name. /// Restricts the given number of rows to be equal. @@ -100,4 +101,5 @@ where N: Scalar, DefaultAllocator: Allocator + Allocator>, ShapeConstraint: SameNumberOfRows, -{} +{ +} diff --git a/src/base/array_storage.rs b/src/base/array_storage.rs index bebb8740..3ff06e89 100644 --- a/src/base/array_storage.rs +++ b/src/base/array_storage.rs @@ -44,7 +44,7 @@ where data: GenericArray>, } -#[deprecated(note="renamed to `ArrayStorage`")] +#[deprecated(note = "renamed to `ArrayStorage`")] /// Renamed to [ArrayStorage]. pub type MatrixArray = ArrayStorage; @@ -111,7 +111,8 @@ where R::Value: Mul, Prod: ArrayLength, GenericArray>: Copy, -{} +{ +} impl Clone for ArrayStorage where @@ -136,7 +137,8 @@ where C: DimName, R::Value: Mul, Prod: ArrayLength, -{} +{ +} impl PartialEq for ArrayStorage where @@ -186,13 +188,17 @@ where #[inline] fn into_owned(self) -> Owned - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self } #[inline] fn clone_owned(&self) -> Owned - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { let it = self.iter().cloned(); DefaultAllocator::allocate_from_iterator(self.shape().0, self.shape().1, it) @@ -232,7 +238,8 @@ where R::Value: Mul, Prod: ArrayLength, DefaultAllocator: Allocator, -{} +{ +} unsafe impl ContiguousStorageMut for ArrayStorage where @@ -242,7 +249,8 @@ where R::Value: Mul, Prod: ArrayLength, DefaultAllocator: Allocator, -{} +{ +} /* * @@ -260,7 +268,9 @@ where Prod: ArrayLength, { fn serialize(&self, serializer: S) -> Result - where S: Serializer { + where + S: Serializer, + { let mut serializer = serializer.serialize_seq(Some(R::dim() * C::dim()))?; for e in self.iter() { @@ -281,7 +291,9 @@ where Prod: ArrayLength, { fn deserialize(deserializer: D) -> Result - where D: Deserializer<'a> { + where + D: Deserializer<'a>, + { deserializer.deserialize_seq(ArrayStorageVisitor::new()) } } @@ -326,12 +338,15 @@ where #[inline] fn visit_seq(self, mut visitor: V) -> Result, V::Error> - where V: SeqAccess<'a> { + where + V: SeqAccess<'a>, + { let mut out: Self::Value = unsafe { mem::uninitialized() }; let mut curr = 0; while let Some(value) = visitor.next_element()? { - *out.get_mut(curr).ok_or_else(|| V::Error::invalid_length(curr, &self))? = value; + *out.get_mut(curr) + .ok_or_else(|| V::Error::invalid_length(curr, &self))? = value; curr += 1; } diff --git a/src/base/blas.rs b/src/base/blas.rs index 0c9ef1a7..add17af2 100644 --- a/src/base/blas.rs +++ b/src/base/blas.rs @@ -104,7 +104,9 @@ impl> Vector { /// ``` #[inline] pub fn iamax(&self) -> usize - where N: Signed { + where + N: Signed, + { assert!(!self.is_empty(), "The input vector must not be empty."); let mut the_max = unsafe { self.vget_unchecked(0).abs() }; @@ -175,7 +177,9 @@ impl> Vector { /// ``` #[inline] pub fn iamin(&self) -> usize - where N: Signed { + where + N: Signed, + { assert!(!self.is_empty(), "The input vector must not be empty."); let mut the_min = unsafe { self.vget_unchecked(0).abs() }; @@ -265,7 +269,8 @@ impl> Matri } impl> Matrix -where N: Scalar + Zero + ClosedAdd + ClosedMul +where + N: Scalar + Zero + ClosedAdd + ClosedMul, { #[inline(always)] fn dotx( @@ -535,7 +540,9 @@ fn array_axcpy( } fn array_axc(y: &mut [N], a: N, x: &[N], c: N, stride1: usize, stride2: usize, len: usize) -where N: Scalar + Zero + ClosedAdd + ClosedMul { +where + N: Scalar + Zero + ClosedAdd + ClosedMul, +{ for i in 0..len { unsafe { *y.get_unchecked_mut(i * stride1) = a.inlined_clone() @@ -948,7 +955,8 @@ where } impl> Matrix -where N: Scalar + Zero + ClosedAdd + ClosedMul +where + N: Scalar + Zero + ClosedAdd + ClosedMul, { #[inline(always)] fn gerx( @@ -1321,7 +1329,8 @@ where N: Scalar + Zero + ClosedAdd + ClosedMul } impl> Matrix -where N: Scalar + Zero + ClosedAdd + ClosedMul +where + N: Scalar + Zero + ClosedAdd + ClosedMul, { #[inline(always)] fn xxgerx( @@ -1468,7 +1477,8 @@ where N: Scalar + Zero + ClosedAdd + ClosedMul } impl> SquareMatrix -where N: Scalar + Zero + One + ClosedAdd + ClosedMul +where + N: Scalar + Zero + One + ClosedAdd + ClosedMul, { /// Computes the quadratic form `self = alpha * lhs * mid * lhs.transpose() + beta * self`. /// diff --git a/src/base/cg.rs b/src/base/cg.rs index e61483b8..6a7db4bd 100644 --- a/src/base/cg.rs +++ b/src/base/cg.rs @@ -253,7 +253,9 @@ impl { + where + D: DimNameSub, + { let mut to_scale = self.fixed_rows_mut::>(0); to_scale *= scaling; } @@ -261,7 +263,9 @@ impl { + where + D: DimNameSub, + { let mut to_scale = self.fixed_columns_mut::>(0); to_scale *= scaling; } @@ -331,17 +335,17 @@ impl, S: Storage> SquareMatrix -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator + Allocator> - + Allocator, DimNameDiff> + + Allocator, DimNameDiff>, { /// Transforms the given vector, assuming the matrix `self` uses homogeneous coordinates. #[inline] pub fn transform_vector( &self, v: &VectorN>, - ) -> VectorN> - { + ) -> VectorN> { let transform = self.fixed_slice::, DimNameDiff>(0, 0); let normalizer = self.fixed_slice::>(D::dim() - 1, 0); let n = normalizer.tr_dot(&v); @@ -358,8 +362,7 @@ where DefaultAllocator: Allocator pub fn transform_point( &self, pt: &Point>, - ) -> Point> - { + ) -> Point> { let transform = self.fixed_slice::, DimNameDiff>(0, 0); let translation = self.fixed_slice::, U1>(0, D::dim() - 1); let normalizer = self.fixed_slice::>(D::dim() - 1, 0); diff --git a/src/base/constraint.rs b/src/base/constraint.rs index 89226fe3..f681dc25 100644 --- a/src/base/constraint.rs +++ b/src/base/constraint.rs @@ -8,8 +8,10 @@ pub struct ShapeConstraint; /// Constraints `C1` and `R2` to be equivalent. pub trait AreMultipliable: DimEq {} -impl AreMultipliable for ShapeConstraint where ShapeConstraint: DimEq -{} +impl AreMultipliable for ShapeConstraint where + ShapeConstraint: DimEq +{ +} /// Constraints `D1` and `D2` to be equivalent. pub trait DimEq { diff --git a/src/base/construction.rs b/src/base/construction.rs index f9223179..ae8c10d4 100644 --- a/src/base/construction.rs +++ b/src/base/construction.rs @@ -28,7 +28,8 @@ use crate::base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Scalar, Unit, Vec * */ impl MatrixMN -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// Creates a new uninitialized matrix. If the matrix has a compile-time dimension, this panics /// if `nrows != R::to_usize()` or `ncols != C::to_usize()`. @@ -56,14 +57,18 @@ where DefaultAllocator: Allocator /// Creates a matrix with all its elements set to 0. #[inline] pub fn zeros_generic(nrows: R, ncols: C) -> Self - where N: Zero { + where + N: Zero, + { Self::from_element_generic(nrows, ncols, N::zero()) } /// Creates a matrix with all its elements filled by an iterator. #[inline] pub fn from_iterator_generic(nrows: R, ncols: C, iter: I) -> Self - where I: IntoIterator { + where + I: IntoIterator, + { Self::from_data(DefaultAllocator::allocate_from_iterator(nrows, ncols, iter)) } @@ -102,7 +107,9 @@ where DefaultAllocator: Allocator /// coordinates. #[inline] pub fn from_fn_generic(nrows: R, ncols: C, mut f: F) -> Self - where F: FnMut(usize, usize) -> N { + where + F: FnMut(usize, usize) -> N, + { let mut res = unsafe { Self::new_uninitialized_generic(nrows, ncols) }; for j in 0..ncols.value() { @@ -120,7 +127,9 @@ where DefaultAllocator: Allocator /// to the identity matrix. All other entries are set to zero. #[inline] pub fn identity_generic(nrows: R, ncols: C) -> Self - where N: Zero + One { + where + N: Zero + One, + { Self::from_diagonal_element_generic(nrows, ncols, N::one()) } @@ -130,7 +139,9 @@ where DefaultAllocator: Allocator /// to the identity matrix. All other entries are set to zero. #[inline] pub fn from_diagonal_element_generic(nrows: R, ncols: C, elt: N) -> Self - where N: Zero + One { + where + N: Zero + One, + { let mut res = Self::zeros_generic(nrows, ncols); for i in 0..crate::min(nrows.value(), ncols.value()) { @@ -146,7 +157,9 @@ where DefaultAllocator: Allocator /// Panics if `elts.len()` is larger than the minimum among `nrows` and `ncols`. #[inline] pub fn from_partial_diagonal_generic(nrows: R, ncols: C, elts: &[N]) -> Self - where N: Zero { + where + N: Zero, + { let mut res = Self::zeros_generic(nrows, ncols); assert!( elts.len() <= crate::min(nrows.value(), ncols.value()), @@ -178,7 +191,9 @@ where DefaultAllocator: Allocator /// ``` #[inline] pub fn from_rows(rows: &[Matrix]) -> Self - where SB: Storage { + where + SB: Storage, + { assert!(rows.len() > 0, "At least one row must be given."); let nrows = R::try_to_usize().unwrap_or(rows.len()); let ncols = rows[0].len(); @@ -218,7 +233,9 @@ where DefaultAllocator: Allocator /// ``` #[inline] pub fn from_columns(columns: &[Vector]) -> Self - where SB: Storage { + where + SB: Storage, + { assert!(columns.len() > 0, "At least one column must be given."); let ncols = C::try_to_usize().unwrap_or(columns.len()); let nrows = columns[0].len(); @@ -244,7 +261,9 @@ where DefaultAllocator: Allocator #[inline] #[cfg(feature = "std")] pub fn new_random_generic(nrows: R, ncols: C) -> Self - where Standard: Distribution { + where + Standard: Distribution, + { Self::from_fn_generic(nrows, ncols, |_, _| rand::random()) } @@ -255,8 +274,7 @@ where DefaultAllocator: Allocator ncols: C, distribution: &Distr, rng: &mut G, - ) -> Self - { + ) -> Self { Self::from_fn_generic(nrows, ncols, |_, _| distribution.sample(rng)) } @@ -309,7 +327,9 @@ where /// ``` #[inline] pub fn from_diagonal>(diag: &Vector) -> Self - where N: Zero { + where + N: Zero, + { let (dim, _) = diag.data.shape(); let mut res = Self::zeros_generic(dim, dim); @@ -994,7 +1014,9 @@ where /// The column vector with a 1 as its first component, and zero elsewhere. #[inline] pub fn x() -> Self - where R::Value: Cmp { + where + R::Value: Cmp, + { let mut res = Self::zeros(); unsafe { *res.vget_unchecked_mut(0) = N::one(); @@ -1006,7 +1028,9 @@ where /// The column vector with a 1 as its second component, and zero elsewhere. #[inline] pub fn y() -> Self - where R::Value: Cmp { + where + R::Value: Cmp, + { let mut res = Self::zeros(); unsafe { *res.vget_unchecked_mut(1) = N::one(); @@ -1018,7 +1042,9 @@ where /// The column vector with a 1 as its third component, and zero elsewhere. #[inline] pub fn z() -> Self - where R::Value: Cmp { + where + R::Value: Cmp, + { let mut res = Self::zeros(); unsafe { *res.vget_unchecked_mut(2) = N::one(); @@ -1030,7 +1056,9 @@ where /// The column vector with a 1 as its fourth component, and zero elsewhere. #[inline] pub fn w() -> Self - where R::Value: Cmp { + where + R::Value: Cmp, + { let mut res = Self::zeros(); unsafe { *res.vget_unchecked_mut(3) = N::one(); @@ -1042,7 +1070,9 @@ where /// The column vector with a 1 as its fifth component, and zero elsewhere. #[inline] pub fn a() -> Self - where R::Value: Cmp { + where + R::Value: Cmp, + { let mut res = Self::zeros(); unsafe { *res.vget_unchecked_mut(4) = N::one(); @@ -1054,7 +1084,9 @@ where /// The column vector with a 1 as its sixth component, and zero elsewhere. #[inline] pub fn b() -> Self - where R::Value: Cmp { + where + R::Value: Cmp, + { let mut res = Self::zeros(); unsafe { *res.vget_unchecked_mut(5) = N::one(); @@ -1066,42 +1098,54 @@ where /// The unit column vector with a 1 as its first component, and zero elsewhere. #[inline] pub fn x_axis() -> Unit - where R::Value: Cmp { + where + R::Value: Cmp, + { Unit::new_unchecked(Self::x()) } /// The unit column vector with a 1 as its second component, and zero elsewhere. #[inline] pub fn y_axis() -> Unit - where R::Value: Cmp { + where + R::Value: Cmp, + { Unit::new_unchecked(Self::y()) } /// The unit column vector with a 1 as its third component, and zero elsewhere. #[inline] pub fn z_axis() -> Unit - where R::Value: Cmp { + where + R::Value: Cmp, + { Unit::new_unchecked(Self::z()) } /// The unit column vector with a 1 as its fourth component, and zero elsewhere. #[inline] pub fn w_axis() -> Unit - where R::Value: Cmp { + where + R::Value: Cmp, + { Unit::new_unchecked(Self::w()) } /// The unit column vector with a 1 as its fifth component, and zero elsewhere. #[inline] pub fn a_axis() -> Unit - where R::Value: Cmp { + where + R::Value: Cmp, + { Unit::new_unchecked(Self::a()) } /// The unit column vector with a 1 as its sixth component, and zero elsewhere. #[inline] pub fn b_axis() -> Unit - where R::Value: Cmp { + where + R::Value: Cmp, + { Unit::new_unchecked(Self::b()) } } diff --git a/src/base/construction_slice.rs b/src/base/construction_slice.rs index 4f745a65..d63b374b 100644 --- a/src/base/construction_slice.rs +++ b/src/base/construction_slice.rs @@ -23,8 +23,7 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> ncols: C, rstride: RStride, cstride: CStride, - ) -> Self - { + ) -> Self { let data = SliceStorage::from_raw_parts( data.as_ptr().offset(start as isize), (nrows, ncols), @@ -44,8 +43,7 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> ncols: C, rstride: RStride, cstride: CStride, - ) -> Self - { + ) -> Self { // NOTE: The assertion implements the following formula, but without subtractions to avoid // underflow panics: // len >= (ncols - 1) * cstride + (nrows - 1) * rstride + 1 @@ -76,8 +74,7 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> ncols: C, rstride: RStride, cstride: CStride, - ) -> Self - { + ) -> Self { let data = SliceStorageMut::from_raw_parts( data.as_mut_ptr().offset(start as isize), (nrows, ncols), @@ -97,8 +94,7 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> ncols: C, rstride: RStride, cstride: CStride, - ) -> Self - { + ) -> Self { // NOTE: The assertion implements the following formula, but without subtractions to avoid // underflow panics: // len >= (ncols - 1) * cstride + (nrows - 1) * rstride + 1 @@ -108,24 +104,27 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> "Matrix slice: input data buffer to small." ); - assert!({ - let nrows = nrows.value(); - let ncols = ncols.value(); - let rstride = rstride.value(); - let cstride = cstride.value(); + assert!( + { + let nrows = nrows.value(); + let ncols = ncols.value(); + let rstride = rstride.value(); + let cstride = cstride.value(); - nrows * ncols <= 1 || - match (rstride, cstride) { - (0, 0) => false, // otherwise: matrix[(0, 0)] == index[(nrows - 1, ncols - 1)], - (0, _) => nrows <= 1, // otherwise: matrix[(0, 0)] == index[(nrows - 1, 0)], - (_, 0) => ncols <= 1, // otherwise: matrix[(0, 0)] == index[(0, ncols - 1)], - (_, _) => { // otherwise: matrix[(0, numer)] == index[(denom, 0)] - let ratio = Ratio::new(rstride, cstride); - nrows <= *ratio.denom() || ncols <= *ratio.numer() + nrows * ncols <= 1 + || match (rstride, cstride) { + (0, 0) => false, // otherwise: matrix[(0, 0)] == index[(nrows - 1, ncols - 1)], + (0, _) => nrows <= 1, // otherwise: matrix[(0, 0)] == index[(nrows - 1, 0)], + (_, 0) => ncols <= 1, // otherwise: matrix[(0, 0)] == index[(0, ncols - 1)], + (_, _) => { + // otherwise: matrix[(0, numer)] == index[(denom, 0)] + let ratio = Ratio::new(rstride, cstride); + nrows <= *ratio.denom() || ncols <= *ratio.numer() + } } - } }, - "Matrix slice: dimensions and strides result in aliased indices."); + "Matrix slice: dimensions and strides result in aliased indices." + ); unsafe { Self::from_slice_with_strides_generic_unchecked(data, 0, nrows, ncols, rstride, cstride) @@ -144,8 +143,7 @@ impl<'a, N: Scalar, R: Dim, C: Dim> MatrixSliceMN<'a, N, R, C> { start: usize, nrows: R, ncols: C, - ) -> Self - { + ) -> Self { Self::from_slice_with_strides_generic_unchecked(data, start, nrows, ncols, U1, nrows) } @@ -170,8 +168,7 @@ impl<'a, N: Scalar, R: Dim, C: Dim> MatrixSliceMutMN<'a, N, R, C> { start: usize, nrows: R, ncols: C, - ) -> Self - { + ) -> Self { Self::from_slice_with_strides_generic_unchecked(data, start, nrows, ncols, U1, nrows) } diff --git a/src/base/default_allocator.rs b/src/base/default_allocator.rs index c07c8708..8e3dae7e 100644 --- a/src/base/default_allocator.rs +++ b/src/base/default_allocator.rs @@ -15,13 +15,13 @@ use generic_array::ArrayLength; use typenum::Prod; use crate::base::allocator::{Allocator, Reallocator}; +use crate::base::array_storage::ArrayStorage; #[cfg(any(feature = "alloc", feature = "std"))] use crate::base::dimension::Dynamic; use crate::base::dimension::{Dim, DimName}; -use crate::base::array_storage::ArrayStorage; +use crate::base::storage::{Storage, StorageMut}; #[cfg(any(feature = "std", feature = "alloc"))] use crate::base::vec_storage::VecStorage; -use crate::base::storage::{Storage, StorageMut}; use crate::base::Scalar; /* @@ -54,8 +54,7 @@ where nrows: R, ncols: C, iter: I, - ) -> Self::Buffer - { + ) -> Self::Buffer { let mut res = unsafe { Self::allocate_uninitialized(nrows, ncols) }; let mut count = 0; @@ -94,8 +93,7 @@ impl Allocator for DefaultAllocator { nrows: Dynamic, ncols: C, iter: I, - ) -> Self::Buffer - { + ) -> Self::Buffer { let it = iter.into_iter(); let res: Vec = it.collect(); assert!(res.len() == nrows.value() * ncols.value(), @@ -125,8 +123,7 @@ impl Allocator for DefaultAllocator { nrows: R, ncols: Dynamic, iter: I, - ) -> Self::Buffer - { + ) -> Self::Buffer { let it = iter.into_iter(); let res: Vec = it.collect(); assert!(res.len() == nrows.value() * ncols.value(), @@ -157,8 +154,7 @@ where rto: RTo, cto: CTo, buf: >::Buffer, - ) -> ArrayStorage - { + ) -> ArrayStorage { let mut res = >::allocate_uninitialized(rto, cto); let (rfrom, cfrom) = buf.shape(); @@ -186,8 +182,7 @@ where rto: Dynamic, cto: CTo, buf: ArrayStorage, - ) -> VecStorage - { + ) -> VecStorage { let mut res = >::allocate_uninitialized(rto, cto); let (rfrom, cfrom) = buf.shape(); @@ -215,8 +210,7 @@ where rto: RTo, cto: Dynamic, buf: ArrayStorage, - ) -> VecStorage - { + ) -> VecStorage { let mut res = >::allocate_uninitialized(rto, cto); let (rfrom, cfrom) = buf.shape(); @@ -239,8 +233,7 @@ impl Reallocator, - ) -> VecStorage - { + ) -> VecStorage { let new_buf = buf.resize(rto.value() * cto.value()); VecStorage::new(rto, cto, new_buf) } @@ -255,8 +248,7 @@ impl Reallocator, - ) -> VecStorage - { + ) -> VecStorage { let new_buf = buf.resize(rto.value() * cto.value()); VecStorage::new(rto, cto, new_buf) } @@ -271,8 +263,7 @@ impl Reallocator, - ) -> VecStorage - { + ) -> VecStorage { let new_buf = buf.resize(rto.value() * cto.value()); VecStorage::new(rto, cto, new_buf) } @@ -287,8 +278,7 @@ impl Reallocator, - ) -> VecStorage - { + ) -> VecStorage { let new_buf = buf.resize(rto.value() * cto.value()); VecStorage::new(rto, cto, new_buf) } diff --git a/src/base/dimension.rs b/src/base/dimension.rs index e7150e65..c171ff23 100644 --- a/src/base/dimension.rs +++ b/src/base/dimension.rs @@ -30,7 +30,9 @@ impl Dynamic { #[cfg(feature = "serde-serialize")] impl Serialize for Dynamic { fn serialize(&self, serializer: S) -> Result - where S: Serializer { + where + S: Serializer, + { self.value.serialize(serializer) } } @@ -38,7 +40,9 @@ impl Serialize for Dynamic { #[cfg(feature = "serde-serialize")] impl<'de> Deserialize<'de> for Dynamic { fn deserialize(deserializer: D) -> Result - where D: Deserializer<'de> { + where + D: Deserializer<'de>, + { usize::deserialize(deserializer).map(|x| Dynamic { value: x }) } } diff --git a/src/base/edition.rs b/src/base/edition.rs index b84a6110..b3133648 100644 --- a/src/base/edition.rs +++ b/src/base/edition.rs @@ -22,7 +22,9 @@ impl> Matrix { /// Extracts the upper triangular part of this matrix (including the diagonal). #[inline] pub fn upper_triangle(&self) -> MatrixMN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { let mut res = self.clone_owned(); res.fill_lower_triangle(N::zero(), 1); @@ -32,7 +34,9 @@ impl> Matrix { /// Extracts the lower triangular part of this matrix (including the diagonal). #[inline] pub fn lower_triangle(&self) -> MatrixMN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { let mut res = self.clone_owned(); res.fill_upper_triangle(N::zero(), 1); @@ -64,7 +68,10 @@ impl> Matrix { let src = self.column(j); for (destination, source) in irows.clone().enumerate() { - unsafe { *res.vget_unchecked_mut(destination) = src.vget_unchecked(*source).inlined_clone() } + unsafe { + *res.vget_unchecked_mut(destination) = + src.vget_unchecked(*source).inlined_clone() + } } } @@ -104,7 +111,9 @@ impl> Matrix { /// Fills `self` with the identity matrix. #[inline] pub fn fill_with_identity(&mut self) - where N: Zero + One { + where + N: Zero + One, + { self.fill(N::zero()); self.fill_diagonal(N::one()); } @@ -350,7 +359,7 @@ impl> Matrix { where R: DimSub, DefaultAllocator: Reallocator, - { + { let mut m = self.into_owned(); let (nrows, ncols) = m.data.shape(); let mut offset: usize = 0; @@ -371,7 +380,7 @@ impl> Matrix { unsafe { Matrix::from_data(DefaultAllocator::reallocate_copy( - nrows.sub(Dynamic::from_usize(offset / ncols.value ())), + nrows.sub(Dynamic::from_usize(offset / ncols.value())), ncols, m.data, )) @@ -693,7 +702,9 @@ impl> Matrix { /// rows and/or columns than `self`, then the extra rows or columns are filled with `val`. #[cfg(any(feature = "std", feature = "alloc"))] pub fn resize(self, new_nrows: usize, new_ncols: usize, val: N) -> DMatrix - where DefaultAllocator: Reallocator { + where + DefaultAllocator: Reallocator, + { self.resize_generic(Dynamic::new(new_nrows), Dynamic::new(new_ncols), val) } @@ -703,7 +714,9 @@ impl> Matrix { /// rows than `self`, then the extra rows are filled with `val`. #[cfg(any(feature = "std", feature = "alloc"))] pub fn resize_vertically(self, new_nrows: usize, val: N) -> MatrixMN - where DefaultAllocator: Reallocator { + where + DefaultAllocator: Reallocator, + { let ncols = self.data.shape().1; self.resize_generic(Dynamic::new(new_nrows), ncols, val) } @@ -714,7 +727,9 @@ impl> Matrix { /// columns than `self`, then the extra columns are filled with `val`. #[cfg(any(feature = "std", feature = "alloc"))] pub fn resize_horizontally(self, new_ncols: usize, val: N) -> MatrixMN - where DefaultAllocator: Reallocator { + where + DefaultAllocator: Reallocator, + { let nrows = self.data.shape().0; self.resize_generic(nrows, Dynamic::new(new_ncols), val) } @@ -724,7 +739,9 @@ impl> Matrix { /// The values are copied such that `self[(i, j)] == result[(i, j)]`. If the result has more /// rows and/or columns than `self`, then the extra rows or columns are filled with `val`. pub fn fixed_resize(self, val: N) -> MatrixMN - where DefaultAllocator: Reallocator { + where + DefaultAllocator: Reallocator, + { self.resize_generic(R2::name(), C2::name(), val) } @@ -805,7 +822,9 @@ impl DMatrix { /// /// Defined only for owned fully-dynamic matrices, i.e., `DMatrix`. pub fn resize_mut(&mut self, new_nrows: usize, new_ncols: usize, val: N) - where DefaultAllocator: Reallocator { + where + DefaultAllocator: Reallocator, + { let placeholder = unsafe { Self::new_uninitialized(0, 0) }; let old = mem::replace(self, placeholder); let new = old.resize(new_nrows, new_ncols, val); @@ -815,7 +834,8 @@ impl DMatrix { #[cfg(any(feature = "std", feature = "alloc"))] impl MatrixMN -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// Changes the number of rows of this matrix in-place. /// @@ -825,7 +845,9 @@ where DefaultAllocator: Allocator /// Defined only for owned matrices with a dynamic number of rows (for example, `DVector`). #[cfg(any(feature = "std", feature = "alloc"))] pub fn resize_vertically_mut(&mut self, new_nrows: usize, val: N) - where DefaultAllocator: Reallocator { + where + DefaultAllocator: Reallocator, + { let placeholder = unsafe { Self::new_uninitialized_generic(Dynamic::new(0), self.data.shape().1) }; let old = mem::replace(self, placeholder); @@ -836,7 +858,8 @@ where DefaultAllocator: Allocator #[cfg(any(feature = "std", feature = "alloc"))] impl MatrixMN -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// Changes the number of column of this matrix in-place. /// @@ -846,7 +869,9 @@ where DefaultAllocator: Allocator /// Defined only for owned matrices with a dynamic number of columns (for example, `DVector`). #[cfg(any(feature = "std", feature = "alloc"))] pub fn resize_horizontally_mut(&mut self, new_ncols: usize, val: N) - where DefaultAllocator: Reallocator { + where + DefaultAllocator: Reallocator, + { let placeholder = unsafe { Self::new_uninitialized_generic(self.data.shape().0, Dynamic::new(0)) }; let old = mem::replace(self, placeholder); @@ -861,8 +886,7 @@ unsafe fn compress_rows( ncols: usize, i: usize, nremove: usize, -) -{ +) { let new_nrows = nrows - nremove; if new_nrows == 0 || ncols == 0 { @@ -901,8 +925,7 @@ unsafe fn extend_rows( ncols: usize, i: usize, ninsert: usize, -) -{ +) { let new_nrows = nrows + ninsert; if new_nrows == 0 || ncols == 0 { diff --git a/src/base/helper.rs b/src/base/helper.rs index ef85a477..de601fb6 100644 --- a/src/base/helper.rs +++ b/src/base/helper.rs @@ -18,7 +18,9 @@ pub fn reject bool, T: Arbitrary>(g: &mut G, f: F) -> T #[doc(hidden)] #[inline] pub fn reject_rand bool, T>(g: &mut G, f: F) -> T -where Standard: Distribution { +where + Standard: Distribution, +{ use std::iter; iter::repeat(()).map(|_| g.gen()).find(f).unwrap() } diff --git a/src/base/indexing.rs b/src/base/indexing.rs index ca786530..65ba5d79 100644 --- a/src/base/indexing.rs +++ b/src/base/indexing.rs @@ -1,13 +1,14 @@ //! Indexing -use crate::base::{Dim, DimName, DimDiff, DimSub, Dynamic, Matrix, MatrixSlice, MatrixSliceMut, Scalar, U1}; use crate::base::storage::{Storage, StorageMut}; +use crate::base::{ + Dim, DimDiff, DimName, DimSub, Dynamic, Matrix, MatrixSlice, MatrixSliceMut, Scalar, U1, +}; use std::ops; // N.B.: Not a public trait! -trait DimRange -{ +trait DimRange { /// The number of elements indexed by this range. type Length: Dim; @@ -68,15 +69,27 @@ impl DimRange for ops::Range { #[test] fn dimrange_range_usize() { - use std::usize::MAX; use crate::base::dimension::U0; + use std::usize::MAX; assert_eq!(DimRange::contained_by(&(0..0), U0), false); assert_eq!(DimRange::contained_by(&(0..1), U0), false); assert_eq!(DimRange::contained_by(&(0..1), U1), true); - assert_eq!(DimRange::contained_by(&((MAX - 1)..MAX), Dynamic::new(MAX)), true); - assert_eq!(DimRange::length(&((MAX - 1)..MAX), Dynamic::new(MAX)), Dynamic::new(1)); - assert_eq!(DimRange::length(&(MAX..(MAX - 1)), Dynamic::new(MAX)), Dynamic::new(0)); - assert_eq!(DimRange::length(&(MAX..MAX), Dynamic::new(MAX)), Dynamic::new(0)); + assert_eq!( + DimRange::contained_by(&((MAX - 1)..MAX), Dynamic::new(MAX)), + true + ); + assert_eq!( + DimRange::length(&((MAX - 1)..MAX), Dynamic::new(MAX)), + Dynamic::new(1) + ); + assert_eq!( + DimRange::length(&(MAX..(MAX - 1)), Dynamic::new(MAX)), + Dynamic::new(0) + ); + assert_eq!( + DimRange::length(&(MAX..MAX), Dynamic::new(MAX)), + Dynamic::new(0) + ); } impl DimRange for ops::RangeFrom { @@ -100,18 +113,28 @@ impl DimRange for ops::RangeFrom { #[test] fn dimrange_rangefrom_usize() { - use std::usize::MAX; use crate::base::dimension::U0; + use std::usize::MAX; assert_eq!(DimRange::contained_by(&(0..), U0), false); assert_eq!(DimRange::contained_by(&(0..), U0), false); assert_eq!(DimRange::contained_by(&(0..), U1), true); - assert_eq!(DimRange::contained_by(&((MAX - 1)..), Dynamic::new(MAX)), true); - assert_eq!(DimRange::length(&((MAX - 1)..), Dynamic::new(MAX)), Dynamic::new(1)); - assert_eq!(DimRange::length(&(MAX..), Dynamic::new(MAX)), Dynamic::new(0)); + assert_eq!( + DimRange::contained_by(&((MAX - 1)..), Dynamic::new(MAX)), + true + ); + assert_eq!( + DimRange::length(&((MAX - 1)..), Dynamic::new(MAX)), + Dynamic::new(1) + ); + assert_eq!( + DimRange::length(&(MAX..), Dynamic::new(MAX)), + Dynamic::new(0) + ); } impl DimRange for ops::RangeFrom -where D: DimSub +where + D: DimSub, { type Length = DimDiff; @@ -133,7 +156,7 @@ where D: DimSub #[test] fn dimrange_rangefrom_dimname() { - use crate::base::dimension::{U5, U4}; + use crate::base::dimension::{U4, U5}; assert_eq!(DimRange::length(&(U1..), U5), U4); } @@ -173,12 +196,11 @@ impl DimRange for ops::RangeInclusive { #[inline(always)] fn length(&self, _: D) -> Self::Length { - Dynamic::new( - if self.end() < self.start() { - 0 - } else { - self.end().wrapping_sub(self.start().wrapping_sub(1)) - }) + Dynamic::new(if self.end() < self.start() { + 0 + } else { + self.end().wrapping_sub(self.start().wrapping_sub(1)) + }) } #[inline(always)] @@ -189,21 +211,38 @@ impl DimRange for ops::RangeInclusive { #[test] fn dimrange_rangeinclusive_usize() { - use std::usize::MAX; use crate::base::dimension::U0; + use std::usize::MAX; assert_eq!(DimRange::contained_by(&(0..=0), U0), false); assert_eq!(DimRange::contained_by(&(0..=0), U1), true); - assert_eq!(DimRange::contained_by(&(MAX..=MAX), Dynamic::new(MAX)), false); - assert_eq!(DimRange::contained_by(&((MAX-1)..=MAX), Dynamic::new(MAX)), false); - assert_eq!(DimRange::contained_by(&((MAX-1)..=(MAX-1)), Dynamic::new(MAX)), true); + assert_eq!( + DimRange::contained_by(&(MAX..=MAX), Dynamic::new(MAX)), + false + ); + assert_eq!( + DimRange::contained_by(&((MAX - 1)..=MAX), Dynamic::new(MAX)), + false + ); + assert_eq!( + DimRange::contained_by(&((MAX - 1)..=(MAX - 1)), Dynamic::new(MAX)), + true + ); assert_eq!(DimRange::length(&(0..=0), U1), Dynamic::new(1)); - assert_eq!(DimRange::length(&((MAX - 1)..=MAX), Dynamic::new(MAX)), Dynamic::new(2)); - assert_eq!(DimRange::length(&(MAX..=(MAX - 1)), Dynamic::new(MAX)), Dynamic::new(0)); - assert_eq!(DimRange::length(&(MAX..=MAX), Dynamic::new(MAX)), Dynamic::new(1)); + assert_eq!( + DimRange::length(&((MAX - 1)..=MAX), Dynamic::new(MAX)), + Dynamic::new(2) + ); + assert_eq!( + DimRange::length(&(MAX..=(MAX - 1)), Dynamic::new(MAX)), + Dynamic::new(0) + ); + assert_eq!( + DimRange::length(&(MAX..=MAX), Dynamic::new(MAX)), + Dynamic::new(1) + ); } -impl DimRange for ops::RangeTo -{ +impl DimRange for ops::RangeTo { type Length = Dynamic; #[inline(always)] @@ -224,18 +263,26 @@ impl DimRange for ops::RangeTo #[test] fn dimrange_rangeto_usize() { - use std::usize::MAX; use crate::base::dimension::U0; + use std::usize::MAX; assert_eq!(DimRange::contained_by(&(..0), U0), true); assert_eq!(DimRange::contained_by(&(..1), U0), false); assert_eq!(DimRange::contained_by(&(..0), U1), true); - assert_eq!(DimRange::contained_by(&(..(MAX - 1)), Dynamic::new(MAX)), true); - assert_eq!(DimRange::length(&(..(MAX - 1)), Dynamic::new(MAX)), Dynamic::new(MAX - 1)); - assert_eq!(DimRange::length(&(..MAX), Dynamic::new(MAX)), Dynamic::new(MAX)); + assert_eq!( + DimRange::contained_by(&(..(MAX - 1)), Dynamic::new(MAX)), + true + ); + assert_eq!( + DimRange::length(&(..(MAX - 1)), Dynamic::new(MAX)), + Dynamic::new(MAX - 1) + ); + assert_eq!( + DimRange::length(&(..MAX), Dynamic::new(MAX)), + Dynamic::new(MAX) + ); } -impl DimRange for ops::RangeToInclusive -{ +impl DimRange for ops::RangeToInclusive { type Length = Dynamic; #[inline(always)] @@ -256,21 +303,29 @@ impl DimRange for ops::RangeToInclusive #[test] fn dimrange_rangetoinclusive_usize() { - use std::usize::MAX; use crate::base::dimension::U0; + use std::usize::MAX; assert_eq!(DimRange::contained_by(&(..=0), U0), false); assert_eq!(DimRange::contained_by(&(..=1), U0), false); assert_eq!(DimRange::contained_by(&(..=0), U1), true); - assert_eq!(DimRange::contained_by(&(..=(MAX)), Dynamic::new(MAX)), false); - assert_eq!(DimRange::contained_by(&(..=(MAX - 1)), Dynamic::new(MAX)), true); - assert_eq!(DimRange::length(&(..=(MAX - 1)), Dynamic::new(MAX)), Dynamic::new(MAX)); + assert_eq!( + DimRange::contained_by(&(..=(MAX)), Dynamic::new(MAX)), + false + ); + assert_eq!( + DimRange::contained_by(&(..=(MAX - 1)), Dynamic::new(MAX)), + true + ); + assert_eq!( + DimRange::length(&(..=(MAX - 1)), Dynamic::new(MAX)), + Dynamic::new(MAX) + ); } /// A helper trait used for indexing operations. pub trait MatrixIndex<'a, N: Scalar, R: Dim, C: Dim, S: Storage>: Sized { - /// The output type returned by methods. - type Output : 'a; + type Output: 'a; /// Produces true if the given matrix is contained by this index. #[doc(hidden)] @@ -282,7 +337,7 @@ pub trait MatrixIndex<'a, N: Scalar, R: Dim, C: Dim, S: Storage>: Sized #[inline(always)] fn get(self, matrix: &'a Matrix) -> Option { if self.contained_by(matrix) { - Some(unsafe{self.get_unchecked(matrix)}) + Some(unsafe { self.get_unchecked(matrix) }) } else { None } @@ -303,9 +358,11 @@ pub trait MatrixIndex<'a, N: Scalar, R: Dim, C: Dim, S: Storage>: Sized } /// A helper trait used for indexing operations. -pub trait MatrixIndexMut<'a, N: Scalar, R: Dim, C: Dim, S: StorageMut>: MatrixIndex<'a, N, R, C, S> { +pub trait MatrixIndexMut<'a, N: Scalar, R: Dim, C: Dim, S: StorageMut>: + MatrixIndex<'a, N, R, C, S> +{ /// The output type returned by methods. - type OutputMut : 'a; + type OutputMut: 'a; /// Produces a mutable view of the data at this location, without /// performing any bounds checking. @@ -318,7 +375,7 @@ pub trait MatrixIndexMut<'a, N: Scalar, R: Dim, C: Dim, S: StorageMut>: #[inline(always)] fn get_mut(self, matrix: &'a mut Matrix) -> Option { if self.contained_by(matrix) { - Some(unsafe{self.get_unchecked_mut(matrix)}) + Some(unsafe { self.get_unchecked_mut(matrix) }) } else { None } @@ -432,14 +489,13 @@ pub trait MatrixIndexMut<'a, N: Scalar, R: Dim, C: Dim, S: StorageMut>: /// 4, 7, /// 5, 8))); /// ``` -impl> Matrix -{ +impl> Matrix { /// Produces a view of the data at the given index, or /// `None` if the index is out of bounds. #[inline] pub fn get<'a, I>(&'a self, index: I) -> Option where - I: MatrixIndex<'a, N, R, C, S> + I: MatrixIndex<'a, N, R, C, S>, { index.get(self) } @@ -450,7 +506,7 @@ impl> Matrix pub fn get_mut<'a, I>(&'a mut self, index: I) -> Option where S: StorageMut, - I: MatrixIndexMut<'a, N, R, C, S> + I: MatrixIndexMut<'a, N, R, C, S>, { index.get_mut(self) } @@ -460,7 +516,7 @@ impl> Matrix #[inline] pub fn index<'a, I>(&'a self, index: I) -> I::Output where - I: MatrixIndex<'a, N, R, C, S> + I: MatrixIndex<'a, N, R, C, S>, { index.index(self) } @@ -471,7 +527,7 @@ impl> Matrix pub fn index_mut<'a, I>(&'a mut self, index: I) -> I::OutputMut where S: StorageMut, - I: MatrixIndexMut<'a, N, R, C, S> + I: MatrixIndexMut<'a, N, R, C, S>, { index.index_mut(self) } @@ -481,7 +537,7 @@ impl> Matrix #[inline] pub unsafe fn get_unchecked<'a, I>(&'a self, index: I) -> I::Output where - I: MatrixIndex<'a, N, R, C, S> + I: MatrixIndex<'a, N, R, C, S>, { index.get_unchecked(self) } @@ -492,7 +548,7 @@ impl> Matrix pub unsafe fn get_unchecked_mut<'a, I>(&'a mut self, index: I) -> I::OutputMut where S: StorageMut, - I: MatrixIndexMut<'a, N, R, C, S> + I: MatrixIndexMut<'a, N, R, C, S>, { index.get_unchecked_mut(self) } @@ -505,7 +561,7 @@ where N: Scalar, R: Dim, C: Dim, - S: Storage + S: Storage, { type Output = &'a N; @@ -527,14 +583,15 @@ where N: Scalar, R: Dim, C: Dim, - S: StorageMut + S: StorageMut, { type OutputMut = &'a mut N; #[doc(hidden)] #[inline(always)] unsafe fn get_unchecked_mut(self, matrix: &'a mut Matrix) -> Self::OutputMut - where S: StorageMut, + where + S: StorageMut, { matrix.data.get_unchecked_linear_mut(self) } @@ -547,7 +604,7 @@ where N: Scalar, R: Dim, C: Dim, - S: Storage + S: Storage, { type Output = &'a N; @@ -572,14 +629,15 @@ where N: Scalar, R: Dim, C: Dim, - S: StorageMut + S: StorageMut, { type OutputMut = &'a mut N; #[doc(hidden)] #[inline(always)] unsafe fn get_unchecked_mut(self, matrix: &'a mut Matrix) -> Self::OutputMut - where S: StorageMut, + where + S: StorageMut, { let (row, col) = self; matrix.data.get_unchecked_mut(row, col) @@ -684,7 +742,7 @@ macro_rules! impl_index_pairs { } } -impl_index_pairs!{ +impl_index_pairs! { index R with { [<> usize => U1], [<> ops::Range => Dynamic], diff --git a/src/base/iter.rs b/src/base/iter.rs index 65cdb20a..ab040b08 100644 --- a/src/base/iter.rs +++ b/src/base/iter.rs @@ -5,7 +5,7 @@ use std::mem; use crate::base::dimension::{Dim, U1}; use crate::base::storage::{Storage, StorageMut}; -use crate::base::{Scalar, Matrix, MatrixSlice, MatrixSliceMut}; +use crate::base::{Matrix, MatrixSlice, MatrixSliceMut, Scalar}; macro_rules! iterator { (struct $Name:ident for $Storage:ident.$ptr: ident -> $Ptr:ty, $Ref:ty, $SRef: ty) => { @@ -125,7 +125,6 @@ macro_rules! iterator { iterator!(struct MatrixIter for Storage.ptr -> *const N, &'a N, &'a S); iterator!(struct MatrixIterMut for StorageMut.ptr_mut -> *mut N, &'a mut N, &'a mut S); - /* * * Row iterators. @@ -135,18 +134,15 @@ iterator!(struct MatrixIterMut for StorageMut.ptr_mut -> *mut N, &'a mut N, &'a /// An iterator through the rows of a matrix. pub struct RowIter<'a, N: Scalar, R: Dim, C: Dim, S: Storage> { mat: &'a Matrix, - curr: usize + curr: usize, } impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> RowIter<'a, N, R, C, S> { pub(crate) fn new(mat: &'a Matrix) -> Self { - RowIter { - mat, curr: 0 - } + RowIter { mat, curr: 0 } } } - impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> Iterator for RowIter<'a, N, R, C, S> { type Item = MatrixSlice<'a, N, U1, C, S::RStride, S::CStride>; @@ -163,7 +159,10 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> Iterator for RowIt #[inline] fn size_hint(&self) -> (usize, Option) { - (self.mat.nrows() - self.curr, Some(self.mat.nrows() - self.curr)) + ( + self.mat.nrows() - self.curr, + Some(self.mat.nrows() - self.curr), + ) } #[inline] @@ -172,19 +171,20 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> Iterator for RowIt } } -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> ExactSizeIterator for RowIter<'a, N, R, C, S> { +impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> ExactSizeIterator + for RowIter<'a, N, R, C, S> +{ #[inline] fn len(&self) -> usize { self.mat.nrows() - self.curr } } - /// An iterator through the mutable rows of a matrix. pub struct RowIterMut<'a, N: Scalar, R: Dim, C: Dim, S: StorageMut> { mat: *mut Matrix, curr: usize, - phantom: PhantomData<&'a mut Matrix> + phantom: PhantomData<&'a mut Matrix>, } impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> RowIterMut<'a, N, R, C, S> { @@ -192,19 +192,18 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> RowIterMut<'a, RowIterMut { mat, curr: 0, - phantom: PhantomData + phantom: PhantomData, } } fn nrows(&self) -> usize { - unsafe { - (*self.mat).nrows() - } + unsafe { (*self.mat).nrows() } } } - -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> Iterator for RowIterMut<'a, N, R, C, S> { +impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> Iterator + for RowIterMut<'a, N, R, C, S> +{ type Item = MatrixSliceMut<'a, N, U1, C, S::RStride, S::CStride>; #[inline] @@ -229,14 +228,15 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> Iterator for Ro } } -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> ExactSizeIterator for RowIterMut<'a, N, R, C, S> { +impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> ExactSizeIterator + for RowIterMut<'a, N, R, C, S> +{ #[inline] fn len(&self) -> usize { self.nrows() - self.curr } } - /* * * Column iterators. @@ -246,19 +246,18 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> ExactSizeIterat /// An iterator through the columns of a matrix. pub struct ColumnIter<'a, N: Scalar, R: Dim, C: Dim, S: Storage> { mat: &'a Matrix, - curr: usize + curr: usize, } impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> ColumnIter<'a, N, R, C, S> { pub(crate) fn new(mat: &'a Matrix) -> Self { - ColumnIter { - mat, curr: 0 - } + ColumnIter { mat, curr: 0 } } } - -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> Iterator for ColumnIter<'a, N, R, C, S> { +impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> Iterator + for ColumnIter<'a, N, R, C, S> +{ type Item = MatrixSlice<'a, N, R, U1, S::RStride, S::CStride>; #[inline] @@ -274,7 +273,10 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> Iterator for Colum #[inline] fn size_hint(&self) -> (usize, Option) { - (self.mat.ncols() - self.curr, Some(self.mat.ncols() - self.curr)) + ( + self.mat.ncols() - self.curr, + Some(self.mat.ncols() - self.curr), + ) } #[inline] @@ -283,19 +285,20 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> Iterator for Colum } } -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> ExactSizeIterator for ColumnIter<'a, N, R, C, S> { +impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> ExactSizeIterator + for ColumnIter<'a, N, R, C, S> +{ #[inline] fn len(&self) -> usize { self.mat.ncols() - self.curr } } - /// An iterator through the mutable columns of a matrix. pub struct ColumnIterMut<'a, N: Scalar, R: Dim, C: Dim, S: StorageMut> { mat: *mut Matrix, curr: usize, - phantom: PhantomData<&'a mut Matrix> + phantom: PhantomData<&'a mut Matrix>, } impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> ColumnIterMut<'a, N, R, C, S> { @@ -303,19 +306,18 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> ColumnIterMut<' ColumnIterMut { mat, curr: 0, - phantom: PhantomData + phantom: PhantomData, } } fn ncols(&self) -> usize { - unsafe { - (*self.mat).ncols() - } + unsafe { (*self.mat).ncols() } } } - -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> Iterator for ColumnIterMut<'a, N, R, C, S> { +impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> Iterator + for ColumnIterMut<'a, N, R, C, S> +{ type Item = MatrixSliceMut<'a, N, R, U1, S::RStride, S::CStride>; #[inline] @@ -340,10 +342,11 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> Iterator for Co } } -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> ExactSizeIterator for ColumnIterMut<'a, N, R, C, S> { +impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> ExactSizeIterator + for ColumnIterMut<'a, N, R, C, S> +{ #[inline] fn len(&self) -> usize { self.ncols() - self.curr } } - diff --git a/src/base/matrix.rs b/src/base/matrix.rs index beb3accf..d7348204 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -103,7 +103,9 @@ where S: Serialize, { fn serialize(&self, serializer: T) -> Result - where T: Serializer { + where + T: Serializer, + { self.data.serialize(serializer) } } @@ -117,7 +119,9 @@ where S: Deserialize<'de>, { fn deserialize(deserializer: D) -> Result - where D: Deserializer<'de> { + where + D: Deserializer<'de>, + { S::deserialize(deserializer).map(|x| Matrix { data: x, _phantoms: PhantomData, @@ -348,7 +352,9 @@ impl> Matrix { /// Moves this matrix into one that owns its data. #[inline] pub fn into_owned(self) -> MatrixMN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { Matrix::from_data(self.data.into_owned()) } @@ -382,7 +388,9 @@ impl> Matrix { /// Clones this matrix to one that owns its data. #[inline] pub fn clone_owned(&self) -> MatrixMN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { Matrix::from_data(self.data.clone_owned()) } @@ -418,7 +426,9 @@ impl> Matrix { /// Returns a matrix containing the result of `f` applied to each of its entries. #[inline] pub fn map N2>(&self, mut f: F) -> MatrixMN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { let (nrows, ncols) = self.data.shape(); let mut res = unsafe { MatrixMN::new_uninitialized_generic(nrows, ncols) }; @@ -447,8 +457,7 @@ impl> Matrix { &self, init_f: impl FnOnce(Option<&N>) -> N2, f: impl FnMut(N2, &N) -> N2, - ) -> N2 - { + ) -> N2 { let mut it = self.iter(); let init = init_f(it.next()); it.fold(init, f) @@ -640,7 +649,9 @@ impl> Matrix { #[inline] #[must_use = "Did you mean to use transpose_mut()?"] pub fn transpose(&self) -> MatrixMN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { let (nrows, ncols) = self.data.shape(); unsafe { @@ -983,7 +994,9 @@ impl> Matrix MatrixMN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { let (nrows, ncols) = self.data.shape(); unsafe { @@ -1011,7 +1024,9 @@ impl> Matrix MatrixMN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self.adjoint() } @@ -1019,7 +1034,9 @@ impl> Matrix MatrixMN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self.map(|e| e.simd_conjugate()) } @@ -1027,7 +1044,9 @@ impl> Matrix MatrixMN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self.map(|e| e.simd_unscale(real)) } @@ -1035,7 +1054,9 @@ impl> Matrix MatrixMN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self.map(|e| e.simd_scale(real)) } } @@ -1100,7 +1121,9 @@ impl> SquareMatrix { /// The diagonal of this matrix. #[inline] pub fn diagonal(&self) -> VectorN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self.map_diagonal(|e| e) } @@ -1109,7 +1132,9 @@ impl> SquareMatrix { /// This is a more efficient version of `self.diagonal().map(f)` since this /// allocates only once. pub fn map_diagonal(&self, mut f: impl FnMut(N) -> N2) -> VectorN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { assert!( self.is_square(), "Unable to get the diagonal of a non-square matrix." @@ -1130,7 +1155,9 @@ impl> SquareMatrix { /// Computes a trace of a square matrix, i.e., the sum of its diagonal elements. #[inline] pub fn trace(&self) -> N - where N: Scalar + Zero + ClosedAdd { + where + N: Scalar + Zero + ClosedAdd, + { assert!( self.is_square(), "Cannot compute the trace of non-square matrix." @@ -1151,7 +1178,9 @@ impl> SquareMatrix { /// The symmetric part of `self`, i.e., `0.5 * (self + self.transpose())`. #[inline] pub fn symmetric_part(&self) -> MatrixMN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { assert!( self.is_square(), "Cannot compute the symmetric part of a non-square matrix." @@ -1165,7 +1194,9 @@ impl> SquareMatrix { /// The hermitian part of `self`, i.e., `0.5 * (self + self.adjoint())`. #[inline] pub fn hermitian_part(&self) -> MatrixMN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { assert!( self.is_square(), "Cannot compute the hermitian part of a non-square matrix." @@ -1185,7 +1216,9 @@ impl + IsNotStaticOne, S: Storage /// and setting the diagonal element to `1`. #[inline] pub fn to_homogeneous(&self) -> MatrixN> - where DefaultAllocator: Allocator, DimSum> { + where + DefaultAllocator: Allocator, DimSum>, + { assert!( self.is_square(), "Only square matrices can currently be transformed to homogeneous coordinates." @@ -1203,7 +1236,9 @@ impl, S: Storage> Vector { /// coordinates. #[inline] pub fn to_homogeneous(&self) -> VectorN> - where DefaultAllocator: Allocator> { + where + DefaultAllocator: Allocator>, + { self.push(N::zero()) } @@ -1228,7 +1263,9 @@ impl, S: Storage> Vector { /// Constructs a new vector of higher dimension by appending `element` to the end of `self`. #[inline] pub fn push(&self, element: N) -> VectorN> - where DefaultAllocator: Allocator> { + where + DefaultAllocator: Allocator>, + { let len = self.len(); let hnrows = DimSum::::from_usize(len + 1); let mut res = unsafe { VectorN::::new_uninitialized_generic(hnrows, U1) }; @@ -1278,8 +1315,7 @@ where other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool - { + ) -> bool { self.relative_eq(other, epsilon, max_relative) } } @@ -1618,7 +1654,8 @@ impl> Vector -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// Computes the matrix `M` such that for all vector `v` we have `M * v == self.cross(&v)`. #[inline] @@ -1675,7 +1712,9 @@ impl>(&self, rhs: &Vector, t: N) -> VectorN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { let mut res = self.clone_owned(); res.axpy(t.inlined_clone(), rhs, N::one() - t); res @@ -1783,8 +1822,7 @@ where other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool - { + ) -> bool { self.as_ref() .relative_eq(other.as_ref(), epsilon, max_relative) } diff --git a/src/base/matrix_slice.rs b/src/base/matrix_slice.rs index be53034a..abb11725 100644 --- a/src/base/matrix_slice.rs +++ b/src/base/matrix_slice.rs @@ -4,9 +4,9 @@ use std::slice; use crate::base::allocator::Allocator; use crate::base::default_allocator::DefaultAllocator; -use crate::base::dimension::{Dim, DimName, Dynamic, U1, IsNotStaticOne}; +use crate::base::dimension::{Dim, DimName, Dynamic, IsNotStaticOne, U1}; use crate::base::iter::MatrixIter; -use crate::base::storage::{Owned, Storage, StorageMut, ContiguousStorage, ContiguousStorageMut}; +use crate::base::storage::{ContiguousStorage, ContiguousStorageMut, Owned, Storage, StorageMut}; use crate::base::{Matrix, Scalar}; macro_rules! slice_storage_impl( @@ -198,13 +198,31 @@ unsafe impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> StorageMu } } -unsafe impl<'a, N: Scalar, R: Dim, CStride: Dim> ContiguousStorage for SliceStorage<'a, N, R, U1, U1, CStride> { } -unsafe impl<'a, N: Scalar, R: Dim, CStride: Dim> ContiguousStorage for SliceStorageMut<'a, N, R, U1, U1, CStride> { } -unsafe impl<'a, N: Scalar, R: Dim, CStride: Dim> ContiguousStorageMut for SliceStorageMut<'a, N, R, U1, U1, CStride> { } +unsafe impl<'a, N: Scalar, R: Dim, CStride: Dim> ContiguousStorage + for SliceStorage<'a, N, R, U1, U1, CStride> +{ +} +unsafe impl<'a, N: Scalar, R: Dim, CStride: Dim> ContiguousStorage + for SliceStorageMut<'a, N, R, U1, U1, CStride> +{ +} +unsafe impl<'a, N: Scalar, R: Dim, CStride: Dim> ContiguousStorageMut + for SliceStorageMut<'a, N, R, U1, U1, CStride> +{ +} -unsafe impl<'a, N: Scalar, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorage for SliceStorage<'a, N, R, C, U1, R> { } -unsafe impl<'a, N: Scalar, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorage for SliceStorageMut<'a, N, R, C, U1, R> { } -unsafe impl<'a, N: Scalar, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorageMut for SliceStorageMut<'a, N, R, C, U1, R> { } +unsafe impl<'a, N: Scalar, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorage + for SliceStorage<'a, N, R, C, U1, R> +{ +} +unsafe impl<'a, N: Scalar, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorage + for SliceStorageMut<'a, N, R, C, U1, R> +{ +} +unsafe impl<'a, N: Scalar, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorageMut + for SliceStorageMut<'a, N, R, C, U1, R> +{ +} impl> Matrix { #[inline] @@ -213,8 +231,7 @@ impl> Matrix { start: (usize, usize), shape: (usize, usize), steps: (usize, usize), - ) - { + ) { let my_shape = self.shape(); // NOTE: we don't do any subtraction to avoid underflow for zero-sized matrices. // @@ -811,8 +828,7 @@ impl> Matrix { pub fn rows_range>( &self, rows: RowRange, - ) -> MatrixSlice - { + ) -> MatrixSlice { self.slice_range(rows, ..) } @@ -821,8 +837,7 @@ impl> Matrix { pub fn columns_range>( &self, cols: ColRange, - ) -> MatrixSlice - { + ) -> MatrixSlice { self.slice_range(.., cols) } } @@ -851,8 +866,7 @@ impl> Matrix { pub fn rows_range_mut>( &mut self, rows: RowRange, - ) -> MatrixSliceMut - { + ) -> MatrixSliceMut { self.slice_range_mut(rows, ..) } @@ -861,30 +875,28 @@ impl> Matrix { pub fn columns_range_mut>( &mut self, cols: ColRange, - ) -> MatrixSliceMut - { + ) -> MatrixSliceMut { self.slice_range_mut(.., cols) } } - impl<'a, N, R, C, RStride, CStride> From> -for MatrixSlice<'a, N, R, C, RStride, CStride> - where - N: Scalar, - R: Dim, - C: Dim, - RStride: Dim, - CStride: Dim, + for MatrixSlice<'a, N, R, C, RStride, CStride> +where + N: Scalar, + R: Dim, + C: Dim, + RStride: Dim, + CStride: Dim, { fn from(slice_mut: MatrixSliceMut<'a, N, R, C, RStride, CStride>) -> Self { let data = SliceStorage { - ptr: slice_mut.data.ptr, - shape: slice_mut.data.shape, - strides: slice_mut.data.strides, + ptr: slice_mut.data.ptr, + shape: slice_mut.data.shape, + strides: slice_mut.data.strides, _phantoms: PhantomData, }; unsafe { Matrix::from_data_statically_unchecked(data) } } -} \ No newline at end of file +} diff --git a/src/base/ops.rs b/src/base/ops.rs index de44104e..12b26d1a 100644 --- a/src/base/ops.rs +++ b/src/base/ops.rs @@ -838,7 +838,9 @@ impl> Matrix MatrixMN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { let mut res = self.clone_owned(); res.add_scalar_mut(rhs); res @@ -847,7 +849,9 @@ impl> Matrix { + where + S: StorageMut, + { for e in self.iter_mut() { *e += rhs.inlined_clone() } @@ -884,7 +888,9 @@ impl> Matrix { /// ``` #[inline] pub fn amax(&self) -> N - where N: Zero + SimdSigned + SimdPartialOrd { + where + N: Zero + SimdSigned + SimdPartialOrd, + { self.fold_with( |e| e.unwrap_or(&N::zero()).simd_abs(), |a, b| a.simd_max(b.simd_abs()), @@ -902,7 +908,9 @@ impl> Matrix { /// ``` #[inline] pub fn camax(&self) -> N::SimdRealField - where N: SimdComplexField { + where + N: SimdComplexField, + { self.fold_with( |e| e.unwrap_or(&N::zero()).simd_norm1(), |a, b| a.simd_max(b.simd_norm1()), @@ -919,7 +927,9 @@ impl> Matrix { /// ``` #[inline] pub fn max(&self) -> N - where N: SimdPartialOrd + Zero { + where + N: SimdPartialOrd + Zero, + { self.fold_with( |e| e.map(|e| e.inlined_clone()).unwrap_or(N::zero()), |a, b| a.simd_max(b.inlined_clone()), @@ -935,7 +945,9 @@ impl> Matrix { /// ``` #[inline] pub fn amin(&self) -> N - where N: Zero + SimdPartialOrd + SimdSigned { + where + N: Zero + SimdPartialOrd + SimdSigned, + { self.fold_with( |e| e.map(|e| e.simd_abs()).unwrap_or(N::zero()), |a, b| a.simd_min(b.simd_abs()), @@ -953,7 +965,9 @@ impl> Matrix { /// ``` #[inline] pub fn camin(&self) -> N::SimdRealField - where N: SimdComplexField { + where + N: SimdComplexField, + { self.fold_with( |e| { e.map(|e| e.simd_norm1()) @@ -973,7 +987,9 @@ impl> Matrix { /// ``` #[inline] pub fn min(&self) -> N - where N: SimdPartialOrd + Zero { + where + N: SimdPartialOrd + Zero, + { self.fold_with( |e| e.map(|e| e.inlined_clone()).unwrap_or(N::zero()), |a, b| a.simd_min(b.inlined_clone()), diff --git a/src/base/properties.rs b/src/base/properties.rs index 9407a578..69ca5d66 100644 --- a/src/base/properties.rs +++ b/src/base/properties.rs @@ -102,7 +102,8 @@ impl> Matrix { } impl> SquareMatrix -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// Checks that this matrix is orthogonal and has a determinant equal to 1. #[inline] diff --git a/src/base/statistics.rs b/src/base/statistics.rs index 16b9cc95..afd9eedd 100644 --- a/src/base/statistics.rs +++ b/src/base/statistics.rs @@ -114,7 +114,9 @@ impl> Matrix RowVectorN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self.compress_rows(|col| col.sum()) } @@ -135,7 +137,9 @@ impl> Matrix VectorN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self.compress_rows_tr(|col| col.sum()) } @@ -156,7 +160,9 @@ impl> Matrix VectorN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { let nrows = self.data.shape().0; self.compress_columns(VectorN::zeros_generic(nrows, U1), |out, col| { *out += col; @@ -210,7 +216,9 @@ impl, R: Dim, C: Dim, S: Storage> M /// ``` #[inline] pub fn row_variance(&self) -> RowVectorN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self.compress_rows(|col| col.variance()) } @@ -227,7 +235,9 @@ impl, R: Dim, C: Dim, S: Storage> M /// ``` #[inline] pub fn row_variance_tr(&self) -> VectorN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self.compress_rows_tr(|col| col.variance()) } @@ -245,7 +255,9 @@ impl, R: Dim, C: Dim, S: Storage> M /// ``` #[inline] pub fn column_variance(&self) -> VectorN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { let (nrows, ncols) = self.data.shape(); let mut mean = self.column_mean(); @@ -303,7 +315,9 @@ impl, R: Dim, C: Dim, S: Storage> M /// ``` #[inline] pub fn row_mean(&self) -> RowVectorN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self.compress_rows(|col| col.mean()) } @@ -320,7 +334,9 @@ impl, R: Dim, C: Dim, S: Storage> M /// ``` #[inline] pub fn row_mean_tr(&self) -> VectorN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self.compress_rows_tr(|col| col.mean()) } @@ -337,7 +353,9 @@ impl, R: Dim, C: Dim, S: Storage> M /// ``` #[inline] pub fn column_mean(&self) -> VectorN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { let (nrows, ncols) = self.data.shape(); let denom = N::one() / crate::convert::<_, N>(ncols.value() as f64); self.compress_columns(VectorN::zeros_generic(nrows, U1), |out, col| { diff --git a/src/base/storage.rs b/src/base/storage.rs index 8e472e1e..9f039ba2 100644 --- a/src/base/storage.rs +++ b/src/base/storage.rs @@ -103,11 +103,13 @@ pub unsafe trait Storage: Debug + Sized { /// Builds a matrix data storage that does not contain any reference. fn into_owned(self) -> Owned - where DefaultAllocator: Allocator; + where + DefaultAllocator: Allocator; /// Clones this data storage to one that does not contain any reference. fn clone_owned(&self) -> Owned - where DefaultAllocator: Allocator; + where + DefaultAllocator: Allocator; } /// Trait implemented by matrix data storage that can provide a mutable access to its elements. diff --git a/src/base/vec_storage.rs b/src/base/vec_storage.rs index bbf5595f..26948693 100644 --- a/src/base/vec_storage.rs +++ b/src/base/vec_storage.rs @@ -5,11 +5,11 @@ use std::io::{Result as IOResult, Write}; use alloc::vec::Vec; use crate::base::allocator::Allocator; +use crate::base::constraint::{SameNumberOfRows, ShapeConstraint}; use crate::base::default_allocator::DefaultAllocator; use crate::base::dimension::{Dim, DimName, Dynamic, U1}; use crate::base::storage::{ContiguousStorage, ContiguousStorageMut, Owned, Storage, StorageMut}; use crate::base::{Scalar, Vector}; -use crate::base::constraint::{SameNumberOfRows, ShapeConstraint}; #[cfg(feature = "abomonation-serialize")] use abomonation::Abomonation; @@ -29,7 +29,7 @@ pub struct VecStorage { ncols: C, } -#[deprecated(note="renamed to `VecStorage`")] +#[deprecated(note = "renamed to `VecStorage`")] /// Renamed to [VecStorage]. pub type MatrixVec = VecStorage; @@ -89,8 +89,7 @@ impl VecStorage { } } -impl Into> for VecStorage -{ +impl Into> for VecStorage { fn into(self) -> Vec { self.data } @@ -103,7 +102,8 @@ impl Into> for VecStorage * */ unsafe impl Storage for VecStorage -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { type RStride = U1; type CStride = Dynamic; @@ -130,13 +130,17 @@ where DefaultAllocator: Allocator #[inline] fn into_owned(self) -> Owned - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self } #[inline] fn clone_owned(&self) -> Owned - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self.clone() } @@ -147,7 +151,8 @@ where DefaultAllocator: Allocator } unsafe impl Storage for VecStorage -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { type RStride = U1; type CStride = R; @@ -174,13 +179,17 @@ where DefaultAllocator: Allocator #[inline] fn into_owned(self) -> Owned - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self } #[inline] fn clone_owned(&self) -> Owned - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self.clone() } @@ -196,7 +205,8 @@ where DefaultAllocator: Allocator * */ unsafe impl StorageMut for VecStorage -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { #[inline] fn ptr_mut(&mut self) -> *mut N { @@ -209,14 +219,19 @@ where DefaultAllocator: Allocator } } -unsafe impl ContiguousStorage for VecStorage where DefaultAllocator: Allocator -{} +unsafe impl ContiguousStorage for VecStorage where + DefaultAllocator: Allocator +{ +} -unsafe impl ContiguousStorageMut for VecStorage where DefaultAllocator: Allocator -{} +unsafe impl ContiguousStorageMut for VecStorage where + DefaultAllocator: Allocator +{ +} unsafe impl StorageMut for VecStorage -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { #[inline] fn ptr_mut(&mut self) -> *mut N { @@ -244,14 +259,17 @@ impl Abomonation for VecStorage { } } -unsafe impl ContiguousStorage for VecStorage where DefaultAllocator: Allocator -{} - -unsafe impl ContiguousStorageMut for VecStorage where DefaultAllocator: Allocator -{} - -impl Extend for VecStorage +unsafe impl ContiguousStorage for VecStorage where + DefaultAllocator: Allocator { +} + +unsafe impl ContiguousStorageMut for VecStorage where + DefaultAllocator: Allocator +{ +} + +impl Extend for VecStorage { /// Extends the number of columns of the `VecStorage` with elements /// from the given iterator. /// @@ -259,8 +277,7 @@ impl Extend for VecStorage /// This function panics if the number of elements yielded by the /// given iterator is not a multiple of the number of rows of the /// `VecStorage`. - fn extend>(&mut self, iter: I) - { + fn extend>(&mut self, iter: I) { self.data.extend(iter); self.ncols = Dynamic::new(self.data.len() / self.nrows.value()); assert!(self.data.len() % self.nrows.value() == 0, @@ -268,8 +285,7 @@ impl Extend for VecStorage } } -impl<'a, N: 'a + Copy, R: Dim> Extend<&'a N> for VecStorage -{ +impl<'a, N: 'a + Copy, R: Dim> Extend<&'a N> for VecStorage { /// Extends the number of columns of the `VecStorage` with elements /// from the given iterator. /// @@ -277,8 +293,7 @@ impl<'a, N: 'a + Copy, R: Dim> Extend<&'a N> for VecStorage /// This function panics if the number of elements yielded by the /// given iterator is not a multiple of the number of rows of the /// `VecStorage`. - fn extend>(&mut self, iter: I) - { + fn extend>(&mut self, iter: I) { self.extend(iter.into_iter().copied()) } } @@ -298,8 +313,7 @@ where /// This function panics if the number of rows of each `Vector` /// yielded by the iterator is not equal to the number of rows /// of this `VecStorage`. - fn extend>>(&mut self, iter: I) - { + fn extend>>(&mut self, iter: I) { let nrows = self.nrows.value(); let iter = iter.into_iter(); let (lower, _upper) = iter.size_hint(); @@ -312,12 +326,10 @@ where } } -impl Extend for VecStorage -{ +impl Extend for VecStorage { /// Extends the number of rows of the `VecStorage` with elements /// from the given iterator. - fn extend>(&mut self, iter: I) - { + fn extend>(&mut self, iter: I) { self.data.extend(iter); self.nrows = Dynamic::new(self.data.len()); } diff --git a/src/debug/random_orthogonal.rs b/src/debug/random_orthogonal.rs index cab2deb0..de72bdb7 100644 --- a/src/debug/random_orthogonal.rs +++ b/src/debug/random_orthogonal.rs @@ -13,13 +13,15 @@ use simba::scalar::ComplexField; /// A random orthogonal matrix. #[derive(Clone, Debug)] pub struct RandomOrthogonal -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { m: MatrixN, } impl RandomOrthogonal -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// Retrieve the generated matrix. pub fn unwrap(self) -> MatrixN { diff --git a/src/debug/random_sdp.rs b/src/debug/random_sdp.rs index d016713a..b9f81859 100644 --- a/src/debug/random_sdp.rs +++ b/src/debug/random_sdp.rs @@ -14,13 +14,15 @@ use crate::debug::RandomOrthogonal; /// A random, well-conditioned, symmetric definite-positive matrix. #[derive(Clone, Debug)] pub struct RandomSDP -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { m: MatrixN, } impl RandomSDP -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// Retrieve the generated matrix. pub fn unwrap(self) -> MatrixN { diff --git a/src/geometry/isometry_construction.rs b/src/geometry/isometry_construction.rs index fc055b93..a9f9c978 100644 --- a/src/geometry/isometry_construction.rs +++ b/src/geometry/isometry_construction.rs @@ -114,7 +114,8 @@ where // 2D rotation. impl Isometry> -where N::Element: SimdRealField +where + N::Element: SimdRealField, { /// Creates a new 2D isometry from a translation and a rotation angle. /// @@ -151,7 +152,8 @@ where N::Element: SimdRealField } impl Isometry> -where N::Element: SimdRealField +where + N::Element: SimdRealField, { /// Creates a new 2D isometry from a translation and a rotation angle. /// diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index b6766e3f..a7d5372f 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -46,7 +46,9 @@ impl PartialEq for Orthographic3 { #[cfg(feature = "serde-serialize")] impl Serialize for Orthographic3 { fn serialize(&self, serializer: S) -> Result - where S: Serializer { + where + S: Serializer, + { self.matrix.serialize(serializer) } } @@ -54,7 +56,9 @@ impl Serialize for Orthographic3 { #[cfg(feature = "serde-serialize")] impl<'a, N: RealField + Deserialize<'a>> Deserialize<'a> for Orthographic3 { fn deserialize(deserializer: Des) -> Result - where Des: Deserializer<'a> { + where + Des: Deserializer<'a>, + { let matrix = Matrix4::::deserialize(deserializer)?; Ok(Self::from_matrix_unchecked(matrix)) @@ -480,7 +484,9 @@ impl Orthographic3 { /// ``` #[inline] pub fn project_vector(&self, p: &Vector) -> Vector3 - where SB: Storage { + where + SB: Storage, + { Vector3::new( self.matrix[(0, 0)] * p[0], self.matrix[(1, 1)] * p[1], @@ -679,7 +685,8 @@ impl Orthographic3 { } impl Distribution> for Standard -where Standard: Distribution +where + Standard: Distribution, { fn sample(&self, r: &mut R) -> Orthographic3 { let left = r.gen(); @@ -695,7 +702,8 @@ where Standard: Distribution #[cfg(feature = "arbitrary")] impl Arbitrary for Orthographic3 -where Matrix4: Send +where + Matrix4: Send, { fn arbitrary(g: &mut G) -> Self { let left = Arbitrary::arbitrary(g); diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index de7de359..325a450c 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -47,7 +47,9 @@ impl PartialEq for Perspective3 { #[cfg(feature = "serde-serialize")] impl Serialize for Perspective3 { fn serialize(&self, serializer: S) -> Result - where S: Serializer { + where + S: Serializer, + { self.matrix.serialize(serializer) } } @@ -55,7 +57,9 @@ impl Serialize for Perspective3 { #[cfg(feature = "serde-serialize")] impl<'a, N: RealField + Deserialize<'a>> Deserialize<'a> for Perspective3 { fn deserialize(deserializer: Des) -> Result - where Des: Deserializer<'a> { + where + Des: Deserializer<'a>, + { let matrix = Matrix4::::deserialize(deserializer)?; Ok(Self::from_matrix_unchecked(matrix)) @@ -212,7 +216,9 @@ impl Perspective3 { /// Projects a vector. Faster than matrix multiplication. #[inline] pub fn project_vector(&self, p: &Vector) -> Vector3 - where SB: Storage { + where + SB: Storage, + { let inverse_denom = -N::one() / p[2]; Vector3::new( self.matrix[(0, 0)] * p[0] * inverse_denom, @@ -263,7 +269,8 @@ impl Perspective3 { } impl Distribution> for Standard -where Standard: Distribution +where + Standard: Distribution, { fn sample<'a, R: Rng + ?Sized>(&self, r: &'a mut R) -> Perspective3 { let znear = r.gen(); diff --git a/src/geometry/point.rs b/src/geometry/point.rs index b2b44033..ab26589b 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -23,7 +23,8 @@ use crate::base::{DefaultAllocator, Scalar, VectorN}; #[repr(C)] #[derive(Debug, Clone)] pub struct Point -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// The coordinates of this point, i.e., the shift from the origin. pub coords: VectorN, @@ -53,7 +54,9 @@ where >::Buffer: Serialize, { fn serialize(&self, serializer: S) -> Result - where S: Serializer { + where + S: Serializer, + { self.coords.serialize(serializer) } } @@ -65,7 +68,9 @@ where >::Buffer: Deserialize<'a>, { fn deserialize(deserializer: Des) -> Result - where Des: Deserializer<'a> { + where + Des: Deserializer<'a>, + { let coords = VectorN::::deserialize(deserializer)?; Ok(Self::from(coords)) @@ -94,7 +99,8 @@ where } impl Point -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// Converts this point into a vector in homogeneous coordinates, i.e., appends a `1` at the /// end of it. @@ -246,8 +252,7 @@ where other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool - { + ) -> bool { self.coords .relative_eq(&other.coords, epsilon, max_relative) } @@ -272,7 +277,8 @@ where impl Eq for Point where DefaultAllocator: Allocator {} impl PartialEq for Point -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { #[inline] fn eq(&self, right: &Self) -> bool { @@ -281,7 +287,8 @@ where DefaultAllocator: Allocator } impl PartialOrd for Point -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { #[inline] fn partial_cmp(&self, other: &Self) -> Option { @@ -313,7 +320,8 @@ where DefaultAllocator: Allocator * inf/sup */ impl Point -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// Computes the infimum (aka. componentwise min) of two points. #[inline] @@ -341,7 +349,8 @@ where DefaultAllocator: Allocator * */ impl fmt::Display for Point -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{{")?; diff --git a/src/geometry/point_construction.rs b/src/geometry/point_construction.rs index 4b0ea70d..c54cb779 100644 --- a/src/geometry/point_construction.rs +++ b/src/geometry/point_construction.rs @@ -13,7 +13,8 @@ use simba::scalar::ClosedDiv; use crate::geometry::Point; impl Point -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// Creates a new point with uninitialized coordinates. #[inline] @@ -38,7 +39,9 @@ where DefaultAllocator: Allocator /// ``` #[inline] pub fn origin() -> Self - where N: Zero { + where + N: Zero, + { Self::from(VectorN::from_element(N::zero())) } @@ -113,7 +116,8 @@ where DefaultAllocator: Allocator * */ impl Bounded for Point -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { #[inline] fn max_value() -> Self { diff --git a/src/geometry/point_ops.rs b/src/geometry/point_ops.rs index d23fd6ec..e6547fc4 100644 --- a/src/geometry/point_ops.rs +++ b/src/geometry/point_ops.rs @@ -21,7 +21,8 @@ use crate::geometry::Point; * */ impl Index for Point -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { type Output = N; @@ -32,7 +33,8 @@ where DefaultAllocator: Allocator } impl IndexMut for Point -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { #[inline] fn index_mut(&mut self, i: usize) -> &mut Self::Output { @@ -46,7 +48,8 @@ where DefaultAllocator: Allocator * */ impl Neg for Point -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { type Output = Self; @@ -57,7 +60,8 @@ where DefaultAllocator: Allocator } impl<'a, N: Scalar + ClosedNeg, D: DimName> Neg for &'a Point -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { type Output = Point; diff --git a/src/geometry/quaternion_conversion.rs b/src/geometry/quaternion_conversion.rs index 1b88be8c..37a8bebd 100644 --- a/src/geometry/quaternion_conversion.rs +++ b/src/geometry/quaternion_conversion.rs @@ -219,7 +219,8 @@ impl Into> for UnitQuaternion { } impl From> for Matrix4 -where N::Element: SimdRealField +where + N::Element: SimdRealField, { #[inline] fn from(q: UnitQuaternion) -> Self { @@ -228,7 +229,8 @@ where N::Element: SimdRealField } impl From> for Rotation3 -where N::Element: SimdRealField +where + N::Element: SimdRealField, { #[inline] fn from(q: UnitQuaternion) -> Self { @@ -237,7 +239,8 @@ where N::Element: SimdRealField } impl From> for UnitQuaternion -where N::Element: SimdRealField +where + N::Element: SimdRealField, { #[inline] fn from(q: Rotation3) -> Self { @@ -246,7 +249,8 @@ where N::Element: SimdRealField } impl From> for Matrix3 -where N::Element: SimdRealField +where + N::Element: SimdRealField, { #[inline] fn from(q: UnitQuaternion) -> Self { diff --git a/src/geometry/quaternion_ops.rs b/src/geometry/quaternion_ops.rs index 0929c6bd..e18c1b16 100644 --- a/src/geometry/quaternion_ops.rs +++ b/src/geometry/quaternion_ops.rs @@ -551,7 +551,8 @@ macro_rules! left_scalar_mul_impl( left_scalar_mul_impl!(f32, f64); impl Neg for Quaternion -where N::Element: SimdRealField +where + N::Element: SimdRealField, { type Output = Quaternion; @@ -562,7 +563,8 @@ where N::Element: SimdRealField } impl<'a, N: SimdRealField> Neg for &'a Quaternion -where N::Element: SimdRealField +where + N::Element: SimdRealField, { type Output = Quaternion; diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index eb393a01..c6cd3d86 100755 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -26,7 +26,8 @@ use crate::geometry::Point; #[repr(C)] #[derive(Debug)] pub struct Rotation -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { matrix: MatrixN, } @@ -87,7 +88,9 @@ where Owned: Serialize, { fn serialize(&self, serializer: S) -> Result - where S: Serializer { + where + S: Serializer, + { self.matrix.serialize(serializer) } } @@ -99,7 +102,9 @@ where Owned: Deserialize<'a>, { fn deserialize(deserializer: Des) -> Result - where Des: Deserializer<'a> { + where + Des: Deserializer<'a>, + { let matrix = MatrixN::::deserialize(deserializer)?; Ok(Self::from_matrix_unchecked(matrix)) @@ -107,7 +112,8 @@ where } impl Rotation -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// A reference to the underlying matrix representation of this rotation. /// @@ -440,7 +446,8 @@ where impl Eq for Rotation where DefaultAllocator: Allocator {} impl PartialEq for Rotation -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { #[inline] fn eq(&self, right: &Self) -> bool { @@ -484,8 +491,7 @@ where other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool - { + ) -> bool { self.matrix .relative_eq(&other.matrix, epsilon, max_relative) } diff --git a/src/geometry/rotation_ops.rs b/src/geometry/rotation_ops.rs index 069f0923..b3330877 100644 --- a/src/geometry/rotation_ops.rs +++ b/src/geometry/rotation_ops.rs @@ -31,7 +31,8 @@ use crate::base::{DefaultAllocator, Matrix, MatrixMN, Scalar, Unit, Vector, Vect use crate::geometry::{Point, Rotation}; impl Index<(usize, usize)> for Rotation -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { type Output = N; diff --git a/src/geometry/rotation_specialization.rs b/src/geometry/rotation_specialization.rs index 399106cd..1ee4a9df 100644 --- a/src/geometry/rotation_specialization.rs +++ b/src/geometry/rotation_specialization.rs @@ -55,7 +55,9 @@ impl Rotation2 { /// convergence parameters and starting solution. /// This implements "A Robust Method to Extract the Rotational Part of Deformations" by Müller et al. pub fn from_matrix(m: &Matrix2) -> Self - where N: RealField { + where + N: RealField, + { Self::from_matrix_eps(m, N::default_epsilon(), 0, Self::identity()) } @@ -72,7 +74,9 @@ impl Rotation2 { /// to the actual solution is provided. Can be set to `Rotation2::identity()` if no other /// guesses come to mind. pub fn from_matrix_eps(m: &Matrix2, eps: N, mut max_iter: usize, guess: Self) -> Self - where N: RealField { + where + N: RealField, + { if max_iter == 0 { max_iter = usize::max_value(); } @@ -199,7 +203,9 @@ impl Rotation2 { /// computations might cause the matrix from progressively not being orthonormal anymore. #[inline] pub fn renormalize(&mut self) - where N: RealField { + where + N: RealField, + { let mut c = UnitComplex::from(*self); let _ = c.renormalize(); @@ -262,7 +268,8 @@ where * */ impl Rotation3 -where N::Element: SimdRealField +where + N::Element: SimdRealField, { /// Builds a 3 dimensional rotation matrix from an axis and an angle. /// @@ -299,7 +306,9 @@ where N::Element: SimdRealField /// convergence parameters and starting solution. /// This implements "A Robust Method to Extract the Rotational Part of Deformations" by Müller et al. pub fn from_matrix(m: &Matrix3) -> Self - where N: RealField { + where + N: RealField, + { Self::from_matrix_eps(m, N::default_epsilon(), 0, Self::identity()) } @@ -316,7 +325,9 @@ where N::Element: SimdRealField /// to the actual solution is provided. Can be set to `Rotation3::identity()` if no other /// guesses come to mind. pub fn from_matrix_eps(m: &Matrix3, eps: N, mut max_iter: usize, guess: Self) -> Self - where N: RealField { + where + N: RealField, + { if max_iter == 0 { max_iter = usize::max_value(); } @@ -391,7 +402,9 @@ where N::Element: SimdRealField /// assert_eq!(Rotation3::from_scaled_axis(Vector3::::zeros()), Rotation3::identity()); /// ``` pub fn from_axis_angle(axis: &Unit>, angle: N) -> Self - where SB: Storage { + where + SB: Storage, + { angle.simd_ne(N::zero()).if_else( || { let ux = axis.as_ref()[0]; @@ -456,7 +469,9 @@ where N::Element: SimdRealField /// The angles are produced in the form (roll, pitch, yaw). #[deprecated(note = "This is renamed to use `.euler_angles()`.")] pub fn to_euler_angles(&self) -> (N, N, N) - where N: RealField { + where + N: RealField, + { self.euler_angles() } @@ -475,7 +490,9 @@ where N::Element: SimdRealField /// assert_relative_eq!(euler.2, 0.3, epsilon = 1.0e-6); /// ``` pub fn euler_angles(&self) -> (N, N, N) - where N: RealField { + where + N: RealField, + { // Implementation informed by "Computing Euler angles from a rotation matrix", by Gregory G. Slabaugh // https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.371.6578 if self[(2, 0)].abs() < N::one() { @@ -498,7 +515,9 @@ where N::Element: SimdRealField /// computations might cause the matrix from progressively not being orthonormal anymore. #[inline] pub fn renormalize(&mut self) - where N: RealField { + where + N: RealField, + { let mut c = UnitQuaternion::from(*self); let _ = c.renormalize(); @@ -717,7 +736,9 @@ where N::Element: SimdRealField /// ``` #[inline] pub fn axis(&self) -> Option>> - where N: RealField { + where + N: RealField, + { let axis = VectorN::::new( self.matrix()[(2, 1)] - self.matrix()[(1, 2)], self.matrix()[(0, 2)] - self.matrix()[(2, 0)], @@ -739,7 +760,9 @@ where N::Element: SimdRealField /// ``` #[inline] pub fn scaled_axis(&self) -> Vector3 - where N: RealField { + where + N: RealField, + { if let Some(axis) = self.axis() { axis.into_inner() * self.angle() } else { @@ -768,7 +791,9 @@ where N::Element: SimdRealField /// ``` #[inline] pub fn axis_angle(&self) -> Option<(Unit>, N)> - where N: RealField { + where + N: RealField, + { if let Some(axis) = self.axis() { Some((axis, self.angle())) } else { @@ -825,7 +850,9 @@ where N::Element: SimdRealField /// ``` #[inline] pub fn powf(&self, n: N) -> Self - where N: RealField { + where + N: RealField, + { if let Some(axis) = self.axis() { Self::from_axis_angle(&axis, self.angle() * n) } else if self.matrix()[(0, 0)] < N::zero() { diff --git a/src/geometry/similarity.rs b/src/geometry/similarity.rs index ed98d217..fab54759 100755 --- a/src/geometry/similarity.rs +++ b/src/geometry/similarity.rs @@ -40,7 +40,8 @@ use crate::geometry::{AbstractRotation, Isometry, Point, Translation}; Owned: Deserialize<'de>")) )] pub struct Similarity -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// The part of this similarity that does not include the scaling factor. pub isometry: Isometry, @@ -87,7 +88,8 @@ where } impl + Clone> Clone for Similarity -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { #[inline] fn clone(&self) -> Self { @@ -127,7 +129,8 @@ where } impl Similarity -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// The scaling factor of this similarity transformation. #[inline] @@ -329,7 +332,8 @@ where // This is OK since all constructors of the isometry enforce the Rotation bound already (and // explicit struct construction is prevented by the private scaling factor). impl Similarity -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// Converts this similarity into its equivalent homogeneous transformation matrix. #[inline] @@ -404,8 +408,7 @@ where other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool - { + ) -> bool { self.isometry .relative_eq(&other.isometry, epsilon, max_relative) && self diff --git a/src/geometry/transform.rs b/src/geometry/transform.rs index b7d47f0a..42586509 100755 --- a/src/geometry/transform.rs +++ b/src/geometry/transform.rs @@ -158,7 +158,8 @@ super_tcategory_impl!( #[repr(C)] #[derive(Debug)] pub struct Transform, C: TCategory> -where DefaultAllocator: Allocator, DimNameSum> +where + DefaultAllocator: Allocator, DimNameSum>, { matrix: MatrixN>, _phantom: PhantomData, @@ -181,7 +182,8 @@ where } impl, C: TCategory> Clone for Transform -where DefaultAllocator: Allocator, DimNameSum> +where + DefaultAllocator: Allocator, DimNameSum>, { #[inline] fn clone(&self) -> Self { @@ -196,7 +198,9 @@ where Owned, DimNameSum>: Serialize, { fn serialize(&self, serializer: S) -> Result - where S: Serializer { + where + S: Serializer, + { self.matrix.serialize(serializer) } } @@ -208,18 +212,23 @@ where Owned, DimNameSum>: Deserialize<'a>, { fn deserialize(deserializer: Des) -> Result - where Des: Deserializer<'a> { + where + Des: Deserializer<'a>, + { let matrix = MatrixN::>::deserialize(deserializer)?; Ok(Transform::from_matrix_unchecked(matrix)) } } -impl, C: TCategory> Eq for Transform where DefaultAllocator: Allocator, DimNameSum> -{} +impl, C: TCategory> Eq for Transform where + DefaultAllocator: Allocator, DimNameSum> +{ +} impl, C: TCategory> PartialEq for Transform -where DefaultAllocator: Allocator, DimNameSum> +where + DefaultAllocator: Allocator, DimNameSum>, { #[inline] fn eq(&self, right: &Self) -> bool { @@ -228,7 +237,8 @@ where DefaultAllocator: Allocator, DimNameSum> } impl, C: TCategory> Transform -where DefaultAllocator: Allocator, DimNameSum> +where + DefaultAllocator: Allocator, DimNameSum>, { /// Creates a new transformation from the given homogeneous matrix. The transformation category /// of `Self` is not checked to be verified by the given matrix. @@ -398,7 +408,9 @@ where DefaultAllocator: Allocator, DimNameSum> #[inline] #[must_use = "Did you mean to use inverse_mut()?"] pub fn inverse(self) -> Transform - where C: SubTCategoryOf { + where + C: SubTCategoryOf, + { // FIXME: specialize for TAffine? Transform::from_matrix_unchecked(self.matrix.try_inverse().unwrap()) } @@ -451,7 +463,9 @@ where DefaultAllocator: Allocator, DimNameSum> /// ``` #[inline] pub fn inverse_mut(&mut self) - where C: SubTCategoryOf { + where + C: SubTCategoryOf, + { let _ = self.matrix.try_inverse_mut(); } } @@ -509,7 +523,8 @@ where } impl> Transform -where DefaultAllocator: Allocator, DimNameSum> +where + DefaultAllocator: Allocator, DimNameSum>, { /// A mutable reference to underlying matrix. Use `.matrix_mut_unchecked` instead if this /// transformation category is not `TGeneral`. @@ -553,8 +568,7 @@ where other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool - { + ) -> bool { self.matrix .relative_eq(&other.matrix, epsilon, max_relative) } diff --git a/src/geometry/transform_construction.rs b/src/geometry/transform_construction.rs index 85fe6676..e0826eeb 100644 --- a/src/geometry/transform_construction.rs +++ b/src/geometry/transform_construction.rs @@ -9,7 +9,8 @@ use crate::base::{DefaultAllocator, MatrixN}; use crate::geometry::{TCategory, Transform}; impl, C: TCategory> Transform -where DefaultAllocator: Allocator, DimNameSum> +where + DefaultAllocator: Allocator, DimNameSum>, { /// Creates a new identity transform. /// @@ -46,7 +47,8 @@ where DefaultAllocator: Allocator, DimNameSum> } impl, C: TCategory> One for Transform -where DefaultAllocator: Allocator, DimNameSum> +where + DefaultAllocator: Allocator, DimNameSum>, { /// Creates a new identity transform. #[inline] diff --git a/src/geometry/translation_construction.rs b/src/geometry/translation_construction.rs index 18793721..9466816d 100644 --- a/src/geometry/translation_construction.rs +++ b/src/geometry/translation_construction.rs @@ -16,7 +16,8 @@ use crate::base::{DefaultAllocator, Scalar, VectorN}; use crate::geometry::Translation; impl Translation -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// Creates a new identity translation. /// @@ -39,7 +40,8 @@ where DefaultAllocator: Allocator } impl One for Translation -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { #[inline] fn one() -> Self { diff --git a/src/geometry/translation_conversion.rs b/src/geometry/translation_conversion.rs index 6c43bc04..0754a678 100644 --- a/src/geometry/translation_conversion.rs +++ b/src/geometry/translation_conversion.rs @@ -167,7 +167,8 @@ where } impl From> for Translation -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { #[inline] fn from(vector: VectorN) -> Self { diff --git a/src/geometry/unit_complex.rs b/src/geometry/unit_complex.rs index 7b51391b..a8ac5bcd 100755 --- a/src/geometry/unit_complex.rs +++ b/src/geometry/unit_complex.rs @@ -41,7 +41,8 @@ impl Normed for Complex { } impl UnitComplex -where N::Element: SimdRealField +where + N::Element: SimdRealField, { /// The rotation angle in `]-pi; pi]` of this unit complex number. /// @@ -100,7 +101,9 @@ where N::Element: SimdRealField /// Returns `None` if the angle is zero. #[inline] pub fn axis_angle(&self) -> Option<(Unit>, N)> - where N: RealField { + where + N: RealField, + { let ang = self.angle(); if ang.is_zero() { @@ -391,8 +394,7 @@ impl RelativeEq for UnitComplex { other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool - { + ) -> bool { self.re.relative_eq(&other.re, epsilon, max_relative) && self.im.relative_eq(&other.im, epsilon, max_relative) } diff --git a/src/geometry/unit_complex_construction.rs b/src/geometry/unit_complex_construction.rs index a65498c4..cfe8d918 100644 --- a/src/geometry/unit_complex_construction.rs +++ b/src/geometry/unit_complex_construction.rs @@ -14,7 +14,8 @@ use simba::scalar::RealField; use simba::simd::SimdRealField; impl UnitComplex -where N::Element: SimdRealField +where + N::Element: SimdRealField, { /// The unit complex number multiplicative identity. /// @@ -138,7 +139,9 @@ where N::Element: SimdRealField /// convergence parameters and starting solution. /// This implements "A Robust Method to Extract the Rotational Part of Deformations" by Müller et al. pub fn from_matrix(m: &Matrix2) -> Self - where N: RealField { + where + N: RealField, + { Rotation2::from_matrix(m).into() } @@ -155,7 +158,9 @@ where N::Element: SimdRealField /// to the actual solution is provided. Can be set to `UnitQuaternion::identity()` if no other /// guesses come to mind. pub fn from_matrix_eps(m: &Matrix2, eps: N, max_iter: usize, guess: Self) -> Self - where N: RealField { + where + N: RealField, + { let guess = Rotation2::from(guess); Rotation2::from_matrix_eps(m, eps, max_iter, guess).into() } @@ -276,7 +281,8 @@ where N::Element: SimdRealField } impl One for UnitComplex -where N::Element: SimdRealField +where + N::Element: SimdRealField, { #[inline] fn one() -> Self { @@ -298,7 +304,8 @@ where #[cfg(feature = "arbitrary")] impl Arbitrary for UnitComplex -where N::Element: SimdRealField +where + N::Element: SimdRealField, { #[inline] fn arbitrary(g: &mut G) -> Self { diff --git a/src/io/matrix_market.rs b/src/io/matrix_market.rs index f0e817a1..3f7834ac 100644 --- a/src/io/matrix_market.rs +++ b/src/io/matrix_market.rs @@ -1,9 +1,9 @@ use std::fs; use std::path::Path; -use pest::Parser; use crate::sparse::CsMatrix; use crate::RealField; +use pest::Parser; #[derive(Parser)] #[grammar = "io/matrix_market.pest"] diff --git a/src/linalg/balancing.rs b/src/linalg/balancing.rs index aca28cbf..e7dbc6fb 100644 --- a/src/linalg/balancing.rs +++ b/src/linalg/balancing.rs @@ -13,7 +13,9 @@ use crate::base::{DefaultAllocator, MatrixN, VectorN}; /// /// See https://arxiv.org/pdf/1401.5766.pdf pub fn balance_parlett_reinsch(m: &mut MatrixN) -> VectorN -where DefaultAllocator: Allocator + Allocator { +where + DefaultAllocator: Allocator + Allocator, +{ assert!(m.is_square(), "Unable to balance a non-square matrix."); let dim = m.data.shape().0; @@ -65,7 +67,9 @@ where DefaultAllocator: Allocator + Allocator { /// Computes in-place `D * m * D.inverse()`, where `D` is the matrix with diagonal `d`. pub fn unbalance(m: &mut MatrixN, d: &VectorN) -where DefaultAllocator: Allocator + Allocator { +where + DefaultAllocator: Allocator + Allocator, +{ assert!(m.is_square(), "Unable to unbalance a non-square matrix."); assert_eq!(m.nrows(), d.len(), "Unbalancing: mismatched dimensions."); diff --git a/src/linalg/bidiagonal.rs b/src/linalg/bidiagonal.rs index 9dd9a131..c19a0662 100644 --- a/src/linalg/bidiagonal.rs +++ b/src/linalg/bidiagonal.rs @@ -171,9 +171,11 @@ where MatrixN>, MatrixMN, C>, ) - where DefaultAllocator: Allocator, DimMinimum> + where + DefaultAllocator: Allocator, DimMinimum> + Allocator> - + Allocator, C> { + + Allocator, C>, + { // FIXME: optimize by calling a reallocator. (self.u(), self.d(), self.v_t()) } @@ -181,7 +183,9 @@ where /// Retrieves the upper trapezoidal submatrix `R` of this decomposition. #[inline] pub fn d(&self) -> MatrixN> - where DefaultAllocator: Allocator, DimMinimum> { + where + DefaultAllocator: Allocator, DimMinimum>, + { let (nrows, ncols) = self.uv.data.shape(); let d = nrows.min(ncols); @@ -198,7 +202,9 @@ where // FIXME: code duplication with householder::assemble_q. // Except that we are returning a rectangular matrix here. pub fn u(&self) -> MatrixMN> - where DefaultAllocator: Allocator> { + where + DefaultAllocator: Allocator>, + { let (nrows, ncols) = self.uv.data.shape(); let mut res = Matrix::identity_generic(nrows, nrows.min(ncols)); @@ -226,7 +232,9 @@ where /// Computes the orthogonal matrix `V_t` of this `U * D * V_t` decomposition. pub fn v_t(&self) -> MatrixMN, C> - where DefaultAllocator: Allocator, C> { + where + DefaultAllocator: Allocator, C>, + { let (nrows, ncols) = self.uv.data.shape(); let min_nrows_ncols = nrows.min(ncols); @@ -259,13 +267,17 @@ where /// The diagonal part of this decomposed matrix. pub fn diagonal(&self) -> VectorN> - where DefaultAllocator: Allocator> { + where + DefaultAllocator: Allocator>, + { self.diagonal.map(|e| e.modulus()) } /// The off-diagonal part of this decomposed matrix. pub fn off_diagonal(&self) -> VectorN, U1>> - where DefaultAllocator: Allocator, U1>> { + where + DefaultAllocator: Allocator, U1>>, + { self.off_diagonal.map(|e| e.modulus()) } diff --git a/src/linalg/cholesky.rs b/src/linalg/cholesky.rs index 0e2fec0b..da3549d7 100644 --- a/src/linalg/cholesky.rs +++ b/src/linalg/cholesky.rs @@ -24,7 +24,8 @@ use crate::storage::{Storage, StorageMut}; )] #[derive(Clone, Debug)] pub struct Cholesky -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { chol: MatrixN, } @@ -37,7 +38,8 @@ where } impl> Cholesky -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// Attempts to compute the Cholesky decomposition of `matrix`. /// @@ -325,7 +327,8 @@ where DefaultAllocator: Allocator } impl, S: Storage> SquareMatrix -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// Attempts to compute the Cholesky decomposition of this matrix. /// diff --git a/src/linalg/convolution.rs b/src/linalg/convolution.rs index 29c5f61c..df84c301 100644 --- a/src/linalg/convolution.rs +++ b/src/linalg/convolution.rs @@ -64,7 +64,10 @@ impl> Vector { /// # Errors /// Inputs must satisfy `self.len() >= kernel.len() > 0`. /// - pub fn convolve_valid(&self, kernel: Vector) -> VectorN, D2>> + pub fn convolve_valid( + &self, + kernel: Vector, + ) -> VectorN, D2>> where D1: DimAdd, D2: Dim, diff --git a/src/linalg/determinant.rs b/src/linalg/determinant.rs index f02bf7de..73365d78 100644 --- a/src/linalg/determinant.rs +++ b/src/linalg/determinant.rs @@ -13,7 +13,9 @@ impl, S: Storage> SquareMatri /// If the matrix has a dimension larger than 3, an LU decomposition is used. #[inline] pub fn determinant(&self) -> N - where DefaultAllocator: Allocator + Allocator<(usize, usize), D> { + where + DefaultAllocator: Allocator + Allocator<(usize, usize), D>, + { assert!( self.is_square(), "Unable to compute the determinant of a non-square matrix." diff --git a/src/linalg/full_piv_lu.rs b/src/linalg/full_piv_lu.rs index bdb296c2..bfa6854f 100644 --- a/src/linalg/full_piv_lu.rs +++ b/src/linalg/full_piv_lu.rs @@ -29,7 +29,8 @@ use crate::linalg::PermutationSequence; )] #[derive(Clone, Debug)] pub struct FullPivLU, C: Dim> -where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum> +where + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, { lu: MatrixMN, p: PermutationSequence>, @@ -45,7 +46,8 @@ where } impl, C: Dim> FullPivLU -where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum> +where + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, { /// Computes the LU decomposition with full pivoting of `matrix`. /// @@ -103,7 +105,9 @@ where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimu /// The lower triangular matrix of this decomposition. #[inline] pub fn l(&self) -> MatrixMN> - where DefaultAllocator: Allocator> { + where + DefaultAllocator: Allocator>, + { let (nrows, ncols) = self.lu.data.shape(); let mut m = self.lu.columns_generic(0, nrows.min(ncols)).into_owned(); m.fill_upper_triangle(N::zero(), 1); @@ -114,7 +118,9 @@ where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimu /// The upper triangular matrix of this decomposition. #[inline] pub fn u(&self) -> MatrixMN, C> - where DefaultAllocator: Allocator, C> { + where + DefaultAllocator: Allocator, C>, + { let (nrows, ncols) = self.lu.data.shape(); self.lu.rows_generic(0, nrows.min(ncols)).upper_triangle() } @@ -141,7 +147,8 @@ where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimu MatrixMN, C>, PermutationSequence>, ) - where DefaultAllocator: Allocator> + Allocator, C> + where + DefaultAllocator: Allocator> + Allocator, C>, { // Use reallocation for either l or u. let l = self.l(); @@ -154,7 +161,8 @@ where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimu } impl> FullPivLU -where DefaultAllocator: Allocator + Allocator<(usize, usize), D> +where + DefaultAllocator: Allocator + Allocator<(usize, usize), D>, { /// Solves the linear system `self * x = b`, where `x` is the unknown to be determined. /// @@ -259,7 +267,8 @@ where DefaultAllocator: Allocator + Allocator<(usize, usize), D> } impl, C: Dim, S: Storage> Matrix -where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum> +where + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, { /// Computes the LU decomposition with full pivoting of `matrix`. /// diff --git a/src/linalg/hessenberg.rs b/src/linalg/hessenberg.rs index 37dea77e..57a24097 100644 --- a/src/linalg/hessenberg.rs +++ b/src/linalg/hessenberg.rs @@ -27,7 +27,8 @@ use crate::linalg::householder; )] #[derive(Clone, Debug)] pub struct Hessenberg> -where DefaultAllocator: Allocator + Allocator> +where + DefaultAllocator: Allocator + Allocator>, { hess: MatrixN, subdiag: VectorN>, @@ -42,7 +43,8 @@ where } impl> Hessenberg -where DefaultAllocator: Allocator + Allocator + Allocator> +where + DefaultAllocator: Allocator + Allocator + Allocator>, { /// Computes the Hessenberg decomposition using householder reflections. pub fn new(hess: MatrixN) -> Self { @@ -131,7 +133,8 @@ where DefaultAllocator: Allocator + Allocator + Allocator, S: Storage> SquareMatrix -where DefaultAllocator: Allocator + Allocator + Allocator> +where + DefaultAllocator: Allocator + Allocator + Allocator>, { /// Computes the Hessenberg decomposition of this matrix using householder reflections. pub fn hessenberg(self) -> Hessenberg { diff --git a/src/linalg/householder.rs b/src/linalg/householder.rs index a804656d..9f4c9e69 100644 --- a/src/linalg/householder.rs +++ b/src/linalg/householder.rs @@ -109,7 +109,9 @@ pub fn clear_row_unchecked( /// matrices. #[doc(hidden)] pub fn assemble_q(m: &MatrixN, signs: &[N]) -> MatrixN -where DefaultAllocator: Allocator { +where + DefaultAllocator: Allocator, +{ assert!(m.is_square()); let dim = m.data.shape().0; diff --git a/src/linalg/inverse.rs b/src/linalg/inverse.rs index 6e0d6661..79d64121 100644 --- a/src/linalg/inverse.rs +++ b/src/linalg/inverse.rs @@ -12,7 +12,9 @@ impl> SquareMatrix { #[inline] #[must_use = "Did you mean to use try_inverse_mut()?"] pub fn try_inverse(self) -> Option> - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { let mut me = self.into_owned(); if me.try_inverse_mut() { Some(me) @@ -27,7 +29,9 @@ impl> SquareMatrix { /// inversion fails. #[inline] pub fn try_inverse_mut(&mut self) -> bool - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { assert!(self.is_square(), "Unable to invert a non-square matrix."); let dim = self.shape().0; diff --git a/src/linalg/lu.rs b/src/linalg/lu.rs index fc94ba8b..b3acaaa0 100644 --- a/src/linalg/lu.rs +++ b/src/linalg/lu.rs @@ -29,7 +29,8 @@ use crate::linalg::PermutationSequence; )] #[derive(Clone, Debug)] pub struct LU, C: Dim> -where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum> +where + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, { lu: MatrixMN, p: PermutationSequence>, @@ -84,7 +85,8 @@ where } impl, C: Dim> LU -where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum> +where + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, { /// Computes the LU decomposition with partial (row) pivoting of `matrix`. pub fn new(mut matrix: MatrixMN) -> Self { @@ -126,7 +128,9 @@ where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimu /// The lower triangular matrix of this decomposition. #[inline] pub fn l(&self) -> MatrixMN> - where DefaultAllocator: Allocator> { + where + DefaultAllocator: Allocator>, + { let (nrows, ncols) = self.lu.data.shape(); let mut m = self.lu.columns_generic(0, nrows.min(ncols)).into_owned(); m.fill_upper_triangle(N::zero(), 1); @@ -141,7 +145,9 @@ where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimu MatrixMN>, PermutationSequence>, ) - where DefaultAllocator: Reallocator> { + where + DefaultAllocator: Reallocator>, + { let (nrows, ncols) = self.lu.data.shape(); let mut m = self.lu.resize_generic(nrows, nrows.min(ncols), N::zero()); m.fill_upper_triangle(N::zero(), 1); @@ -152,7 +158,9 @@ where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimu /// The lower triangular matrix of this decomposition. #[inline] pub fn l_unpack(self) -> MatrixMN> - where DefaultAllocator: Reallocator> { + where + DefaultAllocator: Reallocator>, + { let (nrows, ncols) = self.lu.data.shape(); let mut m = self.lu.resize_generic(nrows, nrows.min(ncols), N::zero()); m.fill_upper_triangle(N::zero(), 1); @@ -163,7 +171,9 @@ where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimu /// The upper triangular matrix of this decomposition. #[inline] pub fn u(&self) -> MatrixMN, C> - where DefaultAllocator: Allocator, C> { + where + DefaultAllocator: Allocator, C>, + { let (nrows, ncols) = self.lu.data.shape(); self.lu.rows_generic(0, nrows.min(ncols)).upper_triangle() } @@ -183,9 +193,11 @@ where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimu MatrixMN>, MatrixMN, C>, ) - where DefaultAllocator: Allocator> + where + DefaultAllocator: Allocator> + Allocator, C> - + Reallocator> { + + Reallocator>, + { // Use reallocation for either l or u. let u = self.u(); let (l, p) = self.l_unpack_with_p(); @@ -195,7 +207,8 @@ where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimu } impl> LU -where DefaultAllocator: Allocator + Allocator<(usize, usize), D> +where + DefaultAllocator: Allocator + Allocator<(usize, usize), D>, { /// Solves the linear system `self * x = b`, where `x` is the unknown to be determined. /// @@ -368,7 +381,8 @@ pub fn gauss_step_swap( } impl, C: Dim, S: Storage> Matrix -where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum> +where + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, { /// Computes the LU decomposition with partial (row) pivoting of `matrix`. pub fn lu(self) -> LU { diff --git a/src/linalg/mod.rs b/src/linalg/mod.rs index b6a9e8d8..de1108f7 100644 --- a/src/linalg/mod.rs +++ b/src/linalg/mod.rs @@ -3,6 +3,7 @@ pub mod balancing; mod bidiagonal; mod cholesky; +mod convolution; mod determinant; mod full_piv_lu; pub mod givens; @@ -17,7 +18,6 @@ mod solve; mod svd; mod symmetric_eigen; mod symmetric_tridiagonal; -mod convolution; //// FIXME: Not complete enough for publishing. //// This handles only cases where each eigenvalue has multiplicity one. @@ -25,6 +25,7 @@ mod convolution; pub use self::bidiagonal::*; pub use self::cholesky::*; +pub use self::convolution::*; pub use self::full_piv_lu::*; pub use self::hessenberg::*; pub use self::lu::*; @@ -34,4 +35,3 @@ pub use self::schur::*; pub use self::svd::*; pub use self::symmetric_eigen::*; pub use self::symmetric_tridiagonal::*; -pub use self::convolution::*; diff --git a/src/linalg/permutation_sequence.rs b/src/linalg/permutation_sequence.rs index 5d295dcb..0b45510c 100644 --- a/src/linalg/permutation_sequence.rs +++ b/src/linalg/permutation_sequence.rs @@ -25,7 +25,8 @@ use crate::storage::StorageMut; )] #[derive(Clone, Debug)] pub struct PermutationSequence -where DefaultAllocator: Allocator<(usize, usize), D> +where + DefaultAllocator: Allocator<(usize, usize), D>, { len: usize, ipiv: VectorN<(usize, usize), D>, @@ -39,7 +40,8 @@ where } impl PermutationSequence -where DefaultAllocator: Allocator<(usize, usize), D> +where + DefaultAllocator: Allocator<(usize, usize), D>, { /// Creates a new statically-allocated sequence of `D` identity permutations. #[inline] @@ -50,7 +52,8 @@ where DefaultAllocator: Allocator<(usize, usize), D> #[cfg(any(feature = "std", feature = "alloc"))] impl PermutationSequence -where DefaultAllocator: Allocator<(usize, usize), Dynamic> +where + DefaultAllocator: Allocator<(usize, usize), Dynamic>, { /// Creates a new dynamically-allocated sequence of `n` identity permutations. #[inline] @@ -60,7 +63,8 @@ where DefaultAllocator: Allocator<(usize, usize), Dynamic> } impl PermutationSequence -where DefaultAllocator: Allocator<(usize, usize), D> +where + DefaultAllocator: Allocator<(usize, usize), D>, { /// Creates a new sequence of D identity permutations. #[inline] @@ -90,7 +94,9 @@ where DefaultAllocator: Allocator<(usize, usize), D> /// Applies this sequence of permutations to the rows of `rhs`. #[inline] pub fn permute_rows(&self, rhs: &mut Matrix) - where S2: StorageMut { + where + S2: StorageMut, + { for i in self.ipiv.rows_range(..self.len).iter() { rhs.swap_rows(i.0, i.1) } @@ -98,10 +104,8 @@ where DefaultAllocator: Allocator<(usize, usize), D> /// Applies this sequence of permutations in reverse to the rows of `rhs`. #[inline] - pub fn inv_permute_rows( - &self, - rhs: &mut Matrix, - ) where + pub fn inv_permute_rows(&self, rhs: &mut Matrix) + where S2: StorageMut, { for i in 0..self.len { @@ -112,10 +116,8 @@ where DefaultAllocator: Allocator<(usize, usize), D> /// Applies this sequence of permutations to the columns of `rhs`. #[inline] - pub fn permute_columns( - &self, - rhs: &mut Matrix, - ) where + pub fn permute_columns(&self, rhs: &mut Matrix) + where S2: StorageMut, { for i in self.ipiv.rows_range(..self.len).iter() { diff --git a/src/linalg/qr.rs b/src/linalg/qr.rs index acd02c6b..f218d47b 100644 --- a/src/linalg/qr.rs +++ b/src/linalg/qr.rs @@ -30,7 +30,8 @@ use crate::linalg::householder; )] #[derive(Clone, Debug)] pub struct QR, C: Dim> -where DefaultAllocator: Allocator + Allocator> +where + DefaultAllocator: Allocator + Allocator>, { qr: MatrixMN, diag: VectorN>, @@ -45,7 +46,8 @@ where } impl, C: Dim> QR -where DefaultAllocator: Allocator + Allocator + Allocator> +where + DefaultAllocator: Allocator + Allocator + Allocator>, { /// Computes the QR decomposition using householder reflections. pub fn new(mut matrix: MatrixMN) -> Self { @@ -74,7 +76,9 @@ where DefaultAllocator: Allocator + Allocator + Allocator MatrixMN, C> - where DefaultAllocator: Allocator, C> { + where + DefaultAllocator: Allocator, C>, + { let (nrows, ncols) = self.qr.data.shape(); let mut res = self.qr.rows_generic(0, nrows.min(ncols)).upper_triangle(); res.set_partial_diagonal(self.diag.iter().map(|e| N::from_real(e.modulus()))); @@ -86,7 +90,9 @@ where DefaultAllocator: Allocator + Allocator + Allocator MatrixMN, C> - where DefaultAllocator: Reallocator, C> { + where + DefaultAllocator: Reallocator, C>, + { let (nrows, ncols) = self.qr.data.shape(); let mut res = self.qr.resize_generic(nrows.min(ncols), ncols, N::zero()); res.fill_lower_triangle(N::zero(), 1); @@ -96,7 +102,9 @@ where DefaultAllocator: Allocator + Allocator + Allocator MatrixMN> - where DefaultAllocator: Allocator> { + where + DefaultAllocator: Allocator>, + { let (nrows, ncols) = self.qr.data.shape(); // NOTE: we could build the identity matrix and call q_mul on it. @@ -139,7 +147,9 @@ where DefaultAllocator: Allocator + Allocator + Allocator(&self, rhs: &mut Matrix) // FIXME: do we need a static constraint on the number of rows of rhs? - where S2: StorageMut { + where + S2: StorageMut, + { let dim = self.diag.len(); for i in 0..dim { @@ -153,7 +163,8 @@ where DefaultAllocator: Allocator + Allocator + Allocator> QR -where DefaultAllocator: Allocator + Allocator +where + DefaultAllocator: Allocator + Allocator, { /// Solves the linear system `self * x = b`, where `x` is the unknown to be determined. /// @@ -285,7 +296,8 @@ where DefaultAllocator: Allocator + Allocator } impl, C: Dim, S: Storage> Matrix -where DefaultAllocator: Allocator + Allocator + Allocator> +where + DefaultAllocator: Allocator + Allocator + Allocator>, { /// Computes the QR decomposition of this matrix. pub fn qr(self) -> QR { diff --git a/src/linalg/schur.rs b/src/linalg/schur.rs index 1fb4de2b..99e73ea1 100644 --- a/src/linalg/schur.rs +++ b/src/linalg/schur.rs @@ -32,7 +32,8 @@ use crate::linalg::Hessenberg; )] #[derive(Clone, Debug)] pub struct Schur -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { q: MatrixN, t: MatrixN, @@ -84,8 +85,7 @@ where eps: N::RealField, max_niter: usize, compute_q: bool, - ) -> Option<(Option>, MatrixN)> - { + ) -> Option<(Option>, MatrixN)> { assert!( m.is_square(), "Unable to compute the eigenvectors and eigenvalues of a non-square matrix." diff --git a/src/linalg/svd.rs b/src/linalg/svd.rs index ac33829c..6d74a438 100644 --- a/src/linalg/svd.rs +++ b/src/linalg/svd.rs @@ -41,9 +41,10 @@ use crate::linalg::Bidiagonal; )] #[derive(Clone, Debug)] pub struct SVD, C: Dim> -where DefaultAllocator: Allocator, C> +where + DefaultAllocator: Allocator, C> + Allocator> - + Allocator> + + Allocator>, { /// The left-singular vectors `U` of this SVD. pub u: Option>>, @@ -105,8 +106,7 @@ where compute_v: bool, eps: N::RealField, max_niter: usize, - ) -> Option - { + ) -> Option { assert!( matrix.len() != 0, "Cannot compute the SVD of an empty matrix." @@ -333,8 +333,7 @@ where is_upper_diagonal: bool, end: usize, eps: N::RealField, - ) -> (usize, usize) - { + ) -> (usize, usize) { let mut n = end; while n > 0 { @@ -437,8 +436,7 @@ where is_upper_diagonal: bool, i: usize, end: usize, - ) - { + ) { let mut v = Vector2::new(off_diagonal[i], diagonal[i + 1]); off_diagonal[i] = N::RealField::zero(); @@ -475,8 +473,7 @@ where v_t: &mut Option, C>>, is_upper_diagonal: bool, i: usize, - ) - { + ) { let mut v = Vector2::new(diagonal[i], off_diagonal[i]); off_diagonal[i] = N::RealField::zero(); @@ -541,7 +538,9 @@ where /// Returns `Err` if the right- and left- singular vectors have not /// been computed at construction-time. pub fn pseudo_inverse(mut self, eps: N::RealField) -> Result, &'static str> - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { if eps < N::RealField::zero() { Err("SVD pseudo inverse: the epsilon must be non-negative.") } else { @@ -638,8 +637,7 @@ where compute_v: bool, eps: N::RealField, max_niter: usize, - ) -> Option> - { + ) -> Option> { SVD::try_new(self.into_owned(), compute_u, compute_v, eps, max_niter) } @@ -660,7 +658,9 @@ where /// /// All singular values below `eps` are considered equal to 0. pub fn pseudo_inverse(self, eps: N::RealField) -> Result, &'static str> - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { SVD::new(self.clone_owned(), true, true).pseudo_inverse(eps) } } @@ -678,8 +678,7 @@ fn compute_2x2_uptrig_svd( Option>, Vector2, Option>, -) -{ +) { let two: N::RealField = crate::convert(2.0f64); let half: N::RealField = crate::convert(0.5f64); diff --git a/src/linalg/symmetric_eigen.rs b/src/linalg/symmetric_eigen.rs index 54fa2e84..70f57cdf 100644 --- a/src/linalg/symmetric_eigen.rs +++ b/src/linalg/symmetric_eigen.rs @@ -31,7 +31,8 @@ use crate::linalg::SymmetricTridiagonal; )] #[derive(Clone, Debug)] pub struct SymmetricEigen -where DefaultAllocator: Allocator + Allocator +where + DefaultAllocator: Allocator + Allocator, { /// The eigenvectors of the decomposed matrix. pub eigenvectors: MatrixN, @@ -49,7 +50,8 @@ where } impl SymmetricEigen -where DefaultAllocator: Allocator + Allocator +where + DefaultAllocator: Allocator + Allocator, { /// Computes the eigendecomposition of the given symmetric matrix. /// @@ -300,10 +302,11 @@ pub fn wilkinson_shift(tmm: N, tnn: N, tmn: N) -> N { * */ impl, S: Storage> SquareMatrix -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator + Allocator> + Allocator - + Allocator> + + Allocator>, { /// Computes the eigendecomposition of this symmetric matrix. /// @@ -327,8 +330,7 @@ where DefaultAllocator: Allocator self, eps: N::RealField, max_niter: usize, - ) -> Option> - { + ) -> Option> { SymmetricEigen::try_new(self.into_owned(), eps, max_niter) } diff --git a/src/linalg/symmetric_tridiagonal.rs b/src/linalg/symmetric_tridiagonal.rs index 49502efa..f4dc13ba 100644 --- a/src/linalg/symmetric_tridiagonal.rs +++ b/src/linalg/symmetric_tridiagonal.rs @@ -27,7 +27,8 @@ use crate::linalg::householder; )] #[derive(Clone, Debug)] pub struct SymmetricTridiagonal> -where DefaultAllocator: Allocator + Allocator> +where + DefaultAllocator: Allocator + Allocator>, { tri: MatrixN, off_diagonal: VectorN>, @@ -42,7 +43,8 @@ where } impl> SymmetricTridiagonal -where DefaultAllocator: Allocator + Allocator> +where + DefaultAllocator: Allocator + Allocator>, { /// Computes the tridiagonalization of the symmetric matrix `m`. /// @@ -102,7 +104,8 @@ where DefaultAllocator: Allocator + Allocator> VectorN, VectorN>, ) - where DefaultAllocator: Allocator + Allocator> + where + DefaultAllocator: Allocator + Allocator>, { let diag = self.diagonal(); let q = self.q(); @@ -117,20 +120,25 @@ where DefaultAllocator: Allocator + Allocator> VectorN, VectorN>, ) - where DefaultAllocator: Allocator + Allocator> + where + DefaultAllocator: Allocator + Allocator>, { (self.diagonal(), self.off_diagonal.map(N::modulus)) } /// The diagonal components of this decomposition. pub fn diagonal(&self) -> VectorN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self.tri.map_diagonal(|e| e.real()) } /// The off-diagonal components of this decomposition. pub fn off_diagonal(&self) -> VectorN> - where DefaultAllocator: Allocator> { + where + DefaultAllocator: Allocator>, + { self.off_diagonal.map(N::modulus) } @@ -156,7 +164,8 @@ where DefaultAllocator: Allocator + Allocator> } impl, S: Storage> SquareMatrix -where DefaultAllocator: Allocator + Allocator> +where + DefaultAllocator: Allocator + Allocator>, { /// Computes the tridiagonalization of this symmetric matrix. /// diff --git a/src/sparse/cs_matrix_cholesky.rs b/src/sparse/cs_matrix_cholesky.rs index 4c3fffd8..db3c221a 100644 --- a/src/sparse/cs_matrix_cholesky.rs +++ b/src/sparse/cs_matrix_cholesky.rs @@ -7,7 +7,8 @@ use crate::{DefaultAllocator, Dim, RealField, VectorN, U1}; /// The cholesky decomposition of a column compressed sparse matrix. pub struct CsCholesky -where DefaultAllocator: Allocator + Allocator +where + DefaultAllocator: Allocator + Allocator, { // Non-zero pattern of the original matrix upper-triangular part. // Unlike the original matrix, the `original_p` array does contain the last sentinel value @@ -26,7 +27,8 @@ where DefaultAllocator: Allocator + Allocator } impl CsCholesky -where DefaultAllocator: Allocator + Allocator +where + DefaultAllocator: Allocator + Allocator, { /// Computes the cholesky decomposition of the sparse matrix `m`. pub fn new(m: &CsMatrix) -> Self { @@ -260,8 +262,7 @@ where DefaultAllocator: Allocator + Allocator tree: &[usize], marks: &mut Vec, out: &mut Vec, - ) - { + ) { marks.clear(); marks.resize(tree.len(), false); @@ -333,24 +334,24 @@ where DefaultAllocator: Allocator + Allocator let mut counts: Vec<_> = iter::repeat(0).take(len).collect(); let mut reach = Vec::new(); let mut marks = Vec::new(); - + for i in 0..len { Self::reach(m, i, i, tree, &mut marks, &mut reach); - + for j in reach.drain(..) { counts[j] += 1; } } - + counts } - + fn tree_postorder(tree: &[usize]) -> Vec { // FIXME: avoid all those allocations? let mut first_child: Vec<_> = iter::repeat(usize::max_value()).take(tree.len()).collect(); let mut other_children: Vec<_> = iter::repeat(usize::max_value()).take(tree.len()).collect(); - + // Build the children list from the parent list. // The set of children of the node `i` is given by the linked list // starting at `first_child[i]`. The nodes of this list are then: @@ -362,10 +363,10 @@ where DefaultAllocator: Allocator + Allocator other_children[i] = brother; } } - + let mut stack = Vec::with_capacity(tree.len()); let mut postorder = Vec::with_capacity(tree.len()); - + for (i, node) in tree.iter().enumerate() { if *node == usize::max_value() { Self::dfs( @@ -377,10 +378,10 @@ where DefaultAllocator: Allocator + Allocator ) } } - + postorder } - + fn dfs( i: usize, first_child: &mut [usize], @@ -390,10 +391,10 @@ where DefaultAllocator: Allocator + Allocator ) { stack.clear(); stack.push(i); - + while let Some(n) = stack.pop() { let child = first_child[n]; - + if child == usize::max_value() { // No children left. result.push(n); diff --git a/src/sparse/cs_matrix_conversion.rs b/src/sparse/cs_matrix_conversion.rs index 63a417b2..8025f94e 100644 --- a/src/sparse/cs_matrix_conversion.rs +++ b/src/sparse/cs_matrix_conversion.rs @@ -15,14 +15,14 @@ impl<'a, N: Scalar + Zero + ClosedAdd> CsMatrix { irows: &[usize], icols: &[usize], vals: &[N], - ) -> Self - { + ) -> Self { Self::from_triplet_generic(Dynamic::new(nrows), Dynamic::new(ncols), irows, icols, vals) } } impl<'a, N: Scalar + Zero + ClosedAdd, R: Dim, C: Dim> CsMatrix -where DefaultAllocator: Allocator + Allocator +where + DefaultAllocator: Allocator + Allocator, { /// Creates a column-compressed sparse matrix from a sparse matrix in triplet form. pub fn from_triplet_generic( @@ -31,8 +31,7 @@ where DefaultAllocator: Allocator + Allocator irows: &[usize], icols: &[usize], vals: &[N], - ) -> Self - { + ) -> Self { assert!(vals.len() == irows.len()); assert!(vals.len() == icols.len()); diff --git a/src/sparse/cs_matrix_solve.rs b/src/sparse/cs_matrix_solve.rs index 14ca9f78..73b50db3 100644 --- a/src/sparse/cs_matrix_solve.rs +++ b/src/sparse/cs_matrix_solve.rs @@ -264,8 +264,7 @@ impl> CsMatrix { visited: &mut [bool], stack: &mut Vec, xi: &mut Vec, - ) - { + ) { if !visited[start] { stack.clear(); stack.push(start); diff --git a/src/sparse/cs_utils.rs b/src/sparse/cs_utils.rs index a8a454eb..c73b9639 100644 --- a/src/sparse/cs_utils.rs +++ b/src/sparse/cs_utils.rs @@ -2,7 +2,9 @@ use crate::allocator::Allocator; use crate::{DefaultAllocator, Dim, VectorN}; pub fn cumsum(a: &mut VectorN, b: &mut VectorN) -> usize -where DefaultAllocator: Allocator { +where + DefaultAllocator: Allocator, +{ assert!(a.len() == b.len()); let mut sum = 0; diff --git a/tests/core/conversion.rs b/tests/core/conversion.rs index 783654ca..74aa41e9 100644 --- a/tests/core/conversion.rs +++ b/tests/core/conversion.rs @@ -8,10 +8,10 @@ use na::{ RowVector4, RowVector5, RowVector6, Similarity3, Transform3, Translation3, UnitQuaternion, Vector1, Vector2, Vector3, Vector4, Vector5, Vector6, }; +use na::{DMatrix, DMatrixSlice, DMatrixSliceMut, MatrixSlice, MatrixSliceMut}; use na::{U1, U3, U4}; -use na::{DMatrix, MatrixSlice, MatrixSliceMut, DMatrixSlice, DMatrixSliceMut}; -quickcheck!{ +quickcheck! { fn translation_conversion(t: Translation3, v: Vector3, p: Point3) -> bool { let iso: Isometry3 = na::convert(t); let sim: Similarity3 = na::convert(t); @@ -255,9 +255,9 @@ array_matrix_conversion!( #[test] fn matrix_slice_from_matrix_ref() { - let a = Matrix3x4::new(11.0, 12.0, 13.0, 14.0, - 21.0, 22.0, 23.0, 24.0, - 31.0, 32.0, 33.0, 34.0); + let a = Matrix3x4::new( + 11.0, 12.0, 13.0, 14.0, 21.0, 22.0, 23.0, 24.0, 31.0, 32.0, 33.0, 34.0, + ); // TODO: What's a more idiomatic/better way to convert a static matrix to a dynamic one? let d = DMatrix::from(a.get((0..a.nrows(), 0..a.ncols())).unwrap()); @@ -265,11 +265,25 @@ fn matrix_slice_from_matrix_ref() { // Note: these have to be macros, and not functions, because the input type is different // across the different tests. Moreover, the output type depends on the stride of the input, // which is different for static and dynamic matrices. - macro_rules! dynamic_slice { ($mref:expr) => { DMatrixSlice::<_>::from($mref) } } - macro_rules! dynamic_slice_mut { ($mref:expr) => { DMatrixSliceMut::<_>::from($mref) } } - macro_rules! fixed_slice { ($mref:expr) => { MatrixSlice::<_, U3, U4, U1, U3>::from($mref)} }; + macro_rules! dynamic_slice { + ($mref:expr) => { + DMatrixSlice::<_>::from($mref) + }; + } + macro_rules! dynamic_slice_mut { + ($mref:expr) => { + DMatrixSliceMut::<_>::from($mref) + }; + } + macro_rules! fixed_slice { + ($mref:expr) => { + MatrixSlice::<_, U3, U4, U1, U3>::from($mref) + }; + }; macro_rules! fixed_slice_mut { - ($mref:expr) => { MatrixSliceMut::<_, U3, U4, U1, U3>::from($mref) } + ($mref:expr) => { + MatrixSliceMut::<_, U3, U4, U1, U3>::from($mref) + }; }; // TODO: The `into_owned()` is a result of `PartialEq` not being implemented for different diff --git a/tests/core/empty.rs b/tests/core/empty.rs index 3e17ee1b..f2a52e6d 100644 --- a/tests/core/empty.rs +++ b/tests/core/empty.rs @@ -57,4 +57,4 @@ fn empty_matrix_gemm_tr() { let m2 = DMatrix::::zeros(0, 4); res.gemm_tr(1.0, &m1, &m2, 0.5); assert_eq!(res, DMatrix::repeat(3, 4, 0.5)); -} \ No newline at end of file +} diff --git a/tests/core/helper.rs b/tests/core/helper.rs index 625a4a46..42938580 100644 --- a/tests/core/helper.rs +++ b/tests/core/helper.rs @@ -1,11 +1,11 @@ // This module implement several methods to fill some // missing features of num-complex when it comes to randomness. -use quickcheck::{Arbitrary, Gen}; -use rand::distributions::{Standard, Distribution}; -use rand::Rng; -use num_complex::Complex; use na::RealField; +use num_complex::Complex; +use quickcheck::{Arbitrary, Gen}; +use rand::distributions::{Distribution, Standard}; +use rand::Rng; #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct RandComplex(pub Complex); @@ -20,8 +20,8 @@ impl Arbitrary for RandComplex { } impl Distribution> for Standard - where - Standard: Distribution, +where + Standard: Distribution, { #[inline] fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> RandComplex { @@ -44,11 +44,11 @@ impl Arbitrary for RandScalar { } impl Distribution> for Standard - where - Standard: Distribution, +where + Standard: Distribution, { #[inline] fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> RandScalar { RandScalar(self.sample(rng)) } -} \ No newline at end of file +} diff --git a/tests/core/mod.rs b/tests/core/mod.rs index f8c7e477..6e897c85 100644 --- a/tests/core/mod.rs +++ b/tests/core/mod.rs @@ -5,11 +5,10 @@ mod conversion; mod edition; mod matrix; mod matrix_slice; +mod empty; #[cfg(feature = "mint")] mod mint; mod serde; -mod empty; - #[cfg(feature = "arbitrary")] -pub mod helper; \ No newline at end of file +pub mod helper; diff --git a/tests/core/serde.rs b/tests/core/serde.rs index 781ace77..aced2a9f 100644 --- a/tests/core/serde.rs +++ b/tests/core/serde.rs @@ -1,9 +1,9 @@ #![cfg(feature = "serde-serialize")] use na::{ - DMatrix, Isometry3, IsometryMatrix3, Matrix3x4, Point3, Quaternion, Rotation3, Similarity3, - SimilarityMatrix3, Translation3, Unit, Point2, Translation2, Rotation2, Isometry2, IsometryMatrix2, - Similarity2, SimilarityMatrix2, + DMatrix, Isometry2, Isometry3, IsometryMatrix2, IsometryMatrix3, Matrix3x4, Point2, Point3, + Quaternion, Rotation2, Rotation3, Similarity2, Similarity3, SimilarityMatrix2, + SimilarityMatrix3, Translation2, Translation3, Unit, }; use rand; use serde_json; diff --git a/tests/geometry/isometry.rs b/tests/geometry/isometry.rs index ecf29e94..710c4ba9 100644 --- a/tests/geometry/isometry.rs +++ b/tests/geometry/isometry.rs @@ -81,9 +81,8 @@ quickcheck!( r: Rotation2, t: Translation2, v: Vector2, - p: Point2 - ) -> bool - { + p: Point2, + ) -> bool { // (rotation × translation) * point = rotation × (translation * point) relative_eq!((uc * t) * v, uc * v, epsilon = 1.0e-7) && relative_eq!((r * t) * v, r * v, epsilon = 1.0e-7) && @@ -119,9 +118,8 @@ quickcheck!( r: Rotation3, t: Translation3, v: Vector3, - p: Point3 - ) -> bool - { + p: Point3, + ) -> bool { // (rotation × translation) * point = rotation × (translation * point) relative_eq!((uq * t) * v, uq * v, epsilon = 1.0e-7) && relative_eq!((r * t) * v, r * v, epsilon = 1.0e-7) && @@ -157,9 +155,8 @@ quickcheck!( t: Translation3, v: Vector3, p: Point3, - r: Rotation3 - ) -> bool - { + r: Rotation3, + ) -> bool { let iMi = i * i; let iMuq = i * uq; let iDi = i / i; diff --git a/tests/geometry/projection.rs b/tests/geometry/projection.rs index 03c6d4df..626c4ffb 100644 --- a/tests/geometry/projection.rs +++ b/tests/geometry/projection.rs @@ -37,7 +37,7 @@ fn perspective_matrix_point_transformation() { mod quickcheck_tests { use na::{Orthographic3, Perspective3, Point3}; - quickcheck!{ + quickcheck! { fn perspective_project_unproject(pt: Point3) -> bool { let proj = Perspective3::new(800.0 / 600.0, 3.14 / 2.0, 1.0, 1000.0); diff --git a/tests/geometry/similarity.rs b/tests/geometry/similarity.rs index a5736864..e8e417ef 100644 --- a/tests/geometry/similarity.rs +++ b/tests/geometry/similarity.rs @@ -18,9 +18,8 @@ quickcheck!( fn inverse_is_parts_inversion( t: Translation3, r: UnitQuaternion, - scaling: f64 - ) -> bool - { + scaling: f64, + ) -> bool { if relative_eq!(scaling, 0.0) { true } else { @@ -32,9 +31,8 @@ quickcheck!( fn multiply_equals_alga_transform( s: Similarity3, v: Vector3, - p: Point3 - ) -> bool - { + p: Point3, + ) -> bool { s * v == s.transform_vector(&v) && s * p == s.transform_point(&p) && relative_eq!( @@ -55,9 +53,8 @@ quickcheck!( t: Translation3, v: Vector3, p: Point3, - scaling: f64 - ) -> bool - { + scaling: f64, + ) -> bool { if relative_eq!(scaling, 0.0) { return true; } @@ -151,9 +148,8 @@ quickcheck!( uq: UnitQuaternion, t: Translation3, v: Vector3, - p: Point3 - ) -> bool - { + p: Point3, + ) -> bool { let sMs = s * s; let sMuq = s * uq; let sDs = s / s; diff --git a/tests/geometry/unit_complex.rs b/tests/geometry/unit_complex.rs index 46998036..37af38f9 100644 --- a/tests/geometry/unit_complex.rs +++ b/tests/geometry/unit_complex.rs @@ -72,9 +72,8 @@ quickcheck!( uc: UnitComplex, v: Vector2, p: Point2, - r: Rotation2 - ) -> bool - { + r: Rotation2, + ) -> bool { let uv = Unit::new_normalize(v); let ucMuc = uc * uc; diff --git a/tests/linalg/bidiagonal.rs b/tests/linalg/bidiagonal.rs index 9778eea3..8fefb4a2 100644 --- a/tests/linalg/bidiagonal.rs +++ b/tests/linalg/bidiagonal.rs @@ -75,4 +75,4 @@ fn bidiagonal_identity() { let bidiagonal = m.clone().bidiagonalize(); let (u, d, v_t) = bidiagonal.unpack(); assert_eq!(m, &u * d * &v_t); -} \ No newline at end of file +} diff --git a/tests/linalg/convolution.rs b/tests/linalg/convolution.rs index 65380162..84f42a6e 100644 --- a/tests/linalg/convolution.rs +++ b/tests/linalg/convolution.rs @@ -1,4 +1,4 @@ -use na::{Vector2,Vector3,Vector4,Vector5,DVector}; +use na::{DVector, Vector2, Vector3, Vector4, Vector5}; use std::panic; // @@ -9,111 +9,109 @@ use std::panic; // >>> convolve([1,2,3,4],[1,2],"same") // array([ 1, 4, 7, 10]) #[test] -fn convolve_same_check(){ +fn convolve_same_check() { // Static Tests - let actual_s = Vector4::new(1.0, 4.0, 7.0, 10.0); + let actual_s = Vector4::new(1.0, 4.0, 7.0, 10.0); let expected_s = Vector4::new(1.0, 2.0, 3.0, 4.0).convolve_same(Vector2::new(1.0, 2.0)); assert!(relative_eq!(actual_s, expected_s, epsilon = 1.0e-7)); // Dynamic Tests - let actual_d = DVector::from_vec(vec![1.0, 4.0, 7.0, 10.0]); - let expected_d = DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0]).convolve_same(DVector::from_vec(vec![1.0, 2.0])); + let actual_d = DVector::from_vec(vec![1.0, 4.0, 7.0, 10.0]); + let expected_d = DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0]) + .convolve_same(DVector::from_vec(vec![1.0, 2.0])); assert!(relative_eq!(actual_d, expected_d, epsilon = 1.0e-7)); // Panic Tests // These really only apply to dynamic sized vectors - assert!( - panic::catch_unwind(|| { - DVector::from_vec(vec![1.0, 2.0]).convolve_same(DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0])); - }).is_err() - ); + assert!(panic::catch_unwind(|| { + DVector::from_vec(vec![1.0, 2.0]) + .convolve_same(DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0])); + }) + .is_err()); - assert!( - panic::catch_unwind(|| { - DVector::::from_vec(vec![]).convolve_same(DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0])); - }).is_err() - ); + assert!(panic::catch_unwind(|| { + DVector::::from_vec(vec![]).convolve_same(DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0])); + }) + .is_err()); - assert!( - panic::catch_unwind(|| { - DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0]).convolve_same(DVector::::from_vec(vec![])); - }).is_err() - ); + assert!(panic::catch_unwind(|| { + DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0]).convolve_same(DVector::::from_vec(vec![])); + }) + .is_err()); } // >>> convolve([1,2,3,4],[1,2],"full") // array([ 1, 4, 7, 10, 8]) #[test] -fn convolve_full_check(){ +fn convolve_full_check() { // Static Tests - let actual_s = Vector5::new(1.0, 4.0, 7.0, 10.0, 8.0); + let actual_s = Vector5::new(1.0, 4.0, 7.0, 10.0, 8.0); let expected_s = Vector4::new(1.0, 2.0, 3.0, 4.0).convolve_full(Vector2::new(1.0, 2.0)); assert!(relative_eq!(actual_s, expected_s, epsilon = 1.0e-7)); // Dynamic Tests - let actual_d = DVector::from_vec(vec![1.0, 4.0, 7.0, 10.0, 8.0]); - let expected_d = DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0]).convolve_full(DVector::from_vec(vec![1.0, 2.0])); + let actual_d = DVector::from_vec(vec![1.0, 4.0, 7.0, 10.0, 8.0]); + let expected_d = DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0]) + .convolve_full(DVector::from_vec(vec![1.0, 2.0])); assert!(relative_eq!(actual_d, expected_d, epsilon = 1.0e-7)); // Panic Tests // These really only apply to dynamic sized vectors - assert!( - panic::catch_unwind(|| { - DVector::from_vec(vec![1.0, 2.0] ).convolve_full(DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0] )); - }).is_err() - ); + assert!(panic::catch_unwind(|| { + DVector::from_vec(vec![1.0, 2.0]) + .convolve_full(DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0])); + }) + .is_err()); - assert!( - panic::catch_unwind(|| { - DVector::::from_vec(vec![]).convolve_full(DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0] )); - }).is_err() - ); + assert!(panic::catch_unwind(|| { + DVector::::from_vec(vec![]).convolve_full(DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0])); + }) + .is_err()); - assert!( - panic::catch_unwind(|| { - DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0] ).convolve_full(DVector::::from_vec(vec![])); - }).is_err() - ); + assert!(panic::catch_unwind(|| { + DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0]).convolve_full(DVector::::from_vec(vec![])); + }) + .is_err()); } // >>> convolve([1, 2, 3, 4],[1, 2],"valid") // array([4, 7, 10]) #[test] -fn convolve_valid_check(){ +fn convolve_valid_check() { // Static Tests - let actual_s = Vector3::from_vec(vec![4.0, 7.0, 10.0]); - let expected_s = Vector4::new(1.0, 2.0, 3.0, 4.0).convolve_valid( Vector2::new(1.0, 2.0)); + let actual_s = Vector3::from_vec(vec![4.0, 7.0, 10.0]); + let expected_s = Vector4::new(1.0, 2.0, 3.0, 4.0).convolve_valid(Vector2::new(1.0, 2.0)); assert!(relative_eq!(actual_s, expected_s, epsilon = 1.0e-7)); // Dynamic Tests - let actual_d = DVector::from_vec(vec![4.0, 7.0, 10.0]); - let expected_d = DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0]).convolve_valid(DVector::from_vec(vec![1.0, 2.0])); + let actual_d = DVector::from_vec(vec![4.0, 7.0, 10.0]); + let expected_d = DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0]) + .convolve_valid(DVector::from_vec(vec![1.0, 2.0])); assert!(relative_eq!(actual_d, expected_d, epsilon = 1.0e-7)); // Panic Tests // These really only apply to dynamic sized vectors - assert!( - panic::catch_unwind(|| { - DVector::from_vec(vec![1.0, 2.0]).convolve_valid(DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0])); - }).is_err() - ); + assert!(panic::catch_unwind(|| { + DVector::from_vec(vec![1.0, 2.0]) + .convolve_valid(DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0])); + }) + .is_err()); - assert!( - panic::catch_unwind(|| { - DVector::::from_vec(vec![]).convolve_valid(DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0])); - }).is_err() - ); + assert!(panic::catch_unwind(|| { + DVector::::from_vec(vec![]) + .convolve_valid(DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0])); + }) + .is_err()); - assert!( - panic::catch_unwind(|| { - DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0]).convolve_valid(DVector::::from_vec(vec![])); - }).is_err() - ); - -} \ No newline at end of file + assert!(panic::catch_unwind(|| { + DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0]) + .convolve_valid(DVector::::from_vec(vec![])); + }) + .is_err()); +} diff --git a/tests/linalg/hessenberg.rs b/tests/linalg/hessenberg.rs index 378fbd87..ec499f82 100644 --- a/tests/linalg/hessenberg.rs +++ b/tests/linalg/hessenberg.rs @@ -2,7 +2,6 @@ use na::Matrix2; - #[test] fn hessenberg_simple() { let m = Matrix2::new(1.0, 0.0, 1.0, 3.0); @@ -11,7 +10,6 @@ fn hessenberg_simple() { assert!(relative_eq!(m, p * h * p.transpose(), epsilon = 1.0e-7)) } - macro_rules! gen_tests( ($module: ident, $scalar: ty) => { mod $module { @@ -49,4 +47,4 @@ macro_rules! gen_tests( ); gen_tests!(complex, RandComplex); -gen_tests!(f64, RandScalar); \ No newline at end of file +gen_tests!(f64, RandScalar); diff --git a/tests/linalg/mod.rs b/tests/linalg/mod.rs index e881d999..234cac39 100644 --- a/tests/linalg/mod.rs +++ b/tests/linalg/mod.rs @@ -10,5 +10,5 @@ mod qr; mod schur; mod solve; mod svd; +mod convolution; mod tridiagonal; -mod convolution; \ No newline at end of file diff --git a/tests/linalg/tridiagonal.rs b/tests/linalg/tridiagonal.rs index 5d04587e..7f7300a1 100644 --- a/tests/linalg/tridiagonal.rs +++ b/tests/linalg/tridiagonal.rs @@ -51,6 +51,5 @@ macro_rules! gen_tests( } ); - gen_tests!(complex, RandComplex); gen_tests!(f64, RandScalar);