assertions.h#
Defines
-
_ONNX_EXPECT(x, y)#
Provides a branch-prediction hint to the compiler.
On GCC, Clang, and ICC expands to
__builtin_expect((x),(y)) so the compiler can optimize the fast path. On all other compilers the macro is a no-op that simply evaluates tox.- Parameters:
x – The expression whose value is being predicted.
y – The expected value of
x(0 for unlikely, 1 for likely).
-
ONNX_ASSERT(cond)#
Asserts that
condis true; throws assert_error if it is not.The failure message includes the source file, line number, enclosing function name, and the stringified condition. The branch is annotated as unlikely via _ONNX_EXPECT so the fast path incurs no extra overhead.
- Parameters:
cond – Boolean expression that is expected to be true.
-
ONNX_ASSERTM(cond, ...)#
Asserts that
condis true; throws assert_error with a custom message if not.The message arguments are concatenated via MakeString (using std::stringstream), so std::string, std::string_view, and numeric types are all accepted directly without format specifiers or .c_str(). The resulting exception message has the form:
file:line: func: Assertion `cond` failed: <message>
- Parameters:
cond – Boolean expression that is expected to be true.
... – Arguments concatenated by MakeString to describe the failure.
-
TENSOR_ASSERTM(cond, ...)#
Asserts that
condis true; throws tensor_error with a custom message if not.Identical in structure to ONNX_ASSERTM but throws tensor_error instead of assert_error, allowing callers to catch tensor-specific failures separately.
- Parameters:
cond – Boolean expression that is expected to be true.
... – Arguments concatenated by MakeString to describe the failure.
-
namespace onnx_light
Alias that makes onnx-light headers compatible with code that references
ONNX_LIGHT_NAMESPACE(the macro used in the standard onnx package).Set to
ONNX_LIGHT_NAMESPACEso both names resolve to the same namespace.Symbol-visibility attribute for the public onnx-light C++ API.
Defined as empty because onnx-light does not require explicit
__declspec(dllexport)or__attribute__((visibility("default")))annotations — visibility is controlled at the shared-library level. The macro is provided so that vendored ONNX headers that decorate their declarations withONNX_APIcompile without modification.Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal
onnxnamespace — rather than theONNX_NAMESPACEmacro — resolves to the onnx-light namespace. The standard onnx package lives innamespace onnx; onnx-light usesonnx_light(via ONNX_LIGHT_NAMESPACE), so this alias keeps onnx-light a true drop-in. It is only introduced when the onnx-light namespace differs fromonnx.Functions
-
void throw_assert_error(const std::string &msg)#
Throws an assert_error with the given message.
When exceptions are disabled (ONNX_NO_EXCEPTIONS), prints the message to
std::cerrand callsstd::abort()instead.- Parameters:
msg – Error message to embed in the exception.
-
void throw_tensor_error(const std::string &msg)#
Throws a tensor_error with the given message.
When exceptions are disabled (ONNX_NO_EXCEPTIONS), prints the message to
std::cerrand callsstd::abort()instead.- Parameters:
msg – Error message to embed in the exception.
-
struct assert_error : public std::runtime_error#
- #include <assertions.h>
Exception type thrown when an ONNX assertion fails.
Derives from
std::runtime_errorand carries the assertion message.Subclassed by onnx_light::tensor_error
Public Functions
-
inline explicit assert_error(const std::string &msg)#
Constructs an assert_error with the given message.
- Parameters:
msg – Human-readable description of the failed assertion.
-
inline explicit assert_error(const std::string &msg)#
-
struct tensor_error : public onnx_light::assert_error#
- #include <assertions.h>
Exception type thrown when a tensor-specific assertion fails.
Specialization of assert_error used by TENSOR_ASSERTM to distinguish tensor-related failures from general assertion failures.
Public Functions
-
inline explicit tensor_error(const std::string &msg)#
Constructs a tensor_error with the given message.
- Parameters:
msg – Human-readable description of the failed tensor assertion.
-
inline explicit tensor_error(const std::string &msg)#
-
void throw_assert_error(const std::string &msg)#