tensor_compare.h#
-
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.
Maps the upstream compatibility macro to onnx-light’s explicit proto ABI annotation. This keeps declarations from vendored ONNX headers visible when
lib_onnx_protouses hidden visibility by default.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.-
namespace core
-
namespace runtime
Functions
-
TensorComparison CompareTensors(const Tensor &actual, const Tensor &expected, double rtol = 1e-5, double atol = 1e-8, bool equal_nan = false)#
Compares two tensors element-wise within an absolute and relative tolerance, mirroring
numpy.allclose.The comparison first requires
actualandexpectedto share the samedata_typeandshape.STRINGtensors are then compared for exact equality of their string values. Numeric tensors are compared element-wise: two finite valuesaandbare considered close when|a - b| <= atol + rtol * |b|.NaNand infinity must occur at the same positions in both tensors; aNaN(resp. infinity) in one tensor with a different value at the same position in the other is reported as a mismatch. Infinities must additionally match in sign.NaNvalues compare unequal unlessequal_nanis true, in which case twoNaNvalues at the same position are treated as equal.The returned :cpp:class:
TensorComparisonalso records the maximum absolute and relative errors over the finite element pairs together with their flat indices (see the struct documentation).Half-precision (
FLOAT16/BFLOAT16) elements are decoded tofloatbefore comparison. Element types that cannot be represented asdoublehere (theFLOAT8*variants and the 4-bit / 2-bit packed types) fall back to an exact byte-for-byte comparison.- Parameters:
actual – The computed tensor.
expected – The reference tensor.
rtol – Relative tolerance (default
1e-5).atol – Absolute tolerance (default
1e-8).equal_nan – When true,
NaNvalues in matching positions compare equal (defaultfalse).
- Returns:
A :cpp:class:
TensorComparisondescribing the outcome.
-
struct TensorComparison#
- #include <tensor_compare.h>
Outcome of :cpp:func:
CompareTensors.closeis true when the two tensors match within the requested tolerance. When it is false,messageholds a human-readable description of the first mismatch (differing data type, shape, string value, mismatchedNaN/infinity positions, or a numeric element outside tolerance).The error statistics are computed over the finite element pairs of numeric tensors (they stay at their defaults for
STRINGtensors and for the byte-compared types that cannot be decoded todouble).max_abs_errorismax |actual - expected|andmax_rel_errorismax |actual - expected| / |expected|(an element withexpected == 0andactual != 0contributes an infinite relative error).max_abs_error_indexandmax_rel_error_indexare the flat element indices where those maxima occur (the first occurrence wins on ties), or-1when no finite pair was compared.Public Members
-
bool close = false#
Whether the tensors match within tolerance.
-
double max_abs_error = 0.0#
Largest absolute error
|actual - expected|over finite pairs.
-
int64_t max_abs_error_index = -1#
Flat element index of
max_abs_error(-1if none computed).
-
double max_rel_error = 0.0#
Largest relative error
|actual - expected| / |expected|over finite pairs.
-
int64_t max_rel_error_index = -1#
Flat element index of
max_rel_error(-1if none computed).
-
bool close = false#
-
TensorComparison CompareTensors(const Tensor &actual, const Tensor &expected, double rtol = 1e-5, double atol = 1e-8, bool equal_nan = false)#
-
namespace runtime
-
namespace core