shape_traditionalml.h#
Shape-inference functions for ONNX operators in the ai.onnx.ml (traditional machine-learning) family.
-
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_optim
-
namespace shapes
-
namespace traditionalml#
Functions
-
void ComputeShapeBinarizer(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aBinarizernode and stores it inctx.Binarizer(ai.onnx.ml) is an element-wise operator: the output tensor has the exact same shape and element type as the input — only the values change (each element becomes1if it is strictly greater than thethresholdattribute,0otherwise).- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
BinarizerNodeProtowhose output should be described.node.op_type()must be"Binarizer"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeCategoryMapper(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aCategoryMappernode and stores it inctx.CategoryMapper(ai.onnx.ml) is a one-to-one mapping between strings and integers: the output tensor has the exact same shape as the input, while its element type is determined by the input element type (STRINGinput →INT64output;INT64input →STRINGoutput).- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
CategoryMapperNodeProtowhose output should be described.node.op_type()must be"CategoryMapper"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeCastMap(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aCastMapnode and stores it inctx.CastMap(ai.onnx.ml) converts a map into a 1-D tensor. The output element type is determined by thecast_toattribute ("TO_FLOAT"→FLOAT,"TO_INT64"→INT64,"TO_STRING"→STRING; the default is"TO_FLOAT"). The output shape is[max_map]whenmap_form == "SPARSE"and a 1-D tensor of unknown length otherwise ("DENSE", the default).- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
CastMapNodeProtowhose output should be described.node.op_type()must be"CastMap"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeImputer(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof anImputernode and stores it inctx.Imputer(ai.onnx.ml) is an element-wise operator: the output tensor has the exact same shape and element type as the input — only the values change (elements matchingreplaced_value_floatorreplaced_value_int64are replaced by the corresponding imputed values).- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
ImputerNodeProtowhose output should be described.node.op_type()must be"Imputer"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeArrayFeatureExtractor(ShapesContext &ctx, const NodeProto &node, const char *x, const char *y)#
Computes the output :cpp:class:
OptimTensorof anArrayFeatureExtractornode and stores it inctx.ArrayFeatureExtractorselects values from the last axis ofxusing indices fromy:output dtype always matches
x;all leading dimensions of
xare preserved;the last output dimension equals the flattened element count of
y(product ofy’s dimensions) when that value can be inferred fromy’s shape.
- Parameters:
ctx – In/out context. Must already contain entries for
xandy; on return it also contains an entry fornode.output(0).node – The
ArrayFeatureExtractorNodeProtowhose output should be described.node.op_type()must be"ArrayFeatureExtractor"andnodemust declare at least one output.x – Name of the data input tensor.
y – Name of the indices input tensor.
- Throws:
-
void ComputeShapeLabelEncoder(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aLabelEncodernode and stores it inctx.LabelEncoder(ai.onnx.ml) is a one-to-one mapping from input keys to output values, so the output shape always matches the input shape. The output dtype is determined by which of thevalues_*attributes is set:values_tensor— dtype is the tensor’sdata_type;values_strings— dtype isstring;values_int64s— dtype isint64;values_floats— dtype isfloat.
Exactly one of these attributes must be set; an error is raised otherwise.
- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
LabelEncoderNodeProtowhose output should be described.node.op_type()must be"LabelEncoder"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeOneHotEncoder(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aOneHotEncodernode and stores it inctx.OneHotEncoder(ai.onnx.ml) emits a one-hot encoding of the input: the output is afloattensor whose shape equals the input shape extended by a trailing dimension of sizelen(cats_*). Exactly one ofcats_int64sorcats_stringsmust be set on the node.- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
OneHotEncoderNodeProtowhose output should be described.node.op_type()must be"OneHotEncoder"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeLinearClassifier(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorobjects of aLinearClassifiernode and stores them inctx.LinearClassifier(ai.onnx.ml) consumes either a single feature vector[C]or a batch[N,C]and emits:Y: predicted labels (stringwhenclasslabels_stringsis provided,int64otherwise), shape[N](or[1]for rank-1 input);Z: classification scores, shape[N,E]whereEis the number of classes inferred from theintercepts/classlabels_*attributes (binary classifiers with a single intercept and two labels exposeE == 2).
- Parameters:
ctx – In/out context with input
xalready present.node –
LinearClassifiernode.x – Name of the input value to read from
ctx.
-
void ComputeShapeLinearRegressor(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aLinearRegressornode and stores it inctx.LinearRegressor(ai.onnx.ml) consumes either[C]or[N,C]and emits a float tensor of regression scores with shape[N, targets]wheretargetsis taken from the operator’stargetsattribute (default 1).- Parameters:
ctx – In/out context with input
xalready present.node –
LinearRegressornode.x – Name of the input value to read from
ctx.
-
void ComputeShapeScaler(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aScalernode and stores it inctx.Scaler(ai.onnx.ml) is an element-wise operator: the output tensor has the same shape as the input but its element type is alwaysfloat(per the ONNX schema,Yistensor(float)regardless of the input element type).- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
ScalerNodeProtowhose output should be described.node.op_type()must be"Scaler"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeNormalizer(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aNormalizernode and stores it inctx.Normalizer(ai.onnx.ml) normalizes its input along the last (feature) axis. The output tensor has the same shape as the input but its element type is alwaysfloat(per the ONNX schema,Yistensor(float)regardless of the input element type).- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
NormalizerNodeProtowhose output should be described.node.op_type()must be"Normalizer"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeSVMClassifier(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorobjects of anSVMClassifiernode and stores them inctx.SVMClassifier(ai.onnx.ml) consumes either a single feature vector[C]or a batch[N,C]and emits:Y: predicted labels (stringwhenclasslabels_stringsis provided,int64otherwise), shape[N](or[1]for rank-1 input);Z: class scores/probabilities, shape[N,S]whereSis inferred from class labels when available.
- Parameters:
ctx – In/out context with input
xalready present.node –
SVMClassifiernode.x – Name of the input value to read from
ctx.
-
void ComputeShapeSVMRegressor(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof anSVMRegressornode and stores it inctx.SVMRegressor(ai.onnx.ml) consumes either[C]or[N,C]and emits a float tensor of regression scores with shape[N,1](or[1,1]for rank-1 input).- Parameters:
ctx – In/out context with input
xalready present.node –
SVMRegressornode.x – Name of the input value to read from
ctx.
-
void ComputeShapeTreeEnsembleRegressor(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aTreeEnsembleRegressornode and stores it inctx.TreeEnsembleRegressor(ai.onnx.ml) consumes either[C]or[N,C]and emits a float tensor of regression scores with shape[N, n_targets], wheren_targetsis taken from the operator’sn_targetsattribute (default 1).- Parameters:
ctx – In/out context with input
xalready present.node –
TreeEnsembleRegressornode.x – Name of the input value to read from
ctx.
-
void ComputeShapeTreeEnsembleClassifier(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorobjects of aTreeEnsembleClassifiernode and stores them inctx.TreeEnsembleClassifier(ai.onnx.ml) consumes either[C]or[N,C]and emits:Y: predicted labels (stringwhenclasslabels_stringsis provided,int64otherwise), shape[N](or[1]for rank-1 input);Z: classification scores, shape[N,E]whereEis the number of classes from theclasslabels_*attribute.
- Parameters:
ctx – In/out context with input
xalready present.node –
TreeEnsembleClassifiernode.x – Name of the input value to read from
ctx.
-
void ComputeShapeTreeEnsemble(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aTreeEnsemblenode and stores it inctx.TreeEnsemble(ai.onnx.ml, opset 5) consumes[N, F]and emits a tensor of shape[N, n_targets]with the same element type as the input, wheren_targetsis taken from then_targetsattribute (default 1).- Parameters:
ctx – In/out context with input
xalready present.node –
TreeEnsemblenode.x – Name of the input value to read from
ctx.
-
void ComputeShapeZipMap(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aZipMapnode and stores it inctx.ZipMap(ai.onnx.ml) converts each row of the float input tensor into a map keyed by eitherclasslabels_stringsorclasslabels_int64s. The output dtype is therefore inferred as eitherseq(map(string, float))orseq(map(int64, float)).- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
ZipMapNodeProtowhose output should be described.node.op_type()must be"ZipMap"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeDictVectorizer(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aDictVectorizernode and stores it inctx.DictVectorizer(ai.onnx.ml) converts a dictionary input into a 1-D tensor whose length matches the vocabulary attribute length. Exactly one ofstring_vocabularyorint64_vocabularymust be set on the node. The output element type is inferred from the value type of the input map (or from a non-emptyT2ValueInfoProtoannotation whenxis not a tensor); when neither is available, the output dtype is left undefined and only the shape[C]is propagated.- Parameters:
ctx – In/out context. May contain an entry for
x(a map); on return it contains an entry fornode.output(0).node – The
DictVectorizerNodeProtowhose output should be described.node.op_type()must be"DictVectorizer".x – Name of the input value (a map).
-
void ComputeShapeFeatureVectorizer(ShapesContext &ctx, const NodeProto &node, const std::vector<std::string> &inputs)#
Computes the output :cpp:class:
OptimTensorof aFeatureVectorizernode and stores it inctx.FeatureVectorizer(ai.onnx.ml) concatenates a variadic list of tensors along the trailing feature dimension; the output is always afloattensor of shape[N, sum(inputdimensions)]whereNis the common batch size of the inputs. When theinputdimensionsattribute is absent the per-input feature widths are taken from each input’s last dimension; if any feature width or the batch size is unknown, the corresponding output dimension is left symbolic.- Parameters:
ctx – In/out context.
node – The
FeatureVectorizerNodeProto.inputs – Names of the variadic input values, in declaration order.
Variables
-
constexpr const char *kOnnxMlDomain = "ai.onnx.ml"#
Canonical domain string for the
ai.onnx.mloperator set.
-
void ComputeShapeBinarizer(ShapesContext &ctx, const NodeProto &node, const char *x)#
-
namespace traditionalml#
-
namespace shapes
-
namespace onnx_optim