shape_math.h#

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

namespace ONNX_LIGHT_NAMESPACE
namespace onnx_optim
namespace shapes#
namespace math#

Functions

void ComputeShapeAbs(ShapesContext &ctx, const NodeProto &node, const char *x)#

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

Abs is element-wise and unary in every revision of its schema (v1, v6, v13 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.

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

  • node – The Abs NodeProto whose output should be described. node.op_type() must be "Abs" and node must declare at least one output.

  • x – Name of the input value to read from ctx. Must be present in ctx.

Throws:
  • std::invalid_argument – if node.op_type() is not "Abs" or if node has no output.

  • std::out_of_range – if x is not present in ctx.

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

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

Add is element-wise and binary, with numpy-style multidirectional broadcasting between its two operands (since opset 7; earlier revisions had an explicit broadcast attribute but the shape propagation rules are identical when broadcasting is enabled, which onnx-light assumes). The output dtype matches the input dtype (both operands share the same type via the T type constraint) 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 Add NodeProto whose output should be described. node.op_type() must be "Add" 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 "Add", 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.