Skip to content

Commit

Permalink
Show warning on some unused matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
pjotrp committed Sep 6, 2018
1 parent 8b0a36e commit 2ac6385
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
18 changes: 13 additions & 5 deletions src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ int gsl_matrix_safe_memcpy (gsl_matrix *dest, const gsl_matrix *src) {
return gsl_matrix_memcpy(dest,src);
}

void do_gsl_matrix_safe_free (gsl_matrix *m, const char *__pretty_function, const char *__file, int __line) {
void do_gsl_matrix_safe_free (gsl_matrix *m, const char *__pretty_function, const char *__file, int __line, bool warn_only) {
enforce(m);
if (is_strict_mode() && is_check_mode() && is_debug_mode()) {
bool has_NaN = has_nan(m);
Expand All @@ -228,10 +228,18 @@ void do_gsl_matrix_safe_free (gsl_matrix *m, const char *__pretty_function, cons
msg += "x";
msg += std::to_string(m->size2);
msg += ")";
if (has_Inf)
warnfail_at_msg(is_strict_mode(),__pretty_function,__file,__line,(msg+" contains Infinite on free!").c_str());
if (has_NaN)
warnfail_at_msg(is_strict_mode(),__pretty_function,__file,__line,(msg+" contains NaN on free!").c_str());
if (warn_only) {
if (has_Inf)
warning_at_msg(__file,__line,(msg+" contains Infinite on free!").c_str());
if (has_NaN)
warning_at_msg(__file,__line,(msg+" contains NaN on free!").c_str());
}
else {
if (has_Inf)
warnfail_at_msg(is_strict_mode(),__pretty_function,__file,__line,(msg+" contains Infinite on free!").c_str());
if (has_NaN)
warnfail_at_msg(is_strict_mode(),__pretty_function,__file,__line,(msg+" contains NaN on free!").c_str());
}
}
}
return gsl_matrix_free(m);
Expand Down
7 changes: 5 additions & 2 deletions src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ void write(const gsl_matrix *m, const char *msg = "");
gsl_matrix *gsl_matrix_safe_alloc(size_t rows,size_t cols);
int gsl_matrix_safe_memcpy (gsl_matrix *dest, const gsl_matrix *src);
void gsl_matrix_safe_free (gsl_matrix *v);
void do_gsl_matrix_safe_free (gsl_matrix *m, const char *__pretty_function, const char *__file, int __line);
void gsl_matrix_warn_free (gsl_matrix *v);
void do_gsl_matrix_safe_free (gsl_matrix *m, const char *__pretty_function, const char *__file, int __line, bool warn_only);

double do_gsl_matrix_safe_get (const gsl_matrix * m, const size_t i, const size_t j, const char *__pretty_function, const char *__file, int __line);
#define gsl_matrix_safe_get(m,i,j) do_gsl_matrix_safe_get(m, i, j,__SHOW_FUNC,__FILE__,__LINE__);
Expand Down Expand Up @@ -186,7 +187,9 @@ inline void __enforce_fail(const char *__assertion, const char *__file,
((std::string(__STRING(fn)) + " " + fn + ": " + msg).c_str()));

#define gsl_matrix_safe_free(m) \
do_gsl_matrix_safe_free(m,__SHOW_FUNC,__FILE__,__LINE__);
do_gsl_matrix_safe_free(m,__SHOW_FUNC,__FILE__,__LINE__,false);
#define gsl_matrix_warn_free(m) \
do_gsl_matrix_safe_free(m,__SHOW_FUNC,__FILE__,__LINE__,true);
#define gsl_vector_safe_free(v) \
do_gsl_vector_safe_free(v,__SHOW_FUNC,__FILE__,__LINE__);

Expand Down
8 changes: 4 additions & 4 deletions src/gemma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2837,14 +2837,14 @@ void GEMMA::BatchRun(PARAM &cPar) {
// release all matrices and vectors
gsl_matrix_safe_free(Y);
gsl_matrix_safe_free(W);
gsl_matrix_safe_free(B);
gsl_matrix_safe_free(se_B);
gsl_matrix_safe_free(G);
gsl_matrix_warn_free(B); // sometimes unused
gsl_matrix_warn_free(se_B);
gsl_matrix_warn_free(G);
gsl_matrix_safe_free(U);
gsl_matrix_safe_free(UtW);
gsl_matrix_safe_free(UtY);
gsl_vector_safe_free(eval);
gsl_vector_safe_free(env);
gsl_vector_free(env); // sometimes unused
}

// BSLMM
Expand Down

0 comments on commit 2ac6385

Please sign in to comment.