From b1616e236ce49bba8ea7c52b38806eecb103c3e6 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Sat, 16 Jun 2018 12:57:57 +0200 Subject: [PATCH] Changed loops order in from_fn_generic --- benches/core/matrix.rs | 18 ++++++++++++++++++ src/base/construction.rs | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/benches/core/matrix.rs b/benches/core/matrix.rs index 2a780fe1..7fe65481 100644 --- a/benches/core/matrix.rs +++ b/benches/core/matrix.rs @@ -186,3 +186,21 @@ fn mat_mul_mat(bench: &mut Bencher) { test::black_box(a.mul_to(&b, &mut ab)); }) } + +#[bench] +fn mat100_from_fn(bench: &mut Bencher) { + bench.iter(|| { + DMatrix::from_fn(100, 100, |a, b| { + a + b + }); + }) +} + +#[bench] +fn mat500_from_fn(bench: &mut Bencher) { + bench.iter(|| { + DMatrix::from_fn(500, 500, |a, b| { + a + b + }); + }) +} diff --git a/src/base/construction.rs b/src/base/construction.rs index f76d1d31..063f005d 100644 --- a/src/base/construction.rs +++ b/src/base/construction.rs @@ -108,8 +108,8 @@ where { let mut res = unsafe { Self::new_uninitialized_generic(nrows, ncols) }; - for i in 0..nrows.value() { - for j in 0..ncols.value() { + for j in 0..ncols.value() { + for i in 0..nrows.value() { unsafe { *res.get_unchecked_mut(i, j) = f(i, j) } } }