From 099186cd41f8aba32ef8f70afd507ee344f3e75c Mon Sep 17 00:00:00 2001 From: minqiyang Date: Fri, 21 Dec 2018 20:01:59 +0800 Subject: [PATCH] Support one argument PADDLE_ENFORCE test=develop --- paddle/fluid/platform/enforce.h | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/paddle/fluid/platform/enforce.h b/paddle/fluid/platform/enforce.h index eee8173ba59..ec4d0bf9101 100644 --- a/paddle/fluid/platform/enforce.h +++ b/paddle/fluid/platform/enforce.h @@ -258,21 +258,33 @@ inline void throw_on_error(T e) { #define PADDLE_THROW(...) \ throw ::paddle::platform::EnforceNotMet(__FILE__, __LINE__, __VA_ARGS__) -#define PADDLE_JUDGE - -#define __PADDLE_UNARY_COMPARE(COND, ...) \ - do { \ - auto __cond = COND; \ - if (UNLIKELY(::paddle::platform::is_error(__cond))) { \ - ::paddle::platform::throw_on_error(__cond, ##__VA_ARGS__); \ - } \ +#define PADDLE_THROW_ERROR(COND, ...) \ + PADDLE_THROW_I(__VA_ARGS__, \ + ::paddle::platform::throw_on_error(COND, __VA_ARGS__), \ + ::paddle::platform::throw_on_error(COND, __VA_ARGS__), \ + ::paddle::platform::throw_on_error(COND, __VA_ARGS__), \ + ::paddle::platform::throw_on_error(COND, __VA_ARGS__), \ + ::paddle::platform::throw_on_error(COND, __VA_ARGS__), \ + ::paddle::platform::throw_on_error(COND, __VA_ARGS__), \ + ::paddle::platform::throw_on_error(COND, __VA_ARGS__), \ + ::paddle::platform::throw_on_error(COND, __VA_ARGS__), \ + ::paddle::platform::throw_on_error(COND)) + +#define PADDLE_THROW_I(_, _9, _8, _7, _6, _5, _4, _3, _2, X_, ...) X_; + +#define __PADDLE_UNARY_COMPARE(COND, ...) \ + do { \ + auto __cond = COND; \ + if (UNLIKELY(::paddle::platform::is_error(__cond))) { \ + PADDLE_THROW_ERROR(COND, __VA_ARGS__); \ + } \ } while (0) #ifndef REPLACE_ENFORCE_GLOG #define PADDLE_ENFORCE(COND, ...) \ do { \ try { \ - __PADDLE_UNARY_COMPARE(COND, ##__VA_ARGS__); \ + __PADDLE_UNARY_COMPARE(COND, __VA_ARGS__); \ } catch (...) { \ throw ::paddle::platform::EnforceNotMet(std::current_exception(), \ __FILE__, __LINE__); \ @@ -280,7 +292,7 @@ inline void throw_on_error(T e) { } while (0) #else -#define PADDLE_ENFORCE(COND, ...) __PADDLE_UNARY_COMPARE(COND, ##__VA_ARGS__); +#define PADDLE_ENFORCE(COND, ...) __PADDLE_UNARY_COMPARE(COND, __VA_ARGS__); #endif // REPLACE_ENFORCE_GLOG #define PADDLE_THROW_EOF() \ -- GitLab