diff options
author | Pjotr Prins | 2018-09-06 10:25:22 +0000 |
---|---|---|
committer | Pjotr Prins | 2018-09-06 10:25:22 +0000 |
commit | 6dd15bfabc5c655d18ea19c0d69b76ecc34630e2 (patch) | |
tree | 336c37cac9b105bec550405a11853277631c2810 /src/mathfunc.cpp | |
parent | 8010061e8af476d66a0ca6fb6d509b36acdb9b9a (diff) | |
download | pangemma-6dd15bfabc5c655d18ea19c0d69b76ecc34630e2.tar.gz |
More debugging info and raise SIGINT instead of exit
Diffstat (limited to 'src/mathfunc.cpp')
-rw-r--r-- | src/mathfunc.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/mathfunc.cpp b/src/mathfunc.cpp index 4708ffa..fdd6a58 100644 --- a/src/mathfunc.cpp +++ b/src/mathfunc.cpp @@ -70,27 +70,27 @@ bool has_nan(const vector<double> v) { bool has_nan(const gsl_vector *v) { for (size_t i = 0; i < v->size; ++i) - if (gsl_isnan(gsl_vector_get(v,i))) return true; + if (is_nan(gsl_vector_get(v,i))) return true; return false; } bool has_inf(const gsl_vector *v) { for (size_t i = 0; i < v->size; ++i) { auto value = gsl_vector_get(v,i); - if (gsl_isinf(value) != 0) return true; + if (is_inf(value) != 0) return true; } return false; } bool has_nan(const gsl_matrix *m) { for (size_t i = 0; i < m->size1; ++i) for (size_t j = 0; j < m->size2; ++j) - if (gsl_isnan(gsl_matrix_get(m,i,j))) return true; + if (is_nan(gsl_matrix_get(m,i,j))) return true; return false; } bool has_inf(const gsl_matrix *m) { for (size_t i = 0; i < m->size1; ++i) for (size_t j = 0; j < m->size2; ++j) { auto value = gsl_matrix_get(m,i,j); - if (gsl_isinf(value) != 0) return true; + if (is_inf(value) != 0) return true; } return false; } @@ -103,6 +103,12 @@ bool is_float(const std::string & s){ return std::regex_match(s, std::regex("^[+-]?([0-9]*[.])?[0-9]+$")); } +double safe_log(const double d) { + if (!is_legacy_mode()) + enforce_msg(d > 0.0, (std::string("Trying to take the log of ") + std::to_string(d)).c_str()); + return log(d); +} + // calculate variance of a vector double VectorVar(const gsl_vector *v) { double d, m = 0.0, m2 = 0.0; |