From b3ef66fd14b17ffb54f8cb560a5866c81a6aff4a Mon Sep 17 00:00:00 2001 From: Fredrik Jansson Date: Thu, 2 Apr 2020 10:55:00 +0200 Subject: [PATCH] Fixed bug in onenorm_matrix_power_norm --- src/linalg/exp.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/linalg/exp.rs b/src/linalg/exp.rs index 5b76dcaf..7c087159 100644 --- a/src/linalg/exp.rs +++ b/src/linalg/exp.rs @@ -320,31 +320,32 @@ fn factorial(n: u128) -> u128 { n * factorial(n - 1) } -fn onenorm_matrix_power_nnm(a: &MatrixN, p: u64) -> N +/// Compute the 1-norm of a non-negative integer power of a non-negative matrix. +fn onenorm_matrix_power_nonm(a: &MatrixN, p: u64) -> N where N: RealField, R: DimName, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator + Allocator, { - let mut v = MatrixN::::repeat(N::from_f64(1.0).unwrap()); + let mut v = crate::VectorN::::repeat(N::from_f64(1.0).unwrap()); let m = a.transpose(); for _ in 0..p { v = &m * v; } - one_norm(&v) + v.max() } fn ell(a: &MatrixN, m: u64) -> u64 where N: RealField, R: DimName, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator + Allocator, { // 2m choose m = (2m)!/(m! * (2m-m)!) - let a_abs_onenorm = onenorm_matrix_power_nnm(&a.abs(), 2 * m + 1); + let a_abs_onenorm = onenorm_matrix_power_nonm(&a.abs(), 2 * m + 1); if a_abs_onenorm == N::zero() { return 0; @@ -396,9 +397,11 @@ where max } -impl + DimName> MatrixN +impl MatrixN where - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, + R: DimMin + DimName, + DefaultAllocator: + Allocator + Allocator<(usize, usize), DimMinimum> + Allocator, { /// Computes exp of this matrix pub fn exp(&self) -> Self {