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_NAMESPACEso 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 withONNX_APIcompile without modification.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 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(whennew_axis == 0, the default) or stacks them along a new axis at positionaxis(whennew_axis == 1), mirroring the ONNXConcatFromSequenceoperator (since opset 11 in the ai.onnx domain). The project’s runtimeTensortype does not natively model sequence values, so this kernel takes the sequence as astd::vector<Tensor>of identically-typed tensors. All inputs must share the samedata_typeand rank, and must agree on every dimension except (fornew_axis == 0) the concat axis, which must be equal across inputs (fornew_axis == 1) every dimension must match exactly. The output element type is the common input element type; the output shape follows the ONNX schema (rankrfornew_axis == 0, rankr + 1fornew_axis == 1).Public Functions
-
Tensor operator()(const std::vector<Tensor> &inputs, int64_t axis, int64_t new_axis = 0) const#
Returning overload.
axisfollows the ONNX convention and may be negative;new_axismust 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.
outputmust already carry the expecteddata_type,shapeand sufficiently-sizeddatabuffer.
-
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.
-
Tensor operator()(const std::vector<Tensor> &inputs, int64_t axis, int64_t new_axis = 0) const#
-
class SequenceAt : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_sequence_kernels.h>
Returns a copy of the tensor at
positionininput_sequence. This mirrors ONNXSequenceAt(since opset 11 in the ai.onnx domain).positionis a required scalar INT32 or INT64 tensor. Negative positions count from the back of the sequence:position == -1addresses the last element. The accepted range is[-n, n - 1]wherenis the sequence length.
-
class SequenceConstruct : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_sequence_kernels.h>
Stacks
inputsalong a new outer axis 0 to materialize the constructed tensor sequence. All inputs must share the samedata_typeandshape; the output has shape[N, *inputs[0].shape]and contains the concatenation of the per-input byte buffers.Public Functions
-
Sequence AsSequence(const std::vector<Tensor> &inputs) const#
Sequence-returning overload. Builds an :cpp:struct:
Sequencewhoseelem_typeis the common element type ofinputs(orUNDEFINEDwheninputsis empty) and whosevaluespreserves the input order. Unlike theTensor-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.
-
Sequence AsSequence(const std::vector<Tensor> &inputs) const#
-
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 ONNXSequenceEmpty(since opset 11 in the ai.onnx domain).dtypeis the integer value of an ONNXTensorProto::DataType(e.g.DataType::FLOAT). Whendtypeis0(DataType::UNDEFINED), the kernel falls back toDataType::FLOATto match the ONNX schema default.Public Functions
-
Sequence operator()(int32_t dtype = 0) const#
Returns an empty :cpp:struct:
Sequencewhoseelem_typeis the resolveddtype(defaulting toDataType::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).
-
Sequence operator()(int32_t dtype = 0) const#
-
class SequenceErase : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_sequence_kernels.h>
Removes the tensor at
positionfrominput_sequenceand returns the resulting sequence. This mirrors ONNXSequenceErase(since opset 11 in the ai.onnx domain).positionis optional; when omitted the last element is erased. Negative positions count from the back of the sequence:position == -1addresses the last element. The accepted range is[-n, n - 1]wherenis the sequence length.
-
class SequenceInsert : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_sequence_kernels.h>
Inserts
tensorintoinput_sequenceatpositionand returns the resulting sequence. This mirrors ONNXSequenceInsert(since opset 11 in the ai.onnx domain).positionis optional; when omittedtensoris appended to the back of the sequence.positionmay 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 == -1inserts before the last element. The accepted range is[-n, n]wherenis the sequence length.
-
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 ONNXSequenceLength(since opset 11 in the ai.onnx domain).
-
class SequenceMap : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_sequence_kernels.h>
Reference implementation of the ONNX
SequenceMapoperator (since opset 17 in the ai.onnx domain).Like :class:
Ifand :class:Loop, this kernel does not execute thebodysubgraph 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 theNper-iteration tensorsbody_outputs_per_iter[k]into a single :cpp:struct:Sequenceof lengthN, whereN == input_sequence.size();all per-iteration tensors of a given output
kmust 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]—Mbody outputs each with one tensor per iteration (rectangular). Every row must have lengthNand all tensors in a given row must share the same data type.
- Returns:
Moutput sequences each of lengthN.
-
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
inputalongaxisinto a tensor sequence. This mirrors ONNXSplitToSequence(since opset 11 in the ai.onnx domain).When
splitis null (omitted),inputis split into chunks of size 1 alongaxis;keepdimscontrols whether the split axis is preserved (default 1) or squeezed away (0).When
splitis provided,keepdimsis ignored. Ifsplitis a scalar (rank-0 INT32/INT64 tensor) with values,inputis split into equal chunks of sizesalongaxis; the last chunk may be smaller when the axis dimension is not divisible bys. Ifsplitis a 1-D INT32/INT64 tensor, its entries give the per-chunk size alongaxisand must sum toinput.shape[axis].axismay be negative, in which case it counts from the back ofinput’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 throwstd::invalid_argument.Public Functions
-
Sequence operator()(const Tensor &input, const Tensor *split, int64_t axis = 0, int64_t keepdims = 1) const#
Computes the split.
splitmay benullptr(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.
-
Sequence operator()(const Tensor &input, const Tensor *split, int64_t axis = 0, int64_t keepdims = 1) const#
-
class ConcatFromSequence : public onnx_light::onnx_kernels::kernel::KernelBase#
-
namespace kernel
-
namespace onnx_kernels