.xshape.shape_builder

class experimental_experiment.xshape.shape_builder.ShapeBuilder[source]

API for a class computing shapes in an ONNX model.

compare_with_true_inputs(inputs: Dict[str, ndarray] | List[ndarray], outputs: Dict[str, ndarray] | List[ndarray], exc: bool = True) Dict[str, Tuple[Tuple[str, int, int], ...]][source]

Compares the shape of the outputs with what the output shapes would return.

Parameters:
  • inputs – inputs

  • outputs – outputs

  • exc – raises an exception when a discrepancy is met

Returns:

list of expression, expected value, computed value

get_attribute(node: NodeProto, att_name: str, exc: bool = True) AttributeProto | None[source]

Returns an attribute for a node.

get_attribute_with_default(node: NodeProto, name: str, default_value: Any) Any[source]

Returns an attribute or its default value if missing.

Parameters:
  • node – node

  • name – attribute name

  • default_value – default value

Returns:

value

get_attributes_with_default(node: NodeProto, **default_values) Dict[str, Any][source]

Returns int or float attributes. If missing, the default value is returned if it is not None.

Parameters:
  • node – node

  • default_values – default values

pretty_node(node: NodeProto | None, limit: int = 80, short: bool = True, shape: bool = False) str[source]

Pretty rendering for a node.

Parameters:
  • node – node to render

  • limit – to show type and shapes after the limit

  • short – do not display shape information on the left

  • shape – show shape information below

Returns:

string

update_shapes(model: ModelProto)[source]

Updates model shapes with the value stored inside this graph.