include_optional_kernels.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_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.

namespace onnx_kernels
namespace kernel
class Optional : public onnx_light::onnx_kernels::kernel::KernelBase#
#include <include_optional_kernels.h>

Wraps a single tensor input into an optional-of-tensor value. The output’s element type, shape and bytes are an exact copy of input.

Public Functions

Tensor operator()(const Tensor &input) const#
void operator()(const Tensor &input, Tensor &output) const#
inline explicit KernelBase(const KernelContext &ctx)#

Public Static Functions

static inline constexpr bool CanRunInPlace() noexcept#

Output is a byte-for-byte copy of input, so storage may safely be shared with the input buffer.

class OptionalGetElement : public onnx_light::onnx_kernels::kernel::KernelBase#
#include <include_optional_kernels.h>

Reference implementation of the ONNX OptionalGetElement operator (since opset 15 in the ai.onnx domain). It extracts the element from an optional-type input and returns it. Because the project’s runtime :ref:Tensor type does not model optional values, the kernel treats the input as the “present” element and behaves as a passthrough:

  • the tensor overload returns a byte-for-byte copy of the input tensor (same data_type and shape);

  • the sequence overload returns a copy of the input sequence.

Since opset 18, OptionalGetElement also accepts non-optional tensor or sequence inputs as a no-op; the same passthrough behavior is correct in both cases. The kernel does not consume attributes.

Public Functions

Tensor operator()(const Tensor &input) const#
void operator()(const Tensor &input, Tensor &output) const#
Sequence operator()(const Sequence &input) const#
inline explicit KernelBase(const KernelContext &ctx)#

Public Static Functions

static inline constexpr bool CanRunInPlace() noexcept#

Output is a byte-for-byte copy of input, so storage may safely be shared with the input buffer when both are tensors.

class OptionalHasElement : public onnx_light::onnx_kernels::kernel::KernelBase#
#include <include_optional_kernels.h>

Reference implementation of the ONNX OptionalHasElement operator (since opset 15 in the ai.onnx domain). Returns a scalar boolean tensor: true when the input contains an element, false when the input is an empty optional or (since opset 18) when no input is provided.

Because the project’s runtime :ref:Tensor and :ref:Sequence types do not model “empty optional” values, this kernel treats any concrete tensor or sequence input as containing an element (returns true). The zero-input overload returns false and mirrors the opset-18 behavior where the input is omitted.

Public Functions

Tensor operator()(const Tensor &input) const#

Tensor input: always returns Tensor<bool, {}>{true} (the input is assumed to be the present element).

Tensor operator()(const Sequence &input) const#

Sequence input: always returns Tensor<bool, {}>{true}.

Tensor operator()() const#

No input (opset 18 only): returns Tensor<bool, {}>{false}.

inline explicit KernelBase(const KernelContext &ctx)#

Public Static Functions

static inline constexpr bool CanRunInPlace() noexcept#

Output is a fresh scalar bool tensor unrelated to any input storage; aliasing is not permitted.