diff --git a/include/armadillo_bits/glue_solve_meat.hpp b/include/armadillo_bits/glue_solve_meat.hpp index 95f2f01a..51b68df7 100644 --- a/include/armadillo_bits/glue_solve_meat.hpp +++ b/include/armadillo_bits/glue_solve_meat.hpp @@ -130,6 +130,8 @@ glue_solve_gen_full::apply(Mat& out, const Base& A_expr, const Base& out, const Base& A_expr, const Base& out, const Base& A_expr, const Base& actual_out, const Base& A_expr, co arma_debug_check( (A.is_square() == false), "solve(): matrix marked as triangular must be square sized" ); + if(arma_config::check_nonfinite) + { + bool has_nonfinite = false; + + if(triu) { has_nonfinite = trimat_helper::has_nonfinite_triu(A); } + if(tril) { has_nonfinite = trimat_helper::has_nonfinite_tril(A); } + + if(has_nonfinite) { arma_debug_warn_level(3, "solve(): given matrix has non-finite elements"); return false; } + } + const uword layout = (triu) ? uword(0) : uword(1); const bool is_alias = U.is_alias(actual_out); @@ -518,6 +544,16 @@ glue_solve_tri_full::apply(Mat& actual_out, const Base& A_expr, const arma_debug_check( (A.is_square() == false), "solve(): matrix marked as triangular must be square sized" ); + if(arma_config::check_nonfinite) + { + bool has_nonfinite = false; + + if(triu) { has_nonfinite = trimat_helper::has_nonfinite_triu(A); } + if(tril) { has_nonfinite = trimat_helper::has_nonfinite_tril(A); } + + if(has_nonfinite) { arma_debug_warn_level(3, "solve(): given matrix has non-finite elements"); return false; } + } + const uword layout = (triu) ? uword(0) : uword(1); const bool is_alias = U.is_alias(actual_out); diff --git a/include/armadillo_bits/trimat_helper.hpp b/include/armadillo_bits/trimat_helper.hpp index d4d60604..9242083d 100644 --- a/include/armadillo_bits/trimat_helper.hpp +++ b/include/armadillo_bits/trimat_helper.hpp @@ -107,6 +107,58 @@ is_tril(const Mat& A) +template +inline +bool +has_nonfinite_tril(const Mat& A) + { + arma_extra_debug_sigprint(); + + // NOTE: assuming that A has a square size + + const eT* colptr = A.memptr(); + const uword N = A.n_rows; + + for(uword i=0; i +inline +bool +has_nonfinite_triu(const Mat& A) + { + arma_extra_debug_sigprint(); + + // NOTE: assuming that A has a square size + + const eT* colptr = A.memptr(); + const uword N = A.n_rows; + + for(uword i=0; i