diff --git a/include/armadillo_bits/op_norm_meat.hpp b/include/armadillo_bits/op_norm_meat.hpp index 10e255d6..05157766 100644 --- a/include/armadillo_bits/op_norm_meat.hpp +++ b/include/armadillo_bits/op_norm_meat.hpp @@ -29,19 +29,17 @@ op_norm::vec_norm_1(const Proxy& P, const typename arma_not_cx::stored_type>::value) || (is_subview_col::stored_type>::value) || (arma_config::openmp && Proxy::use_mp); if(use_direct_mem) { const quasi_unwrap::stored_type> tmp(P.Q); - const T out_val = op_norm::vec_norm_1_direct_std(tmp.M); - - return (out_val <= T(0)) ? T(0) : out_val; + return op_norm::vec_norm_1_direct_std(tmp.M); } + typedef typename T1::pod_type T; + T acc = T(0); if(Proxy::use_at == false) @@ -176,7 +174,7 @@ op_norm::vec_norm_1(const Proxy& P, const typename arma_cx_only::stored_type> R(P.Q); @@ -226,28 +224,32 @@ op_norm::vec_norm_1_direct_std(const Mat& X) const uword N = X.n_elem; const eT* A = X.memptr(); + eT out_val = eT(0); + #if defined(ARMA_USE_ATLAS) { arma_extra_debug_print("atlas::cblas_asum()"); - return atlas::cblas_asum(N,A); + out_val = atlas::cblas_asum(N,A); } #elif defined(ARMA_USE_BLAS) { if(has_blas_float_bug::value) { - return op_norm::vec_norm_1_direct_mem(N,A); + out_val = op_norm::vec_norm_1_direct_mem(N,A); } else { arma_extra_debug_print("blas::asum()"); - return blas::asum(N,A); + out_val = blas::asum(N,A); } } #else { - return op_norm::vec_norm_1_direct_mem(N,A); + out_val = op_norm::vec_norm_1_direct_mem(N,A); } #endif + + return (out_val <= eT(0)) ? eT(0) : out_val; } @@ -312,19 +314,17 @@ op_norm::vec_norm_2(const Proxy& P, const typename arma_not_cx::stored_type>::value) || (is_subview_col::stored_type>::value) || (arma_config::openmp && Proxy::use_mp); if(use_direct_mem) { const quasi_unwrap::stored_type> tmp(P.Q); - const T out_val = op_norm::vec_norm_2_direct_std(tmp.M); - - return (out_val <= T(0)) ? T(0) : out_val; + return op_norm::vec_norm_2_direct_std(tmp.M); } + typedef typename T1::pod_type T; + T acc = T(0); if(Proxy::use_at == false) @@ -403,7 +403,7 @@ op_norm::vec_norm_2(const Proxy& P, const typename arma_not_cx::stored_type> tmp(P.Q); @@ -482,7 +482,7 @@ op_norm::vec_norm_2(const Proxy& P, const typename arma_cx_only::stored_type> R(P.Q); @@ -525,38 +525,38 @@ op_norm::vec_norm_2_direct_std(const Mat& X) const uword N = X.n_elem; const eT* A = X.memptr(); - eT result = eT(0); + eT out_val = eT(0); #if defined(ARMA_USE_ATLAS) { arma_extra_debug_print("atlas::cblas_nrm2()"); - result = atlas::cblas_nrm2(N,A); + out_val = atlas::cblas_nrm2(N,A); } #elif defined(ARMA_USE_BLAS) { if(has_blas_float_bug::value) { - result = op_norm::vec_norm_2_direct_mem(N,A); + out_val = op_norm::vec_norm_2_direct_mem(N,A); } else { arma_extra_debug_print("blas::nrm2()"); - result = blas::nrm2(N,A); + out_val = blas::nrm2(N,A); } } #else { - result = op_norm::vec_norm_2_direct_mem(N,A); + out_val = op_norm::vec_norm_2_direct_mem(N,A); } #endif - if( (result != eT(0)) && arma_isfinite(result) ) + if( (out_val != eT(0)) && arma_isfinite(out_val) ) { - return result; + return (out_val < eT(0)) ? eT(0) : out_val; } else { - arma_extra_debug_print("op_norm::vec_norm_2_direct_std(): detected possible underflow or overflow"); + arma_extra_debug_print("detected possible underflow or overflow"); return op_norm::vec_norm_2_direct_robust(X); }