From f4c089776438094e33be29405ffe0a28d3c69f0a Mon Sep 17 00:00:00 2001 From: sebcrozet Date: Tue, 21 Apr 2020 10:19:03 +0200 Subject: [PATCH 1/2] Fix compilation of matrix exponential when targetting no-std. --- src/linalg/exp.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/linalg/exp.rs b/src/linalg/exp.rs index 86bd81a7..df375ac9 100644 --- a/src/linalg/exp.rs +++ b/src/linalg/exp.rs @@ -42,7 +42,8 @@ impl ExpmPadeHelper where N: RealField, D: DimMin, - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, + DefaultAllocator: + Allocator + Allocator + Allocator<(usize, usize), DimMinimum>, { fn new(a: MatrixN, use_exact_norm: bool) -> Self { let (nrows, ncols) = a.data.shape(); @@ -405,15 +406,13 @@ where D: Dim, DefaultAllocator: Allocator, { - let mut col_sums = vec![N::zero(); m.ncols()]; + let mut max = N::zero(); + for i in 0..m.ncols() { let col = m.column(i); - col.iter().for_each(|v| col_sums[i] += v.abs()); - } - let mut max = col_sums[0]; - for i in 1..col_sums.len() { - max = N::max(max, col_sums[i]); + max = max.max(col.iter().fold(N::zero(), |a, b| a + b.abs())); } + max } @@ -427,7 +426,7 @@ where pub fn exp(&self) -> Self { // Simple case if self.nrows() == 1 { - return self.clone().map(|v| v.exp()); + return self.map(|v| v.exp()); } let mut h = ExpmPadeHelper::new(self.clone(), true); From 6dc739b70b44a0806d3b10bcc5646cea94696a95 Mon Sep 17 00:00:00 2001 From: sebcrozet Date: Tue, 21 Apr 2020 10:37:14 +0200 Subject: [PATCH 2/2] Remove unused allocator bound. --- src/linalg/exp.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/linalg/exp.rs b/src/linalg/exp.rs index df375ac9..c11fd757 100644 --- a/src/linalg/exp.rs +++ b/src/linalg/exp.rs @@ -42,8 +42,7 @@ impl ExpmPadeHelper where N: RealField, D: DimMin, - DefaultAllocator: - Allocator + Allocator + Allocator<(usize, usize), DimMinimum>, + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, { fn new(a: MatrixN, use_exact_norm: bool) -> Self { let (nrows, ncols) = a.data.shape();