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_EXPAND(x)#

Forces macro expansion of x before it is passed to another macro.

Useful when a variadic macro argument needs to be fully expanded prior to token-pasting or stringification by an outer macro.

Parameters:
  • x – Token or expression to expand.

ONNX_ASSERTM(cond, msg, ...)#

Asserts that cond is true; throws assert_error with a custom message if not.

Combines the source location information from ONNX_ASSERT with a printf-style msg so callers can provide additional context. The resulting exception message has the form:

file:line: func: Assertion `cond` failed: <formatted msg>

Parameters:
  • cond – Boolean expression that is expected to be true.

  • msg – printf-compatible format string describing the failure.

  • ... – Additional arguments matching the format specifiers in msg.

TENSOR_ASSERTM(cond, msg, ...)#

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.

  • msg – printf-compatible format string describing the failure.

  • ... – Additional arguments matching the format specifiers in msg.

namespace ONNX_LIGHT_NAMESPACE

Functions

std::string barf(const char *fmt, ...)#

Formats a printf-style message into a std::string.

Writes the formatted output into an internal fixed-size buffer and returns it as a std::string. The buffer is capped at 2047 characters; longer messages are silently truncated.

Parameters:
  • fmt – printf-compatible format string.

  • ... – Additional arguments matching the format specifiers in fmt.

Returns:

Formatted message as a std::string.

void throw_assert_error(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 – Formatted error message to embed in the exception.

void throw_tensor_error(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 – Formatted 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 formatted assertion message produced by barf().

Subclassed by ONNX_LIGHT_NAMESPACE::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_NAMESPACE::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.