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 to x.

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 cond is 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 cond is 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 cond is 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_NAMESPACE so 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 with ONNX_API compile without modification.

Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal onnx namespace — rather than the ONNX_NAMESPACE macro — resolves to the onnx-light namespace. The standard onnx package lives in namespace onnx; onnx-light uses onnx_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 from onnx.

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::cerr and calls std::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::cerr and calls std::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_error and 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.

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.