From 213fca90a240d750d8ff07d200e83fcd885f17ff Mon Sep 17 00:00:00 2001 From: conrad Date: Thu, 11 Mar 2021 16:04:46 +1000 Subject: [PATCH] print warnings for non-finite matrices --- include/armadillo_bits/op_norm_meat.hpp | 28 ++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/include/armadillo_bits/op_norm_meat.hpp b/include/armadillo_bits/op_norm_meat.hpp index e0d94e51..a8452958 100644 --- a/include/armadillo_bits/op_norm_meat.hpp +++ b/include/armadillo_bits/op_norm_meat.hpp @@ -882,8 +882,14 @@ op_norm::mat_norm_1(const Proxy& P) { arma_extra_debug_sigprint(); + typedef typename T1::pod_type T; + // TODO: this can be sped up with a dedicated implementation - return as_scalar( max( sum(abs(P.Q), 0), 1) ); + const T outval = as_scalar( max( sum(abs(P.Q), 0), 1) ); + + if(arma_isfinite(outval) == false) { arma_debug_warn("norm(): given matrix may have non-finite values"); } + + return outval; } @@ -895,12 +901,18 @@ op_norm::mat_norm_2(const Proxy& P) { arma_extra_debug_sigprint(); - typedef typename T1::pod_type T; + typedef typename T1::pod_type T; Col S; - svd(S, P.Q); + const bool status = svd(S, P.Q); - return (S.n_elem > 0) ? S[0] : T(0); + if(status == false) { arma_debug_warn("norm(): svd failed"); } + + const T outval = (S.n_elem > 0) ? S[0] : T(0); + + if(arma_isfinite(outval) == false) { arma_debug_warn("norm(): given matrix may have non-finite values"); } + + return outval; } @@ -912,8 +924,14 @@ op_norm::mat_norm_inf(const Proxy& P) { arma_extra_debug_sigprint(); + typedef typename T1::pod_type T; + // TODO: this can be sped up with a dedicated implementation - return as_scalar( max( sum(abs(P.Q), 1), 0) ); + const T outval = as_scalar( max( sum(abs(P.Q), 1), 0) ); + + if(arma_isfinite(outval) == false) { arma_debug_warn("norm(): given matrix may have non-finite values"); } + + return outval; }