1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
#ifndef __DEBUG_H__
#define __DEBUG_H__
#include <assert.h>
#include <iostream>
#include "gsl/gsl_matrix.h"
void gemma_gsl_error_handler (const char * reason,
const char * file,
int line, int gsl_errno);
void debug_set_debug_mode(bool setting);
void debug_set_no_check_mode(bool setting);
void debug_set_strict_mode(bool setting);
void debug_set_quiet_mode(bool setting);
void debug_set_issue(uint issue);
void debug_set_legacy_mode(bool setting);
bool is_debug_mode();
bool is_no_check_mode();
bool is_check_mode();
bool is_strict_mode();
bool is_quiet_mode();
bool is_issue(uint issue);
bool is_legacy_mode();
gsl_matrix *gsl_matrix_safe_alloc(size_t rows,size_t cols);
gsl_vector *gsl_vector_safe_alloc(size_t n);
char *do_strtok_safe(char *tokenize, const char *delimiters, const char *__pretty_function, const char *__file, int __line);
#define strtok_safe(string,delimiters) do_strtok_safe(string,delimiters,__PRETTY_FUNCTION__,__FILE__,__LINE__)
// Validation routines
void do_validate_K(const gsl_matrix *K, const char *__file, int __line);
#define ROUND(f) round(f * 10000.)/10000
#define validate_K(K) do_validate_K(K,__FILE__,__LINE__)
#define warning_at_msg(__file,__line,msg) cerr << "**** WARNING: " << msg << " in " << __file << " at line " << __line << endl;
inline void warnfail_at_msg(bool strict, const char *__file, int __line, const char *msg) {
if (strict)
std::cerr << "**** STRICT FAIL: ";
else
std::cerr << "**** WARNING: ";
std::cerr << msg << " in " << __file << " at line " << __line << std::endl;
if (strict)
exit(1);
}
inline void fail_at_msg(const char *__file, int __line, std::string msg) {
std::cerr << msg << " in " << __file << " at line " << __line << std::endl;
exit(1);
}
# ifndef __ASSERT_VOID_CAST
# define __ASSERT_VOID_CAST (void)
# endif
inline void fail_msg(const char *msg) {
std::cerr << "**** FAILED: " << msg << std::endl;
exit(5);
}
inline void fail_msg(std::string msg) {
std::cerr << "**** FAILED: " << msg << std::endl;
exit(5);
}
#if defined NDEBUG
#define warning_msg(msg) cerr << "**** WARNING: " << msg << endl;
#define debug_msg(msg)
#define assert_issue(is_issue, expr)
#else // DEBUG
#define warning_msg(msg) cerr << "**** WARNING: " << msg << " in " << __FILE__ << " at line " << __LINE__ << " in " << __FUNCTION__ << endl;
#define debug_msg(msg) (is_debug_mode() && cerr << "**** DEBUG: " << msg << " in " << __FILE__ << " at line " << __LINE__ << " in " << __FUNCTION__ << endl);
#define assert_issue(is_issue, expr) \
((is_issue) ? enforce_msg(expr,"FAIL: ISSUE assert") : __ASSERT_VOID_CAST(0))
#endif
// enforce works like assert but also when NDEBUG is set (i.e., it
// always works). enforce_msg prints message instead of expr
/* This prints an "Assertion failed" message and aborts. */
inline void __enforce_fail(const char *__assertion, const char *__file,
unsigned int __line,
const char *__function)
{
std::cout << "ERROR: Enforce failed for " << __assertion << " in " << __file << " at line " << __line << " in " << __PRETTY_FUNCTION__ << std::endl;
exit(1);
}
#define __ASSERT_FUNCTION __PRETTY_FUNCTION__
#define enforce(expr) \
((expr) \
? __ASSERT_VOID_CAST(0) \
: __enforce_fail(__STRING(expr), __FILE__, __LINE__, __ASSERT_FUNCTION))
#define enforce_msg(expr, msg) \
((expr) ? __ASSERT_VOID_CAST(0) \
: __enforce_fail(msg, __FILE__, __LINE__, __ASSERT_FUNCTION))
#define enforce_str(expr, msg) \
((expr) \
? __ASSERT_VOID_CAST(0) \
: __enforce_fail((msg).c_str(), __FILE__, __LINE__, __ASSERT_FUNCTION))
// Helpers to create a unique varname per MACRO
#define COMBINE1(X, Y) X##Y
#define COMBINE(X, Y) COMBINE1(X, Y)
#define enforce_gsl(expr) \
auto COMBINE(res, __LINE__) = (expr); \
(COMBINE(res, __LINE__) == 0 \
? __ASSERT_VOID_CAST(0) \
: __enforce_fail(gsl_strerror(COMBINE(res, __LINE__)), __FILE__, \
__LINE__, __ASSERT_FUNCTION))
#endif
|