include_sequence_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 ConcatFromSequence : public onnx_light::onnx_kernels::kernel::KernelBase#
#include <include_sequence_kernels.h>

Concatenates the tensor elements of an input sequence along axis (when new_axis == 0, the default) or stacks them along a new axis at position axis (when new_axis == 1), mirroring the ONNX ConcatFromSequence operator (since opset 11 in the ai.onnx domain). The project’s runtime Tensor type does not natively model sequence values, so this kernel takes the sequence as a std::vector<Tensor> of identically-typed tensors. All inputs must share the same data_type and rank, and must agree on every dimension except (for new_axis == 0) the concat axis, which must be equal across inputs (for new_axis == 1) every dimension must match exactly. The output element type is the common input element type; the output shape follows the ONNX schema (rank r for new_axis == 0, rank r + 1 for new_axis == 1).

Public Functions

Tensor operator()(const std::vector<Tensor> &inputs, int64_t axis, int64_t new_axis = 0) const#

Returning overload. axis follows the ONNX convention and may be negative; new_axis must be 0 (concat) or 1 (stack).

void operator()(const std::vector<Tensor> &inputs, int64_t axis, int64_t new_axis, Tensor &output) const#

In-place overload. output must already carry the expected data_type, shape and sufficiently-sized data buffer.

inline explicit KernelBase(const KernelContext &ctx)#

Public Static Functions

static inline constexpr bool CanRunInPlace() noexcept#

Output layout fundamentally differs from any single input (concatenation/stacking along an axis), so aliasing is not permitted.

class SequenceAt : public onnx_light::onnx_kernels::kernel::KernelBase#
#include <include_sequence_kernels.h>

Returns a copy of the tensor at position in input_sequence. This mirrors ONNX SequenceAt (since opset 11 in the ai.onnx domain).

position is a required scalar INT32 or INT64 tensor. Negative positions count from the back of the sequence: position == -1 addresses the last element. The accepted range is [-n, n - 1] where n is the sequence length.

Public Functions

Tensor operator()(const Sequence &input_sequence, const Tensor &position) const#

Returns a copy of the tensor at position.

inline explicit KernelBase(const KernelContext &ctx)#
class SequenceConstruct : public onnx_light::onnx_kernels::kernel::KernelBase#
#include <include_sequence_kernels.h>

Stacks inputs along a new outer axis 0 to materialize the constructed tensor sequence. All inputs must share the same data_type and shape; the output has shape [N, *inputs[0].shape] and contains the concatenation of the per-input byte buffers.

Public Functions

Tensor operator()(const std::vector<Tensor> &inputs) const#
void operator()(const std::vector<Tensor> &inputs, Tensor &output) const#
Sequence AsSequence(const std::vector<Tensor> &inputs) const#

Sequence-returning overload. Builds an :cpp:struct:Sequence whose elem_type is the common element type of inputs (or UNDEFINED when inputs is empty) and whose values preserves the input order. Unlike the Tensor-returning overloads, this overload does not stack the inputs into a single buffer and does not require the inputs to share a common shape.

inline explicit KernelBase(const KernelContext &ctx)#

Public Static Functions

static inline constexpr bool CanRunInPlace() noexcept#

Output layout is a stacked concatenation of input byte buffers, which cannot share storage with any single input buffer.

class SequenceEmpty : public onnx_light::onnx_kernels::kernel::KernelBase#
#include <include_sequence_kernels.h>

Constructs an empty tensor sequence with element type dtype. This mirrors ONNX SequenceEmpty (since opset 11 in the ai.onnx domain).

dtype is the integer value of an ONNX TensorProto::DataType (e.g. DataType::FLOAT). When dtype is 0 (DataType::UNDEFINED), the kernel falls back to DataType::FLOAT to match the ONNX schema default.

Public Functions

Sequence operator()(int32_t dtype = 0) const#

Returns an empty :cpp:struct:Sequence whose elem_type is the resolved dtype (defaulting to DataType::FLOAT).

inline explicit KernelBase(const KernelContext &ctx)#

Public Static Functions

static inline constexpr bool CanRunInPlace() noexcept#

Output sequence is freshly constructed, so it cannot share storage with any input (there are no inputs).

class SequenceErase : public onnx_light::onnx_kernels::kernel::KernelBase#
#include <include_sequence_kernels.h>

Removes the tensor at position from input_sequence and returns the resulting sequence. This mirrors ONNX SequenceErase (since opset 11 in the ai.onnx domain).

position is optional; when omitted the last element is erased. Negative positions count from the back of the sequence: position == -1 addresses the last element. The accepted range is [-n, n - 1] where n is the sequence length.

Public Functions

Sequence operator()(const Sequence &input_sequence, const Tensor *position = nullptr) const#

Erases the element at position (default: last element).

inline explicit KernelBase(const KernelContext &ctx)#
class SequenceInsert : public onnx_light::onnx_kernels::kernel::KernelBase#
#include <include_sequence_kernels.h>

Inserts tensor into input_sequence at position and returns the resulting sequence. This mirrors ONNX SequenceInsert (since opset 11 in the ai.onnx domain).

position is optional; when omitted tensor is appended to the back of the sequence. position may be a scalar tensor or a single-element tensor of shape [1] (ONNX backend models supply the latter). Negative positions count from the back: position == -1 inserts before the last element. The accepted range is [-n, n] where n is the sequence length.

Public Functions

Sequence operator()(const Sequence &input_sequence, const Tensor &tensor, const Tensor *position = nullptr) const#

Inserts tensor at position (default: append to back).

inline explicit KernelBase(const KernelContext &ctx)#
class SequenceLength : public onnx_light::onnx_kernels::kernel::KernelBase#
#include <include_sequence_kernels.h>

Produces a scalar INT64 tensor containing the number of tensor elements in input_sequence. This mirrors ONNX SequenceLength (since opset 11 in the ai.onnx domain).

Public Functions

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

Computes Tensor<int64, {}>{ len(input_sequence) }.

inline explicit KernelBase(const KernelContext &ctx)#
class SequenceMap : public onnx_light::onnx_kernels::kernel::KernelBase#
#include <include_sequence_kernels.h>

Reference implementation of the ONNX SequenceMap operator (since opset 17 in the ai.onnx domain).

Like :class:If and :class:Loop, this kernel does not execute the body subgraph itself; it consumes already-evaluated per-iteration body output tensors and merely assembles the operator’s output sequences:

  • the operator has one or more output sequences (M >= 1), one per body output;

  • for each output k, the kernel groups the N per-iteration tensors body_outputs_per_iter[k] into a single :cpp:struct:Sequence of length N, where N == input_sequence.size();

  • all per-iteration tensors of a given output k must share the same data type (the ONNX schema permits per-iteration shape variation, so shapes are not required to match).

The kernel is therefore a faithful reference for the operator’s composition semantics that is useful for shape and type-propagation tests while keeping the implementation independent from any graph executor.

Public Functions

std::vector<Sequence> operator()(const Sequence &input_sequence, const std::vector<std::vector<Tensor>> &body_outputs_per_iter) const#
Parameters:
  • input_sequence – Input sequence whose length determines the number of iterations N.

  • body_outputs_per_iter – Per-iteration body outputs, given as body_outputs_per_iter[k][i]M body outputs each with one tensor per iteration (rectangular). Every row must have length N and all tensors in a given row must share the same data type.

Returns:

M output sequences each of length N.

inline explicit KernelBase(const KernelContext &ctx)#

Public Static Functions

static inline constexpr bool CanRunInPlace() noexcept#

Output sequences are freshly constructed, so they cannot share storage with any input.

class SplitToSequence : public onnx_light::onnx_kernels::kernel::KernelBase#
#include <include_sequence_kernels.h>

Splits input along axis into a tensor sequence. This mirrors ONNX SplitToSequence (since opset 11 in the ai.onnx domain).

When split is null (omitted), input is split into chunks of size 1 along axis; keepdims controls whether the split axis is preserved (default 1) or squeezed away (0).

When split is provided, keepdims is ignored. If split is a scalar (rank-0 INT32/INT64 tensor) with value s, input is split into equal chunks of size s along axis; the last chunk may be smaller when the axis dimension is not divisible by s. If split is a 1-D INT32/INT64 tensor, its entries give the per-chunk size along axis and must sum to input.shape[axis].

axis may be negative, in which case it counts from the back of input’s rank. The kernel supports all whole-byte element types supported by :cpp:func:ElementSize; STRING and sub-byte element types are not supported and will cause the kernel to throw std::invalid_argument.

Public Functions

Sequence operator()(const Tensor &input, const Tensor *split, int64_t axis = 0, int64_t keepdims = 1) const#

Computes the split. split may be nullptr (omitted), a scalar INT32/INT64 tensor, or a 1-D INT32/INT64 tensor.

inline explicit KernelBase(const KernelContext &ctx)#

Public Static Functions

static inline constexpr bool CanRunInPlace() noexcept#

Output sequence elements are freshly allocated slices and do not share storage with input.