File indexing completed on 2025-10-31 09:07:09
0001 
0002 
0003 
0004 
0005 
0006 
0007 
0008 
0009 
0010 #pragma once
0011 
0012 #include <stdexcept>
0013 #include <string>
0014 
0015 namespace ONNX_NAMESPACE {
0016 
0017 struct assert_error : public std::runtime_error {
0018  public:
0019   explicit assert_error(const std::string& msg) : runtime_error(msg) {}
0020 };
0021 
0022 struct tensor_error : public assert_error {
0023  public:
0024   explicit tensor_error(const std::string& msg) : assert_error(msg) {}
0025 };
0026 
0027 std::string barf(const char* fmt, ...);
0028 
0029 [[noreturn]] void throw_assert_error(std::string&);
0030 
0031 [[noreturn]] void throw_tensor_error(std::string&);
0032 
0033 } 
0034 
0035 #if defined(__GNUC__) || defined(__ICL) || defined(__clang__)
0036 #define _ONNX_EXPECT(x, y) (__builtin_expect((x), (y)))
0037 #else
0038 #define _ONNX_EXPECT(x, y) (x)
0039 #endif
0040 
0041 #define ONNX_ASSERT(cond)                                                                                 \
0042   if (_ONNX_EXPECT(!(cond), 0)) {                                                                         \
0043     std::string error_msg =                                                                               \
0044         ::ONNX_NAMESPACE::barf("%s:%u: %s: Assertion `%s` failed.", __FILE__, __LINE__, __func__, #cond); \
0045     throw_assert_error(error_msg);                                                                        \
0046   }
0047 
0048 
0049 
0050 #define ONNX_EXPAND(x) x
0051 
0052 
0053 #define _ONNX_ASSERTM(cond, msg, ...)                                                                \
0054   if (_ONNX_EXPECT(!(cond), 0)) {                                                                    \
0055     std::string error_msg = ::ONNX_NAMESPACE::barf(                                                  \
0056         "%s:%u: %s: Assertion `%s` failed: " msg, __FILE__, __LINE__, __func__, #cond, __VA_ARGS__); \
0057     throw_assert_error(error_msg);                                                                   \
0058   }
0059 
0060 
0061 
0062 
0063 #define ONNX_ASSERTM(...) ONNX_EXPAND(_ONNX_ASSERTM(__VA_ARGS__, " "))
0064 
0065 #define _TENSOR_ASSERTM(cond, msg, ...)                                                              \
0066   if (_ONNX_EXPECT(!(cond), 0)) {                                                                    \
0067     std::string error_msg = ::ONNX_NAMESPACE::barf(                                                  \
0068         "%s:%u: %s: Assertion `%s` failed: " msg, __FILE__, __LINE__, __func__, #cond, __VA_ARGS__); \
0069     throw_tensor_error(error_msg);                                                                   \
0070   }
0071 
0072 #define TENSOR_ASSERTM(...) ONNX_EXPAND(_TENSOR_ASSERTM(__VA_ARGS__, " "))