include_tensor_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 AffineGrid : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
AffineGridoperator (since opset 20 in theai.onnxdomain). Generates a flow field of sampling coordinates by applying a batch of affine matricesthetato a regular grid of sizesize.Inputs:
theta: FLOAT tensor of shape(N, 2, 3)for 2D or(N, 3, 4)for 3D.size: INT64 1-D tensor of length 4 ((N, C, H, W)) for 2D or 5 ((N, C, D, H, W)) for 3D. Only the spatial dimensions(H, W)or(D, H, W)are used;Nis taken fromtheta(and must matchsize[0]) andCis ignored.
Attribute
align_corners(int, default 0): when 1, the normalised coordinates-1and+1refer to the centres of the corner pixels; when 0 they refer to the outer edges (the convention matchingtorch.nn.functional.affine_grid).Output shape:
(N, H, W, 2)for 2D or(N, D, H, W, 3)for 3D. The element type follows thethetainput (FLOAT in this implementation).Public Functions
-
Tensor operator()(const Tensor &theta, const Tensor &size, const Attributes &attrs) const#
-
void operator()(const Tensor &theta, const Tensor &size, const Attributes &attrs, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output shape and element layout differ from both inputs, so the output cannot share storage with any input buffer.
-
struct Attributes#
- #include <include_tensor_kernels.h>
Attributes carried by the ONNX
AffineGridoperator.Public Members
-
int64_t align_corners = 0#
-
int64_t align_corners = 0#
-
class BitCast : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
BitCastoperator (since opset 26). Reinterprets the bit pattern of the input tensor as the data typetowithout value conversion.tomust be a non-string type with the same element bit-width asx.data_type; otherwise the kernel throwsstd::invalid_argument. Implementations treat the underlying bytes as little endian, which matches the host ABIs targeted by the backend test library.Public Functions
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
In-place execution is permitted only when
to == x.data_type; the kernel itself does not enforce aliasing constraints so this flag is conservativelyfalse.
-
inline explicit KernelBase(const KernelContext &ctx)#
-
class Cast : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Performs element-wise type conversion of an input tensor
xto the data type specified byto(aDataTypevalue, mirroring theCastoperator’s requiredtoattribute). The output shape always matches the input shape.The reference implementation supports the numeric element types in the backend test library —
FLOAT,DOUBLE,INT32,INT64,INT8,UINT8,INT16,UINT16andBOOL— as well asSTRINGin either direction (numeric ↔ STRING uses the canonical decimal representation). Other dtypes will cause the kernel to throwstd::invalid_argument: this is sufficient for the backend test cases registered today and keeps the implementation small. Out-of-range floating-point values when casting to an integer dtype follow C++static_castsemantics, which matches the behaviour exercised by the upstreamtest_cast_FLOAT_to_*node tests for the supported conversions.Public Functions
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output element type may differ from the input element type, so storage can not be shared in general.
-
inline explicit KernelBase(const KernelContext &ctx)#
-
class CastLike : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Performs element-wise type conversion of an input tensor
xto the data type carried bytarget_type(a second tensor whose values are ignored). This mirrors the ONNXCastLikeoperator (since opset 15 in the ai.onnx domain), which is equivalent toCastwithto = target_type.data_type.The reference implementation forwards to :ref:
kernel::Castand so supports the same element-type matrix.Public Functions
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output element type may differ from the input element type, so storage can not be shared in general.
-
inline explicit KernelBase(const KernelContext &ctx)#
-
class CenterCropPad : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
CenterCropPadoperator (since opset 18 in theai.onnxdomain). It centrally crops and/or pads the input tensor to the dimensions given by theshapeinput. Theshapeinput is a 1-D tensor of lengthrank(input_data)whenaxesis unset, orlen(axes)otherwise. Theaxesattribute, when set, specifies the subset of input axesshaperefers to; unspecified axes are left unchanged. Negative axes are supported.On each selected axis the kernel matches the upstream reference: when
shape[i] < input_dima centered cropping window of lengthshape[i]is extracted (the start index is rounded down on odd differences); whenshape[i] > input_dimthe input is zero-padded equally on both sides (an extra pixel is added on the right when the total padding is odd).Public Functions
-
Tensor operator()(const Tensor &input_data, const Tensor &shape, const Attributes &attrs) const#
-
void operator()(const Tensor &input_data, const Tensor &shape, const Attributes &attrs, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output shape generally differs from input shape, so storage cannot be shared with the input buffer.
-
struct Attributes#
- #include <include_tensor_kernels.h>
Attributes carried by the ONNX
CenterCropPadoperator.axesis optional; an empty vector here means “all axes” (i.e.shapehas length equal torank(input_data)).
-
Tensor operator()(const Tensor &input_data, const Tensor &shape, const Attributes &attrs) const#
-
class Compress : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
Compressoperator (since opset 9 in theai.onnxdomain; axis may be negative since opset 11). Selects slices frominputalong a givenaxiswhere the corresponding entry ofcondition(a rank-1 BOOL tensor) istrue. Whenaxisis not supplied the input is first flattened and individual elements are selected; the output is then a 1-D tensor.The
conditionlength may be shorter than the input size along the axis (or the flattened size when no axis is given); excess slices are discarded.The output dtype always matches
input. The selected count is a runtime value and is therefore unknown at shape-inference time.Public Functions
-
Tensor operator()(const Tensor &input, const Tensor &condition, std::optional<int64_t> axis) const#
axisis anstd::optional<int64_t>: passstd::nulloptto compress the flattened input, or the axis index to compress along.
-
void operator()(const Tensor &input, const Tensor &condition, std::optional<int64_t> axis, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output size is data-dependent and cannot be inferred without evaluating
conditionat runtime.
-
Tensor operator()(const Tensor &input, const Tensor &condition, std::optional<int64_t> axis) const#
-
class Concat : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Concatenates a list of tensors along
axis(since opset 13). All input tensors must share the same data type and the same shape except along the concatenation axis.axismay be negative, in which case it counts from the back of the input rank.Public Functions
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
-
inline explicit KernelBase(const KernelContext &ctx)#
-
class DepthToSpace : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
DepthToSpaceoperator (since opset 1;modeattribute added in opset 11; type set extended in opset 13). Rearranges (permutes) data from depth into blocks of spatial data — the inverse ofSpaceToDepth. The input must be a 4-D tensor of shape(N, C, H, W)withCdivisible byblocksize * blocksize. The output has shape(N, C/(blocksize*blocksize), H*blocksize, W*blocksize).modeis either"DCR"(default; depth-column-row order) or"CRD"(column-row-depth order); the reference implementation matches the upstream NumPy equivalents in the operator spec.The reference implementation supports whole-byte tensor element types supported by :cpp:func:
ElementSize.Public Functions
-
Tensor operator()(const Tensor &input, const Attributes &attrs) const#
-
void operator()(const Tensor &input, const Attributes &attrs, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output shape differs from input shape in general.
-
struct Attributes#
- #include <include_tensor_kernels.h>
Attributes carried by the ONNX
DepthToSpaceoperator.
-
Tensor operator()(const Tensor &input, const Attributes &attrs) const#
-
class Expand : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Broadcasts the
inputtensor to the shape given by the 1-D INT64shapetensor, following the ONNX numpy-style broadcasting rules (ONNXExpandoperator, since opset 8 in theai.onnxdomain).The output shape is computed as
broadcast(input.shape, shape_values). A dimension ininputof size 1 is expanded (repeated) to match the corresponding target dimension; a dimension equal to the target is left unchanged. The output dtype always matches the input dtype.The reference implementation supports all whole-byte element types supported by :cpp:func:
ElementSize. String and sub-byte dtypes (INT4/UINT4/INT2/UINT2) are not supported and will cause the kernel to throwstd::invalid_argument.Public Functions
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
The output may be larger than either input, so storage cannot be shared in general.
-
inline explicit KernelBase(const KernelContext &ctx)#
-
class Gather : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
Gatheroperator (since opset 1 in theai.onnxdomain). Gathers entries of theaxisdimension ofdataindexed byindices, producing an output tensor of rankq + (r - 1)wherer = rank(data)andq = rank(indices).indicesmay be INT32 or INT64; negative values count from the back of the gathered axis. The output dtype always matchesdata.Public Functions
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output shape differs from input shape in general.
-
inline explicit KernelBase(const KernelContext &ctx)#
-
class GatherElements : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
GatherElementsoperator (since opset 11 in theai.onnxdomain).dataandindicesmust have the same rankrand the output has the same shape asindices.In the 3-D case:
out[i][j][k] = data[indices[i][j][k]][j][k]whenaxis == 0(and analogously for other axes).indicesmay be INT32 or INT64; negative values count from the back of the gathered axis.Public Functions
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output shape matches
indicesand differs fromdatain general.
-
inline explicit KernelBase(const KernelContext &ctx)#
-
class GatherND : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
GatherNDoperator (since opset 11 in theai.onnxdomain;batch_dimsattribute added in opset 12). Gathers slices fromdataat the index tuples encoded byindicesand produces an output of rankq + r - indices_shape[-1] - 1 - bwhereq = rank(indices),r = rank(data)andb = batch_dims.indicesmust be INT64. Negative index values count from the back of the correspondingdataaxis.Public Functions
-
void operator()(const Tensor &data, const Tensor &indices, int64_t batch_dims, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output shape differs from both inputs in general.
-
void operator()(const Tensor &data, const Tensor &indices, int64_t batch_dims, Tensor &output) const#
-
class GridSample : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
GridSampleoperator (since opset 16 in theai.onnxdomain; extended to N-D in opset 20). Performs sampling of an input tensorXat the positions given by the flow fieldgrid.Inputs:
X: tensor of shape(N, C, D1, D2, ..., Dr)withrspatial dimensions (r >= 1).grid: floating-point tensor of shape(N, D1_out, D2_out, ..., Dr_out, r)carrying normalised sampling coordinates.
mode(string, default"linear"/"bilinear"): interpolation mode, one of"linear"/"bilinear","nearest"or"cubic"/"bicubic".padding_mode(string, default"zeros"): one of"zeros","border"or"reflection".align_corners(int, default 0): when 1, the normalised coordinates-1and+1refer to the centres of the corner pixels; when 0 they refer to the outer edges.
Output shape:
(N, C, D1_out, D2_out, ..., Dr_out). The element type followsX; this implementation supports the FLOAT/DOUBLE element types ofXandgrid.Public Functions
-
Tensor operator()(const Tensor &X, const Tensor &grid, const Attributes &attrs) const#
-
void operator()(const Tensor &X, const Tensor &grid, const Attributes &attrs, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output shape differs from both inputs, so the output cannot share storage with any input buffer.
-
struct Attributes#
- #include <include_tensor_kernels.h>
Attributes carried by the ONNX
GridSampleoperator.
-
class Identity : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
Identityoperator (since opset 1 in theai.onnxdomain). Copies the input tensor to the output unchanged. The output dtype and shape always match the input.The kernel is element-type agnostic: it simply copies the raw data buffer (and forwards string elements when applicable), so it accepts any tensor element type supported by
Tensor.Public Functions
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output is a bit-for-bit copy of the input; storage may safely be shared when the caller decides so.
-
inline explicit KernelBase(const KernelContext &ctx)#
-
class NonZero : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Returns the indices of the elements that are non-zero of the input tensor
Xin row-major order, as a 2-DINT64tensor of shape(rank, nnz)(ONNXNonZerooperator, since opset 9 in theai.onnxdomain). For scalar input the output shape is(0, nnz)(mirroring the upstream specification, which differs from NumPy).The reference implementation supports the numeric and
BOOLelement types in the backend test library —FLOAT,DOUBLE,INT8,UINT8,INT16,UINT16,INT32,INT64,UINT32,UINT64andBOOL. Other dtypes will cause the kernel to throwstd::invalid_argument.Public Functions
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
The output has a different dtype (INT64) and a different shape from the input, so storage cannot be shared.
-
inline explicit KernelBase(const KernelContext &ctx)#
-
class OneHot : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
OneHotoperator (since opset 9 in theai.onnxdomain; opset 11 added support for negative indices).Inputs:
indices: rank>= 1numeric tensor of indices. Negative entries are accepted from opset 11 onwards (negativeiselects depth positioni + depth); entries outside[-depth, depth-1](or[0, depth)for opset 9) leave the corresponding row filled withoff_value.depth: numeric scalar (or rank-1 tensor with a single element) giving the size of the new one-hot dimension.values: rank-1 tensor of length 2, formatted as[off_value, on_value].
Attribute
axis(int, default-1): position at which the new dimension is inserted in the output. Accepted range is[-rank(indices)-1, rank(indices)].The output has rank
rank(indices) + 1; its element type matchesvalues. The reference implementation supports all numeric element types forindicesanddepth(cast toint64before use) and all numeric andBOOLelement types forvalues/ the output.Public Functions
-
Tensor operator()(const Tensor &indices, const Tensor &depth, const Tensor &values, const Attributes &attrs) const#
-
void operator()(const Tensor &indices, const Tensor &depth, const Tensor &values, const Attributes &attrs, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
The output has a different shape (one extra dimension) than any of the inputs, so storage cannot be shared.
-
struct Attributes#
- #include <include_tensor_kernels.h>
Attributes carried by the ONNX
OneHotoperator.Public Members
-
int64_t axis = -1#
-
int64_t axis = -1#
-
class Pad : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Pads the input
datatensor along selected axes (ONNXPadoperator, since opset 18 with theaxesinput; earlier semantics covered by passingaxes == nullptr).padsis a 1-D INT64 tensor of length2 * num_axesformatted as[x1_begin, x2_begin, ..., x1_end, x2_end, ...]. Whenaxesisnullptrit defaults to[0, 1, ..., rank-1].constant_valueis an optional scalar (one-element tensor) used only whenmodeis"constant"(its dtype must matchdata); whennullptrand the mode is"constant", the kernel uses a zero-initialized value of the input dtype. Supported modes mirrornumpy.pad:"constant"(default),"reflect","edge"and"wrap"(introduced in opset 19).All padding entries must be non-negative (negative pads, i.e. cropping, are accepted by the schema but the reference implementation rejects them to keep the kernel focused on the cases covered by the bundled tests). String and sub-byte dtypes are not supported and cause the kernel to throw
std::invalid_argument.Public Functions
-
Tensor operator()(const Tensor &data, const Tensor &pads, const Tensor *constant_value = nullptr, const Tensor *axes = nullptr, const std::string &mode = "constant") const#
-
void operator()(const Tensor &data, const Tensor &pads, const Tensor *constant_value, const Tensor *axes, const std::string &mode, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
-
Tensor operator()(const Tensor &data, const Tensor &pads, const Tensor *constant_value = nullptr, const Tensor *axes = nullptr, const std::string &mode = "constant") const#
-
class Reshape : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reshapes
datato the target shape described by the 1-D INT64shapetensor (ONNXReshapeoperator, since opset 5; withallowzeroinput semantics unchanged in newer opsets).Output dtype always matches
data. The output shape follows ONNX rules: positive values are copied, one-1is inferred from element count, and0copies the corresponding input dim unlessallowzerois set.Public Functions
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
-
inline explicit KernelBase(const KernelContext &ctx)#
-
class Resize : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
Resizeoperator (since opset 10 in theai.onnxdomain, replacing the deprecatedUpsample).The kernel computes
Yfrom inputXand eitherscales(a 1-D FLOAT tensor with one entry per input axis) orsizes(a 1-D INT64 tensor giving the target shape). Exactly one ofscalesandsizesmust be provided. The output dimiisfloor(X.shape[i] * scales[i])whenscalesis used andsizes[i]whensizesis used.The
"nearest","linear"and"cubic"modes of themodeattribute are supported. The input coordinate of an output position is computed according tocoordinate_transformation_mode(half_pixel— the default —half_pixel_symmetric,pytorch_half_pixel,align_cornersandasymmetric). In"nearest"mode it is rounded according tonearest_modeand clamped to[0, in_dim - 1]; all four ONNXnearest_modevalues (round_prefer_floor— the default —round_prefer_ceil,floor,ceil) are supported. In"linear"and"cubic"mode, the output is computed as a separable per-axis weighted sum of neighbouring input samples (2 taps for"linear", 4 taps for"cubic"); thecubic_coeff_aattribute (default-0.75) tunes the cubic kernel andexclude_outside(default0) renormalises the coefficients when the support window falls outside the input range. The optionalaxesattribute (opset 18) selects the subset of axesscales/sizesrefer to, andkeep_aspect_ratio_policy("stretch"— the default —"not_larger","not_smaller") is honoured whensizesis used. The"tf_crop_and_resize"coordinate transformation is supported (using theroiargument provided through :cpp:member:Attributes::roiand theextrapolation_valueattribute);antialiasis supported for"linear"and"cubic"modes (when non-zero, the interpolation kernel is widened by the resize scale while downsampling to act as an anti-aliasing filter). The supported element types are the same whole-byte types as :cpp:func:ElementSizefor"nearest"mode;"linear"and"cubic"modes require a floating-point input (FLOATorDOUBLE).Public Functions
-
Tensor operator()(const Tensor &X, const Tensor &scales, const Attributes &attrs) const#
Resize using the
scalesinput only. Thesizesinput is treated as absent (matching theResize(X, scales)convenience form).
-
void operator()(const Tensor &X, const Tensor &scales, const Attributes &attrs, Tensor &output) const#
-
Tensor ResizeSizes(const Tensor &X, const Tensor &sizes, const Attributes &attrs) const#
Resize using the
sizesinput (1-D INT64 tensor giving the target shape). Thescalesinput must be empty.
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output shape generally differs from input shape, so storage cannot be shared with the input buffer.
-
struct Attributes#
- #include <include_tensor_kernels.h>
Attributes carried by the ONNX
Resizeoperator.Public Members
-
std::vector<int64_t> axes#
Subset of input axes that
scales/sizesapply to. When empty, every axis is resized (matching the pre-opset-18 behaviour).
-
std::string keep_aspect_ratio_policy = "stretch"#
How to interpret
sizes."stretch"honourssizesexactly;"not_larger"/"not_smaller"rescale by a common factor so that the resulting output is not larger / smaller thansizeson any of the selectedaxes(other axes are left untouched).
-
float cubic_coeff_a = -0.75f#
Coefficient
Aof the cubic interpolation kernel (used only whenmode == "cubic"). Defaults to-0.75to match the ONNX spec.
-
int64_t exclude_outside = 0#
When non-zero (and
modeis"linear"or"cubic"), coefficients corresponding to neighbours that fall outside the input range are zeroed and the remaining coefficients are renormalised to sum to 1.
-
float extrapolation_value = 0.0f#
Value used when
coordinate_transformation_modeis"tf_crop_and_resize"and the transformed coordinate falls outside[0, input_dim - 1]. Ignored for every other coordinate transformation mode.
-
std::vector<float> roi#
Region of interest (used only by the
"tf_crop_and_resize"coordinate transformation). Stored as[start_axis_0, ..., start_axis_{N-1}, end_axis_0, ..., end_axis_{N-1}], whereNis the number of resized axes (i.e.axes.size()whenaxesis non-empty, otherwise the input rank).
-
int64_t antialias = 0#
When non-zero (and
modeis"linear"or"cubic"), the interpolation kernel is stretched by the resize scale when downsampling so that it acts as an anti-aliasing low-pass filter. Ignored for"nearest"mode and for upsampling (scale >= 1).
-
std::vector<int64_t> axes#
-
Tensor operator()(const Tensor &X, const Tensor &scales, const Attributes &attrs) const#
-
class ReverseSequence : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
ReverseSequenceoperator (since opset 10 in theai.onnxdomain). Reverses, for each batch slicei, the firstsequence_lens[i]elements along the time axis. Elements past that prefix are copied unchanged.Inputs:
input: tensor of rank>= 2. Thetime_axisandbatch_axisattributes (each one of0or1) select which of the first two dimensions plays the time / batch role. Any remaining dimensions are treated as inner (feature) dimensions and copied unchanged.sequence_lens: rank-1INT64tensor of lengthinput.shape[batch_axis]. Each entry must satisfy0 <= sequence_lens[i] <= input.shape[time_axis].
Attributes
time_axis(int, default0) andbatch_axis(int, default1): must be0or1and must differ.Output shape and dtype always match
input.Public Functions
-
Tensor operator()(const Tensor &input, const Tensor &sequence_lens, const Attributes &attrs) const#
-
void operator()(const Tensor &input, const Tensor &sequence_lens, const Attributes &attrs, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output shape matches input shape so the kernel can in theory share storage with the input; the reference implementation always writes into a freshly allocated buffer.
-
struct Attributes#
- #include <include_tensor_kernels.h>
Attributes carried by the ONNX
ReverseSequenceoperator.
-
class Scatter : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the deprecated ONNX
Scatteroperator (opset 9, deprecated since opset 11 in favour ofScatterElements). Semantically equivalent toScatterElementswithreduction="none":data,indicesandupdatesmust have the same rankrand the output has the same shape and dtype asdata.indicesmay be INT32 or INT64; negative values count from the back of the scattered axis.Public Functions
-
Tensor operator()(const Tensor &data, const Tensor &indices, const Tensor &updates, const Attributes &attrs) const#
-
void operator()(const Tensor &data, const Tensor &indices, const Tensor &updates, const Attributes &attrs, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output shape matches
dataso the output buffer could share storage with the first input; the reference implementation always writes into a freshly allocated buffer.
-
struct Attributes#
- #include <include_tensor_kernels.h>
Attributes carried by the ONNX
Scatteroperator.Public Members
-
int64_t axis = 0#
-
int64_t axis = 0#
-
Tensor operator()(const Tensor &data, const Tensor &indices, const Tensor &updates, const Attributes &attrs) const#
-
class ScatterElements : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
ScatterElementsoperator (since opset 11 in theai.onnxdomain;reductionattribute added in opset 16 (add/mul) and extended in opset 18 (max/min)).data,indicesandupdatesmust have the same rankrand the output has the same shape and dtype asdata.indicesmay be INT32 or INT64; negative values count from the back of the scattered axis.When
reductionis"none", repeated indices result in unspecified behaviour (the order of iteration is not defined). Whenreductionis"add","mul","max"or"min", the corresponding element ofdatais updated withf(out_elem, updates_elem).Public Functions
-
Tensor operator()(const Tensor &data, const Tensor &indices, const Tensor &updates, const Attributes &attrs) const#
-
void operator()(const Tensor &data, const Tensor &indices, const Tensor &updates, const Attributes &attrs, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output shape matches
dataso the output buffer could share storage with the first input; the reference implementation always writes into a freshly allocated buffer.
-
struct Attributes#
- #include <include_tensor_kernels.h>
Attributes carried by the ONNX
ScatterElementsoperator.
-
Tensor operator()(const Tensor &data, const Tensor &indices, const Tensor &updates, const Attributes &attrs) const#
-
class ScatterND : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
ScatterNDoperator (since opset 11 in theai.onnxdomain;reductionattribute added in opset 16 (add/mul) and extended in opset 18 (max/min)). The output has the same shape and dtype asdata.indicesmust be INT64; negative values count from the back of the correspondingdataaxis.When
reductionis"none", repeated indices result in unspecified behaviour. Whenreductionis"add","mul","max"or"min", the corresponding slice ofdatais updated withf(out_slice, updates_slice).Public Functions
-
Tensor operator()(const Tensor &data, const Tensor &indices, const Tensor &updates, const Attributes &attrs) const#
-
void operator()(const Tensor &data, const Tensor &indices, const Tensor &updates, const Attributes &attrs, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output shape matches
dataso the output buffer could share storage with the first input; the reference implementation always writes into a freshly allocated buffer.
-
struct Attributes#
- #include <include_tensor_kernels.h>
Attributes carried by the ONNX
ScatterNDoperator.
-
Tensor operator()(const Tensor &data, const Tensor &indices, const Tensor &updates, const Attributes &attrs) const#
-
class Shape : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
Shapeoperator (since opset 1 in theai.onnxdomain; extended withstart/endattributes in opset 15). Returns the shape of the input tensor as anINT641-D tensor.Attributes
start(int, default 0) andend(int, optional) bound the sliceinput.shape[start:end](using numpy-style indexing). Negative values count from the back; out-of-range values are clamped to[0, r]whereris the rank of the input. Whenstart > end(after normalisation) the output is empty.The kernel reads only the input shape, never its data buffer, so it accepts an input of any element type.
Public Functions
-
Tensor operator()(const Tensor &data, const Attributes &attrs) const#
-
void operator()(const Tensor &data, const Attributes &attrs, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output has a different dtype (INT64) and shape from the input, so storage cannot be shared.
-
struct Attributes#
- #include <include_tensor_kernels.h>
Attributes carried by the ONNX
Shapeoperator.
-
Tensor operator()(const Tensor &data, const Attributes &attrs) const#
-
class Size : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
Sizeoperator (since opset 1 in theai.onnxdomain). Returns a 0-D (scalar) INT64 tensor whose single value is the total number of elements of the input tensor, i.e. the product of its dimensions.The kernel reads only the input shape, never its data buffer, so it accepts an input of any element type.
Public Functions
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output has a different dtype (INT64) and shape (scalar) from the input, so storage cannot be shared.
-
inline explicit KernelBase(const KernelContext &ctx)#
-
class Slice : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Slices
dataaccording to ONNXSlicesemantics (since opset 10+):startsandendsare required;axesandstepsare optional.Supports positive and negative steps, negative indices, omitted axes/steps, and clamping behavior aligned with ONNX shape-inference rules.
Public Functions
-
Tensor operator()(const Tensor &data, const Tensor &starts, const Tensor &ends, const Tensor *axes = nullptr, const Tensor *steps = nullptr) const#
-
void operator()(const Tensor &data, const Tensor &starts, const Tensor &ends, const Tensor *axes, const Tensor *steps, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
-
Tensor operator()(const Tensor &data, const Tensor &starts, const Tensor &ends, const Tensor *axes = nullptr, const Tensor *steps = nullptr) const#
-
class SpaceToDepth : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
SpaceToDepthoperator (since opset 1; type set extended in opset 13). Rearranges blocks of spatial data into depth — the inverse ofDepthToSpace. The input must be a 4-D tensor of shape(N, C, H, W)withHandWboth divisible byblocksize. The output has shape(N, C*blocksize*blocksize, H/blocksize, W/blocksize).The reference implementation supports whole-byte tensor element types supported by :cpp:func:
ElementSize.Public Functions
-
Tensor operator()(const Tensor &input, const Attributes &attrs) const#
-
void operator()(const Tensor &input, const Attributes &attrs, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output shape differs from input shape in general.
-
struct Attributes#
- #include <include_tensor_kernels.h>
Attributes carried by the ONNX
SpaceToDepthoperator.Public Members
-
int64_t blocksize = 0#
-
int64_t blocksize = 0#
-
Tensor operator()(const Tensor &input, const Attributes &attrs) const#
-
class Split : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Splits
inputalongaxisinto a list of tensors (ONNXSplitoperator). Whensplitis empty the input dimension onaxisis divided intonum_outputschunks of equal size (the last chunk being smaller when the dimension is not evenly divisible). Whensplitis non-empty its entries give the size of each output alongaxisand must sum toinput.shape[axis].axismay be negative, in which case it counts from the back ofinput’s rank.The reference implementation 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
-
std::vector<Tensor> operator()(const Tensor &input, int64_t axis, const std::vector<int64_t> &split, int64_t num_outputs) const#
Computes the split. Exactly one of
split(non-empty) ornum_outputs(> 0) must be provided.
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output buffers are strict subsets of the input and have a different shape, so storage can not generally be shared.
-
std::vector<Tensor> operator()(const Tensor &input, int64_t axis, const std::vector<int64_t> &split, int64_t num_outputs) const#
-
class Squeeze : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Removes dimensions of size 1 from
dataaccording toaxes(ONNXSqueezeoperator). Whenaxesis empty, all dimensions with size 1 are removed.Public Functions
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Rank may change after squeezing.
-
inline explicit KernelBase(const KernelContext &ctx)#
-
class TensorScatter : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
TensorScatteroperator (since opset 24 in theai.onnxdomain). Performs a functional update of a KV-cache style tensor by writing slices ofupdateinto a copy ofpast_cachealong theaxis(sequence) dimension, starting at the per-batch positions given bywrite_indices.Inputs:
past_cache: tensor of rankr >= 2with shape(batch_size, D1, ..., max_sequence_length, ..., Dn).update: tensor of the same dtype and rank aspast_cache; the only dimension that may differ is theaxis(sequence) dimension which holdssequence_length.write_indices: optional 1-DINT64tensor of lengthbatch_size. When omitted (nullptr) it defaults to all zeros.
Attributes
axis(int, default-2) andmode(string, default"linear"):axisselects the sequence dimension and cannot be the batch dimension (0). Whenmodeis"linear"everywrite_indices[batch] + sequence_idxmust remain in[0, max_sequence_length); whenmodeis"circular"the write index wraps around modulomax_sequence_length.Output dtype and shape always match
past_cache.Public Functions
-
Tensor operator()(const Tensor &past_cache, const Tensor &update, const Tensor *write_indices, const Attributes &attrs) const#
-
void operator()(const Tensor &past_cache, const Tensor &update, const Tensor *write_indices, const Attributes &attrs, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output shape matches
past_cacheso the output buffer could share storage with the first input; the reference implementation always writes into a freshly allocated buffer.
-
struct Attributes#
- #include <include_tensor_kernels.h>
Attributes carried by the ONNX
TensorScatteroperator.
-
class Tile : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Constructs a tensor by tiling the
inputtensor a number of times along each axis given by the 1-D INT64repeatstensor (ONNXTileoperator, since opset 6 in theai.onnxdomain).repeatsmust have the same length asinput’s rank, and every entry must be non-negative. The output has the same rank and dtype asinput; its dimensioniisinput.shape[i] * repeats[i].The reference implementation supports all whole-byte element types supported by :cpp:func:
ElementSize. String and sub-byte dtypes (INT4/UINT4/INT2/UINT2) are not supported and will cause the kernel to throwstd::invalid_argument.Public Functions
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
The output is generally larger than the input, so storage cannot be shared in general.
-
inline explicit KernelBase(const KernelContext &ctx)#
-
class Transpose : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Permutes the axes of the input tensor according to
perm(ONNXTransposeoperator). Whenpermis empty, the axis order is reversed.The reference implementation supports whole-byte tensor element types supported by :cpp:func:
ElementSize.Public Functions
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output shape differs from input shape in general.
-
inline explicit KernelBase(const KernelContext &ctx)#
-
class Trilu : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
Triluoperator (since opset 14 in theai.onnxdomain). Returns the upper (upper == 1, default) or lower (upper == 0) triangular part of the input tensor, keeping the elements on/above (resp. on/below) thek-th diagonal and zeroing the others.Inputs:
input: tensor of rank>= 2. The last two dimensions(N, M)are interpreted as a (batch of) matrix; any leading dimensions are treated as batch dimensions and processed independently.k: optionalINT64scalar (0-D tensor) selecting the diagonal to keep/exclude. Defaults to0when omitted (signalled by passingnullptr).
Attribute
upper(int, default 1): when 1 the upper triangular part is retained; when 0 the lower triangular part is retained.Output shape and dtype always match
input. Elements outside the selected triangular region are set to zero (forBOOLtofalse; forSTRINGto the empty string).Public Functions
-
Tensor operator()(const Tensor &input, const Tensor *k, const Attributes &attrs) const#
-
void operator()(const Tensor &input, const Tensor *k, const Attributes &attrs, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output shape matches input shape so the output buffer could in theory share storage with the input; the reference implementation does not rely on that and always writes into a freshly allocated buffer.
-
struct Attributes#
- #include <include_tensor_kernels.h>
Attributes carried by the ONNX
Triluoperator.Public Members
-
int64_t upper = 1#
-
int64_t upper = 1#
-
class Unique : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the ONNX
Uniqueoperator (since opset 11 in theai.onnxdomain). Returns the unique values or subtensors of the input tensor and three optional companion outputs:Y— unique values (1-D whenaxisis not provided) or unique subtensors sliced alongaxis;indices— 1-D INT64 indices of the first occurrence of everyYelement inX;inverse_indices— 1-D INT64 indices that map everyXelement back to its position inY;counts— 1-D INT64 count of eachYelement inX.
When
sortedistrue(the default) outputs are ordered by ascending value (or lexicographic order whenaxisis provided). Whensortedisfalsethe order of first occurrence inXis preserved.The reference implementation supports the same whole-byte element types as :cpp:func:
ElementSize(FLOAT, DOUBLE, INT8/16/32/64, UINT8/16/32/64, BOOL) and STRING.Public Functions
-
Outputs operator()(const Tensor &x, const Attributes &attrs) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
The outputs have different dtypes (Y matches X; the others are INT64) and different shapes, so storage cannot be shared with the input.
-
struct Attributes#
- #include <include_tensor_kernels.h>
Attributes carried by the ONNX
Uniqueoperator.Public Members
-
bool sorted = true#
Whether to sort unique elements in ascending order. Defaults to
true(matching the schema default of 1).
-
bool sorted = true#
-
class Unsqueeze : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Inserts dimensions of size 1 into
dataat positions given byaxes(ONNXUnsqueezeoperator).Public Functions
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Rank changes after unsqueezing.
-
inline explicit KernelBase(const KernelContext &ctx)#
-
class Upsample : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_tensor_kernels.h>
Reference implementation of the (deprecated) ONNX
Upsampleoperator (since opset 1 in theai.onnxdomain, last refreshed at opset 10 and replaced byResizefrom opset 10 onwards).The kernel takes the input tensor
Xand a 1-DFLOATscalestensor of lengthrank(X)and produces a tensor whose dimiisfloor(X.shape[i] * scales[i]). Themodeattribute selects the interpolation rule:"nearest"(default) — every output element is copied from the nearest input element usingfloor(out / scale)to map output coordinates back to input coordinates. Supports any input rank."linear"/"bilinear"— supported only for 4-D NCHW input, with scales equal to1on theNandCaxes. The two spatial axes are upsampled with the “asymmetric” coordinate transformation used by Upsample v7/9/10 in upstream ONNX.
The reference implementation supports the same whole-byte element types as :cpp:func:
ElementSizefor"nearest"mode;"linear"mode requires a floating-point input (FLOAT16/FLOAT/DOUBLE).Public Functions
-
Tensor operator()(const Tensor &X, const Tensor &scales, const Attributes &attrs) const#
-
void operator()(const Tensor &X, const Tensor &scales, const Attributes &attrs, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output shape generally differs from input shape, so storage cannot be shared with the input buffer.
-
struct Attributes#
- #include <include_tensor_kernels.h>
Attributes carried by the ONNX
Upsampleoperator.
-
class AffineGrid : public onnx_light::onnx_kernels::kernel::KernelBase#
-
namespace kernel
-
namespace onnx_kernels