Skip to content

Commit

Permalink
Add DNN_ASSERT_EQ
Browse files Browse the repository at this point in the history
  • Loading branch information
daquexian committed May 13, 2019
1 parent 3c7e7f8 commit 469bd79
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions common/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,22 @@ using css = const std::string;
#define STR(a) #a
#define XSTR(a) STR(a)

#define PNT_STR(var) << XSTR(var) << " = " << (var) << ", "
#define PNT_TO(stream, ...) stream FOR_EACH(PNT_STR, __VA_ARGS__);
#define PNT_STR(s) << s << " "
#define PNT_VAR(var) << XSTR(var) << " = " << (var) << ", "
#define PNT_TO(stream, ...) stream FOR_EACH(PNT_VAR, __VA_ARGS__);
#define PNT(...) PNT_TO(LOG(INFO), __VA_ARGS__)

#define DNN_ASSERT(condition, note) \
if (!(condition)) { \
std::stringstream ss; \
ss << std::string(XSTR(condition)) \
<< std::string(" is not satisfied on ") << std::to_string(__LINE__) \
<< " of " << __FILE__ << note; \
LOG(INFO) << ss.str(); \
throw std::runtime_error(ss.str()); \
#define DNN_ASSERT(condition, ...) \
if (!(condition)) { \
std::stringstream ss; \
ss << std::string(XSTR(condition)) \
<< std::string(" is not satisfied! ") \
FOR_EACH(PNT_STR, __VA_ARGS__); \
LOG(INFO) << ss.str(); \
throw std::runtime_error(ss.str()); \
}

#define DNN_ASSERT_EQ(actual, expected) \
DNN_ASSERT((actual) == (expected), XSTR(actual), "=", actual, ", the expected value is", XSTR(expected), "(which is", expected, ")" )

#endif /* DNNLIBRARY_HELPER_H */

0 comments on commit 469bd79

Please sign in to comment.