diff --git a/include/armadillo_bits/op_rank_meat.hpp b/include/armadillo_bits/op_rank_meat.hpp index bf0de236..2fb31c61 100644 --- a/include/armadillo_bits/op_rank_meat.hpp +++ b/include/armadillo_bits/op_rank_meat.hpp @@ -87,6 +87,8 @@ op_rank::apply_diag(uword& out, Mat& A, typename get_pod_type::result to typedef typename get_pod_type::result T; + out = uword(0); + const uword N = (std::min)(A.n_rows, A.n_cols); podarray diag_abs_vals(N); @@ -98,7 +100,7 @@ op_rank::apply_diag(uword& out, Mat& A, typename get_pod_type::result to const eT Aii = A.at(i,i); const T abs_Aii = std::abs(Aii); - if(arma_isnan(Aii)) { out = uword(0); return false; } + if(arma_isnan(Aii)) { return false; } diag_abs_vals[i] = abs_Aii; @@ -108,7 +110,7 @@ op_rank::apply_diag(uword& out, Mat& A, typename get_pod_type::result to // set tolerance to default if it hasn't been specified if(tol == T(0)) { tol = (std::max)(A.n_rows, A.n_cols) * max_abs_Aii * std::numeric_limits::epsilon(); } - if(arma_isnan(tol)) { out = uword(0); return false; } + if(arma_isnan(tol)) { return false; } uword count = 0; @@ -130,18 +132,20 @@ op_rank::apply_sym(uword& out, Mat& A, typename get_pod_type::result tol typedef typename get_pod_type::result T; - if(A.is_square() == false) { out = uword(0); return false; } + out = uword(0); + + if(A.is_square() == false) { return false; } Col v; const bool status = auxlib::eig_sym(v, A); - if(status == false) { out = uword(0); return false; } + if(status == false) { return false; } const uword v_n_elem = v.n_elem; T* v_mem = v.memptr(); - if(v_n_elem == 0) { out = uword(0); return true; } + if(v_n_elem == 0) { return true; } T max_abs_v = T(0); @@ -150,7 +154,7 @@ op_rank::apply_sym(uword& out, Mat& A, typename get_pod_type::result tol // set tolerance to default if it hasn't been specified if(tol == T(0)) { tol = (std::max)(A.n_rows, A.n_cols) * max_abs_v * std::numeric_limits::epsilon(); } - if(arma_isnan(tol)) { out = uword(0); return false; } + if(arma_isnan(tol)) { return false; } uword count = 0; @@ -172,21 +176,23 @@ op_rank::apply_gen(uword& out, Mat& A, typename get_pod_type::result tol typedef typename get_pod_type::result T; + out = uword(0); + Col s; const bool status = auxlib::svd_dc(s, A); - if(status == false) { out = uword(0); return false; } + if(status == false) { return false; } const uword s_n_elem = s.n_elem; const T* s_mem = s.memptr(); - if(s_n_elem == 0) { out = uword(0); return true; } + if(s_n_elem == 0) { return true; } // set tolerance to default if it hasn't been specified if(tol == T(0)) { tol = (std::max)(A.n_rows, A.n_cols) * s_mem[0] * std::numeric_limits::epsilon(); } - if(arma_isnan(tol)) { out = uword(0); return false; } + if(arma_isnan(tol)) { return false; } uword count = 0;