diff --git a/include/armadillo_bits/glue_solve_meat.hpp b/include/armadillo_bits/glue_solve_meat.hpp index 8f8d348b..d22a609a 100644 --- a/include/armadillo_bits/glue_solve_meat.hpp +++ b/include/armadillo_bits/glue_solve_meat.hpp @@ -285,27 +285,6 @@ glue_solve_gen_full::apply(Mat& out, const Base& A_expr, const Base::epsilon()) || arma_isnan(rcond) ) ) - { - status = false; - } - - - if( (status == false) && (no_approx == false) ) - { - arma_extra_debug_print("glue_solve_gen_full::apply(): solving rank deficient system"); - - arma_debug_warn_level(2, "solve(): system is singular; rcond: ", rcond, "; attempting approx solution"); - - // TODO: conditionally recreate A: have a separate state flag which indicates whether A was previously overwritten - - A = A_expr.get_ref(); // as A may have been overwritten - - status = auxlib::solve_approx_svd(out, A, B_expr.get_ref()); // A is overwritten - } } else { @@ -323,25 +302,28 @@ glue_solve_gen_full::apply(Mat& out, const Base& A_expr, const Base::epsilon()) || arma_isnan(rcond) ) ) - { - status = false; - } - - if( (status == false) && (no_approx == false) ) - { - arma_extra_debug_print("glue_solve_gen_full::apply(): solving rank deficient system"); - - arma_debug_warn_level(2, "solve(): system is singular; rcond: ", rcond, "; attempting approx solution"); - - A = A_expr.get_ref(); // as A was overwritten - - status = auxlib::solve_approx_svd(out, A, B_expr.get_ref()); // A is overwritten - } } + if( (allow_ugly == false) && (status == true) && (fast == false) && ( (rcond < std::numeric_limits::epsilon()) || arma_isnan(rcond) ) ) + { + status = false; + } + + + if( (status == false) && (no_approx == false) ) + { + arma_extra_debug_print("glue_solve_gen_full::apply(): solving rank deficient system"); + + arma_debug_warn_level(2, "solve(): system is singular; rcond: ", rcond, "; attempting approx solution"); + + // TODO: conditionally recreate A: have a separate state flag which indicates whether A was previously overwritten + + A = A_expr.get_ref(); // as A may have been overwritten + + status = auxlib::solve_approx_svd(out, A, B_expr.get_ref()); // A is overwritten + } + return status; }