shape_logical.h#
Shape-inference functions for ONNX operators in the logical 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 logical#
Functions
-
void ComputeShapeAnd(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof anAndnode and stores it inctx.Andis the logical, element-wise AND of two boolean operands with numpy-style multidirectional broadcasting (since opset 7; earlier revisions used an explicitbroadcastattribute but the shape propagation rules are identical when broadcasting is enabled, which onnx-light assumes). The output dtype is always :cpp:enumerator:TensorType::kBooland the output shape is the broadcast of the two input shapes.- Parameters:
ctx – In/out context. Must already contain entries for both
aandb; on return it also contains an entry fornode.output(0).node – The
AndNodeProtowhose output should be described.node.op_type()must be"And"andnodemust declare at least one output.a – Name of the first input value to read from
ctx.b – Name of the second input value to read from
ctx.
- Throws:
-
void ComputeShapeOr(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof anOrnode and stores it inctx.Oris the logical, element-wise OR of two boolean operands with numpy-style multidirectional broadcasting (since opset 7). The output dtype is always :cpp:enumerator:TensorType::kBooland the output shape is the broadcast of the two input shapes.- Parameters:
ctx – In/out context. Must already contain entries for both
aandb; on return it also contains an entry fornode.output(0).node – The
OrNodeProtowhose output should be described.node.op_type()must be"Or"andnodemust declare at least one output.a – Name of the first input value to read from
ctx.b – Name of the second input value to read from
ctx.
- Throws:
-
void ComputeShapeXor(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof aXornode and stores it inctx.Xoris the logical, element-wise XOR of two boolean operands with numpy-style multidirectional broadcasting (since opset 7). The output dtype is always :cpp:enumerator:TensorType::kBooland the output shape is the broadcast of the two input shapes.- Parameters:
ctx – In/out context. Must already contain entries for both
aandb; on return it also contains an entry fornode.output(0).node – The
XorNodeProtowhose output should be described.node.op_type()must be"Xor"andnodemust declare at least one output.a – Name of the first input value to read from
ctx.b – Name of the second input value to read from
ctx.
- Throws:
-
void ComputeShapeGreater(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof aGreaternode and stores it inctx.Greateris the element-wiseA > Bcomparison of two numeric operands with numpy-style multidirectional broadcasting (since opset 7; opset 1 only supported broadcasting via an explicitbroadcastattribute but the shape propagation rules are identical when broadcasting is enabled, which onnx-light assumes). The output dtype is always :cpp:enumerator:TensorType::kBooland the output shape is the broadcast of the two input shapes.- Parameters:
ctx – In/out context. Must already contain entries for both
aandb; on return it also contains an entry fornode.output(0).node – The
GreaterNodeProtowhose output should be described.node.op_type()must be"Greater"andnodemust declare at least one output.a – Name of the first input value to read from
ctx.b – Name of the second input value to read from
ctx.
- Throws:
-
void ComputeShapeLess(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof aLessnode and stores it inctx.Lessis the element-wiseA < Bcomparison of two numeric operands with numpy-style multidirectional broadcasting (since opset 7; opset 1 only supported broadcasting via an explicitbroadcastattribute but the shape propagation rules are identical when broadcasting is enabled, which onnx-light assumes). The output dtype is always :cpp:enumerator:TensorType::kBooland the output shape is the broadcast of the two input shapes.- Parameters:
ctx – In/out context. Must already contain entries for both
aandb; on return it also contains an entry fornode.output(0).node – The
LessNodeProtowhose output should be described.node.op_type()must be"Less"andnodemust declare at least one output.a – Name of the first input value to read from
ctx.b – Name of the second input value to read from
ctx.
- Throws:
-
void ComputeShapeGreaterOrEqual(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof aGreaterOrEqualnode and stores it inctx.GreaterOrEqualis the element-wiseA >= Bcomparison of two numeric operands with numpy-style multidirectional broadcasting (since opset 12). The output dtype is always :cpp:enumerator:TensorType::kBooland the output shape is the broadcast of the two input shapes.- Parameters:
ctx – In/out context. Must already contain entries for both
aandb; on return it also contains an entry fornode.output(0).node – The
GreaterOrEqualNodeProtowhose output should be described.node.op_type()must be"GreaterOrEqual"andnodemust declare at least one output.a – Name of the first input value to read from
ctx.b – Name of the second input value to read from
ctx.
- Throws:
-
void ComputeShapeLessOrEqual(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof aLessOrEqualnode and stores it inctx.LessOrEqualis the element-wiseA <= Bcomparison of two numeric operands with numpy-style multidirectional broadcasting (since opset 12). The output dtype is always :cpp:enumerator:TensorType::kBooland the output shape is the broadcast of the two input shapes.- Parameters:
ctx – In/out context. Must already contain entries for both
aandb; on return it also contains an entry fornode.output(0).node – The
LessOrEqualNodeProtowhose output should be described.node.op_type()must be"LessOrEqual"andnodemust declare at least one output.a – Name of the first input value to read from
ctx.b – Name of the second input value to read from
ctx.
- Throws:
-
void ComputeShapeEqual(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof anEqualnode and stores it inctx.Equalis the element-wiseA == Bcomparison of two operands with numpy-style multidirectional broadcasting (since opset 7; opset 1 only supported broadcasting via an explicitbroadcastattribute but the shape propagation rules are identical when broadcasting is enabled, which onnx-light assumes). The output dtype is always :cpp:enumerator:TensorType::kBooland the output shape is the broadcast of the two input shapes.- Parameters:
ctx – In/out context. Must already contain entries for both
aandb; on return it also contains an entry fornode.output(0).node – The
EqualNodeProtowhose output should be described.node.op_type()must be"Equal"andnodemust declare at least one output.a – Name of the first input value to read from
ctx.b – Name of the second input value to read from
ctx.
- Throws:
-
void ComputeShapeWhere(ShapesContext &ctx, const NodeProto &node, const char *condition, const char *x, const char *y)#
Computes the output :cpp:class:
OptimTensorof aWherenode and stores it inctx.Wherereturns elements fromxorydepending oncondition. The output dtype is the dtype ofx/yand the output shape is the multidirectional broadcast ofcondition,xandy.
-
void ComputeShapeBitwiseAnd(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof aBitwiseAndnode (opset 18) and stores it inctx.BitwiseAndis element-wise with numpy-style multidirectional broadcasting; both inputs must share the same integer dtype and the output dtype equals that input dtype.- Parameters:
ctx – In/out context. Must already contain entries for both
aandb; on return it also contains an entry fornode.output(0).node – The
BitwiseAndNodeProtowhose output should be described.node.op_type()must be"BitwiseAnd"andnodemust declare at least one output.a – Name of the first input value to read from
ctx.b – Name of the second input value to read from
ctx.
- Throws:
-
void ComputeShapeBitwiseOr(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof aBitwiseOrnode (opset 18) and stores it inctx. Shape/type semantics match :cpp:func:ComputeShapeBitwiseAnd.
-
void ComputeShapeBitwiseXor(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof aBitwiseXornode (opset 18) and stores it inctx. Shape/type semantics match :cpp:func:ComputeShapeBitwiseAnd.
-
void ComputeShapeBitwiseNot(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aBitwiseNotnode (opset 18) and stores it inctx.BitwiseNotis element-wise and unary: the output dtype and shape match the input.- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
BitwiseNotNodeProtowhose output should be described.node.op_type()must be"BitwiseNot"andnodemust declare at least one output.x – Name of the input value to read from
ctx.
- Throws:
-
void ComputeShapeNot(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aNotnode (opset 1) and stores it inctx.Notis the element-wise logical NOT of a boolean tensor: the output dtype is always :cpp:enumerator:TensorType::kBool(matching the input) and the output shape matches the input shape.- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
NotNodeProtowhose output should be described.node.op_type()must be"Not"andnodemust declare at least one output.x – Name of the input value to read from
ctx.
- Throws:
-
void ComputeShapeIsNaN(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof anIsNaNnode and stores it inctx.IsNaNis element-wise on a floating-point tensor: the output dtype is always :cpp:enumerator:TensorType::kBooland the output shape matches the input shape.- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
IsNaNNodeProtowhose output should be described.node.op_type()must be"IsNaN"andnodemust declare at least one output.x – Name of the input value to read from
ctx.
- Throws:
-
void ComputeShapeIsInf(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof anIsInfnode and stores it inctx.IsInfis element-wise on a floating-point tensor: the output dtype is always :cpp:enumerator:TensorType::kBooland the output shape matches the input shape. Thedetect_positiveanddetect_negativeattributes do not affect the output type or shape and are therefore not inspected by this function.- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
IsInfNodeProtowhose output should be described.node.op_type()must be"IsInf"andnodemust declare at least one output.x – Name of the input value to read from
ctx.
- Throws:
-
void ComputeShapeBitShift(ShapesContext &ctx, const NodeProto &node, const char *x, const char *y)#
Computes the output :cpp:class:
OptimTensorof aBitShiftnode (opset 11) and stores it inctx.BitShiftis element-wise with numpy-style multidirectional broadcasting; both inputs must share the same unsigned-integer dtype and the output dtype equals that input dtype. The requireddirectionattribute does not affect the output type or shape and is therefore not inspected by this function.
-
void ComputeShapeAnd(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
-
namespace logical#
-
namespace shapes
-
namespace onnx_optim