shape_logical.h#

Shape-inference functions for ONNX operators in the logical family.

namespace ONNX_LIGHT_NAMESPACE
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:OptimTensor of an And node and stores it in ctx.

And is the logical, element-wise AND of two boolean operands with numpy-style multidirectional broadcasting (since opset 7; earlier revisions used an explicit broadcast attribute but the shape propagation rules are identical when broadcasting is enabled, which onnx-light assumes). The output dtype is always :cpp:enumerator:TensorType::kBool and the output shape is the broadcast of the two input shapes.

Parameters:
  • ctx – In/out context. Must already contain entries for both a and b; on return it also contains an entry for node.output(0).

  • node – The And NodeProto whose output should be described. node.op_type() must be "And" and node must 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:
  • std::invalid_argument – if node.op_type() is not "And", if node has no output, or if the two input shapes are not broadcast-compatible.

  • std::out_of_range – if either a or b is missing from ctx.

void ComputeShapeOr(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#

Computes the output :cpp:class:OptimTensor of an Or node and stores it in ctx.

Or is 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::kBool and the output shape is the broadcast of the two input shapes.

Parameters:
  • ctx – In/out context. Must already contain entries for both a and b; on return it also contains an entry for node.output(0).

  • node – The Or NodeProto whose output should be described. node.op_type() must be "Or" and node must 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:
  • std::invalid_argument – if node.op_type() is not "Or", if node has no output, or if the two input shapes are not broadcast-compatible.

  • std::out_of_range – if either a or b is missing from ctx.

void ComputeShapeXor(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#

Computes the output :cpp:class:OptimTensor of a Xor node and stores it in ctx.

Xor is 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::kBool and the output shape is the broadcast of the two input shapes.

Parameters:
  • ctx – In/out context. Must already contain entries for both a and b; on return it also contains an entry for node.output(0).

  • node – The Xor NodeProto whose output should be described. node.op_type() must be "Xor" and node must 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:
  • std::invalid_argument – if node.op_type() is not "Xor", if node has no output, or if the two input shapes are not broadcast-compatible.

  • std::out_of_range – if either a or b is missing from ctx.

void ComputeShapeGreater(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#

Computes the output :cpp:class:OptimTensor of a Greater node and stores it in ctx.

Greater is the element-wise A > B comparison of two numeric operands with numpy-style multidirectional broadcasting (since opset 7; opset 1 only supported broadcasting via an explicit broadcast attribute but the shape propagation rules are identical when broadcasting is enabled, which onnx-light assumes). The output dtype is always :cpp:enumerator:TensorType::kBool and the output shape is the broadcast of the two input shapes.

Parameters:
  • ctx – In/out context. Must already contain entries for both a and b; on return it also contains an entry for node.output(0).

  • node – The Greater NodeProto whose output should be described. node.op_type() must be "Greater" and node must 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:
  • std::invalid_argument – if node.op_type() is not "Greater", if node has no output, or if the two input shapes are not broadcast-compatible.

  • std::out_of_range – if either a or b is missing from ctx.

void ComputeShapeLess(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#

Computes the output :cpp:class:OptimTensor of a Less node and stores it in ctx.

Less is the element-wise A < B comparison of two numeric operands with numpy-style multidirectional broadcasting (since opset 7; opset 1 only supported broadcasting via an explicit broadcast attribute but the shape propagation rules are identical when broadcasting is enabled, which onnx-light assumes). The output dtype is always :cpp:enumerator:TensorType::kBool and the output shape is the broadcast of the two input shapes.

Parameters:
  • ctx – In/out context. Must already contain entries for both a and b; on return it also contains an entry for node.output(0).

  • node – The Less NodeProto whose output should be described. node.op_type() must be "Less" and node must 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:
  • std::invalid_argument – if node.op_type() is not "Less", if node has no output, or if the two input shapes are not broadcast-compatible.

  • std::out_of_range – if either a or b is missing from ctx.