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.

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

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

Sub is element-wise and binary, with numpy-style multidirectional broadcasting between its two operands (since opset 7). 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 Sub NodeProto whose output should be described. node.op_type() must be "Sub" 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 "Sub", 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 ComputeShapeMul(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#

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

Mul is element-wise and binary, with numpy-style multidirectional broadcasting between its two operands (since opset 7). 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 Mul NodeProto whose output should be described. node.op_type() must be "Mul" 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 "Mul", 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 ComputeShapeDiv(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#

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

Div is element-wise and binary, with numpy-style multidirectional broadcasting between its two operands (since opset 7). 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 Div NodeProto whose output should be described. node.op_type() must be "Div" 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 "Div", 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 ComputeShapeAcos(ShapesContext &ctx, const NodeProto &node, const char *x)#

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

Acos is element-wise and unary in every revision of its schema (v7, v22 — 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 Acos NodeProto whose output should be described. node.op_type() must be "Acos" 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 "Acos" or if node has no output.

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

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

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

Acosh is element-wise and unary in every revision of its schema (v9, v22 — 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 Acosh NodeProto whose output should be described. node.op_type() must be "Acosh" 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 "Acosh" or if node has no output.

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