module onnxrt.shape_object
#
Short summary#
module mlprodict.onnxrt.shape_object
Shape object.
Classes#
class |
truncated documentation |
---|---|
Base class to |
|
One dimension of a shape. |
|
Base class for shape binary operator defined by a function. |
|
Base class for shape binary operator. |
|
Handles mathematical operations around shapes. It stores a type (numpy type), and a name to somehow have … |
|
Computes a shape depending on a user defined function. See |
|
Base class for all shapes operator. |
|
Shape addition. |
|
Shape comparison. |
|
Best on each dimension. |
|
Shape multiplication. |
Properties#
property |
truncated documentation |
---|---|
Returns the dimension. |
|
Returns the stored dtype. |
|
|
Returns the stored dtype. |
Returns the stored shape. |
|
|
Returns the stored shape. |
Static Methods#
staticmethod |
truncated documentation |
---|---|
|
|
Returns obj if obj is |
|
Computes einsum shapes. Not the most efficient one as it creates variables of the given shapes. |
|
|
Computes einsum shapes. Not the most efficient one as it creates variables of the given shapes. |
Computes Gather shapes. |
|
|
Computes Gather shapes. |
Methods#
method |
truncated documentation |
---|---|
usual |
|
usual |
|
Tests equality between two shapes. |
|
|
Tests equality between two shapes. |
Extracts a specific dimension. |
|
|
Extracts a specific dimension. |
usual |
|
Compares shapes. Operator |
|
|
Compares shapes. Operator |
|
|
Iterators over dimensions. |
|
|
Iterators over dimensions. |
Returns the number of dimensions. |
|
|
Returns the number of dimensions. |
usual |
|
usual |
|
|
usual |
|
usual |
usual |
|
|
usual |
usual |
|
Displays a string. |
|
Displays a string. |
|
Displays a string. |
|
Displays a string. |
|
Changes a specific dimension. |
|
|
Changes a specific dimension. |
Evalutes the operator assuming some of them are still strings. |
|
Evalutes the operator assuming some of them are still strings. |
|
Evalutes the operator assuming some of them are still strings. |
|
|
Evalutes the operator assuming some of them are still strings. |
|
Evalutes the operator assuming some of them are still strings. |
|
Evalutes the operator assuming some of them are still strings. |
|
Evalutes the operator assuming some of them are still strings. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Appends a dimension. |
|
|
Appends a dimension. |
Computes the shape after a broadcast. |
|
|
Computes the shape after a broadcast. |
Concatenates columns from shapes to this one along one axis. |
|
|
Concatenates columns from shapes to this one along one axis. |
A copy not a deepcopy. |
|
|
A copy not a deepcopy. |
Drops an axis. |
|
|
Drops an axis. |
Evaluates the object, reduces the expression to a number or a string. |
|
Evalutes the dimension. |
|
|
Evalutes the operator. |
|
Evalutes the operator. |
Evaluates the shape. |
|
Evaluates the shape. |
|
Evalutes the operator. |
|
|
Evalutes the operator. |
|
Evalutes the operator. |
|
Evalutes the operator. |
|
Evalutes the operator. |
Inserts a dimension at position pos. |
|
|
Inserts a dimension at position pos. |
Multiplies all the dimension. |
|
|
Multiplies all the dimension. |
Reduces the matrix. Removes one dimension. |
|
|
Reduces the matrix. Removes one dimension. |
Creates a new shape, checks the number of elements is the same. |
|
|
Creates a new shape, checks the number of elements is the same. |
Removes one dimension. |
|
|
Removes one dimension. |
Converts the object into a string. |
|
Represents the dimension as a string. |
|
|
Applies binary operator to a dimension. |
Applies binary operator to a dimension. |
|
Converts shapes into a string. |
|
|
Converts shapes into a string. |
Displays as a string. |
|
|
Applies binary operator to a dimension. |
|
Applies binary operator to a dimension. |
|
Applies binary operator to a dimension. |
|
Applies binary operator to a dimension. |
Removes one dimension. |
|
|
Removes one dimension. |
Adds dimensions. |
|
|
Adds dimensions. |
Documentation#
Shape object.
- class mlprodict.onnxrt.shape_object.BaseDimensionShape#
Bases:
object
Base class to
DimensionObject
,ShapeOperator
,ShapeObject
.- evaluate(**kwargs)#
Evaluates the object, reduces the expression to a number or a string.
- to_string(use_x=True)#
Converts the object into a string.
- class mlprodict.onnxrt.shape_object.DimensionObject(obj)#
Bases:
BaseDimensionShape
One dimension of a shape.
- Parameters:
obj – int or
DimensionObject
or None to specify something unknown
- __add__(obj)#
usual
- __eq__(v)#
usual
- __gt__(obj)#
usual
- __hash__ = None#
- __init__(obj)#
- Parameters:
obj – int or
DimensionObject
or None to specify something unknown
- __mul__(obj)#
usual
- __repr__()#
usual
- static _same_(obj)#
Returns obj if obj is
DimensionObject
otherwise converts it.
- property dim#
Returns the dimension.
- evaluate(**kwargs)#
Evalutes the dimension.
- Parameters:
kwargs – value for the variables.
- Returns:
string or integer
- to_string(use_x=True)#
Represents the dimension as a string.
- class mlprodict.onnxrt.shape_object.ShapeBinaryFctOperator(name, fct, fct_string, x, y)#
Bases:
ShapeBinaryOperator
Base class for shape binary operator defined by a function.
- Parameters:
name – display name of the operator
fct – function doing the operator if argument are numeric
fct_string – function represented as a string
x – first argument
y – second argument
- _evaluate_string_(args, **kwargs)#
Evalutes the operator assuming some of them are still strings.
- Parameters:
args – arguments extracted by method evaluate
kwargs – value for the variables.
- Returns:
string or integer
- _to_string2(x, y)#
- _to_string2b(x, y)#
- _to_string3(x)#
- class mlprodict.onnxrt.shape_object.ShapeBinaryOperator(name, fct, fct_string, x, y)#
Bases:
ShapeOperator
Base class for shape binary operator.
- Parameters:
name – display name of the operator
fct – function doing the operator if argument are numeric
fct_string – function represented as a string
x – first argument
y – second argument
- __init__(name, fct, fct_string, x, y)#
- Parameters:
name – display name of the operator
fct – function doing the operator if argument are numeric
fct_string – function represented as a string
x – first argument
y – second argument
- _evaluate_string_(args, **kwargs)#
Evalutes the operator assuming some of them are still strings.
- Parameters:
args – arguments extracted by method evaluate
kwargs – value for the variables.
- Returns:
string or integer
- _to_string1(x, y)#
- _to_string2(x, y)#
- _to_string2b(x, y)#
- _to_string3(x)#
- to_string(use_x=True)#
Applies binary operator to a dimension.
- Parameters:
use_x – use ‘x’ if dimension is unknown
- Returns:
a string
- class mlprodict.onnxrt.shape_object.ShapeObject(shape, dtype=None, use_n1=False, name=None, subtype=None)#
Bases:
BaseDimensionShape
Handles mathematical operations around shapes. It stores a type (numpy type), and a name to somehow have an idea of where the shape comes from in the ONNX graph. The shape itself is defined by a list of
DimensionObject
orShapeOperator
or None if the shape is unknown. A dimension is an integer or a variable encoded as a string. This variable is a way to tell the dimension may vary.<<<
import numpy from mlprodict.onnxrt.shape_object import ShapeObject sh1 = ShapeObject((1, 2), dtype=numpy.float32) sh2 = ShapeObject((45, 2), dtype=numpy.float32) mx = max(sh1, sh2) print(mx) sh1 = ShapeObject((1, 2), dtype=numpy.float32) sh2 = ShapeObject((None, 2), dtype=numpy.float32) print(sh2) mx = max(sh1, sh2) print(mx.to_string()) sh1 = ShapeObject((1, 2), dtype=numpy.float32) sh2 = ShapeObject(('n', 2), dtype=numpy.float32) print(sh2) mx = max(sh1, sh2) print(mx.evaluate(n=4))
>>>
ShapeObject((45, 2), dtype=numpy.float32) ShapeObject((DimensionObject('None'), 2), dtype=numpy.float32) (?, 2) ShapeObject((n, 2), dtype=numpy.float32) ShapeObject((4, 2), dtype=numpy.float32, name='None-EV')
- Parameters:
shape – tuple or numpy.array
dtype – dtype
use_n1 – use ‘n’ if the first dimension is unknown
name – optional, for debugging purposes
subtype – element type if this type is a list
- __eq__(a)#
Tests equality between two shapes.
- __getitem__(index)#
Extracts a specific dimension.
- __gt__(a)#
Compares shapes. Operator
>
.
- __hash__ = None#
- __init__(shape, dtype=None, use_n1=False, name=None, subtype=None)#
- Parameters:
shape – tuple or numpy.array
dtype – dtype
use_n1 – use ‘n’ if the first dimension is unknown
name – optional, for debugging purposes
subtype – element type if this type is a list
- __iter__()#
Iterators over dimensions.
- __len__()#
Returns the number of dimensions.
- __repr__()#
usual
- __setitem__(index, value)#
Changes a specific dimension.
- static _infer_merged_type(*args, use_dtype=True)#
- append(dim)#
Appends a dimension.
- broadcast(a)#
Computes the shape after a broadcast.
- concat_columns(axis, *shapes)#
Concatenates columns from shapes to this one along one axis.
- copy(dtype=None, name=None)#
A copy not a deepcopy.
- Parameters:
dtype – None or a value to rewrite the type.
name – overwrites the name
- Returns:
- drop_axis(axis)#
Drops an axis.
- property dtype#
Returns the stored dtype.
- static einsum_shape(equation, *inputs)#
Computes einsum shapes. Not the most efficient one as it creates variables of the given shapes.
- evaluate(**kwargs)#
Evaluates the shape.
- static gather_shape(input, indices, axis)#
Computes Gather shapes.
- insert(dim, pos=0)#
Inserts a dimension at position pos.
- product()#
Multiplies all the dimension.
- Returns:
- reduce(axis=1, keepdims=False, dtype=None)#
Reduces the matrix. Removes one dimension.
- Parameters:
axis – axis
keepdims – keep dimensions, replaces the removed dimension by 1
dtype – if not None, changes the type
- Returns:
new dimension
- reshape(shape)#
Creates a new shape, checks the number of elements is the same.
- property shape#
Returns the stored shape.
- squeeze(axis)#
Removes one dimension.
- to_string(use_x=False)#
Converts shapes into a string.
- transpose(perm)#
Removes one dimension.
- unsqueeze(axes)#
Adds dimensions.
- class mlprodict.onnxrt.shape_object.ShapeObjectFct(fct, *shapes, dtype=None, name=None)#
Bases:
ShapeObject
Computes a shape depending on a user defined function. See
Conv
for an example.- Parameters:
fct – function
shapes – shapes sent to fct
dtype – dtype
name – optional, for debugging purposes
- __init__(fct, *shapes, dtype=None, name=None)#
- Parameters:
fct – function
shapes – shapes sent to fct
dtype – dtype
name – optional, for debugging purposes
- evaluate(**kwargs)#
Evaluates the shape.
- class mlprodict.onnxrt.shape_object.ShapeOperator(name, fct, fct_string, *args)#
Bases:
BaseDimensionShape
Base class for all shapes operator.
- Parameters:
name – display name of the operator
fct – function doing the operator if argument are numeric
fct_string – function represented as a string
args – argument of the operator
- __init__(name, fct, fct_string, *args)#
- Parameters:
name – display name of the operator
fct – function doing the operator if argument are numeric
fct_string – function represented as a string
args – argument of the operator
- __repr__()#
usual
- _evaluate_string_(args, **kwargs)#
Evalutes the operator assuming some of them are still strings.
- Parameters:
args – arguments extracted by method evaluate
kwargs – value for the variables.
- Returns:
string or integer
- evaluate(**kwargs)#
Evalutes the operator.
- Parameters:
kwargs – value for the variables.
- Returns:
string or integer
- to_string(use_x=True)#
Displays as a string.
- Returns:
a string
- class mlprodict.onnxrt.shape_object.ShapeOperatorAdd(x, y)#
Bases:
ShapeBinaryOperator
Shape addition.
- Parameters:
name – display name of the operator
fct – function doing the operator if argument are numeric
fct_string – function represented as a string
x – first argument
y – second argument
- __init__(x, y)#
- Parameters:
name – display name of the operator
fct – function doing the operator if argument are numeric
fct_string – function represented as a string
x – first argument
y – second argument
- __repr__()#
Displays a string.
- Returns:
a string
- class mlprodict.onnxrt.shape_object.ShapeOperatorGreater(x, y)#
Bases:
ShapeBinaryOperator
Shape comparison.
- Parameters:
name – display name of the operator
fct – function doing the operator if argument are numeric
fct_string – function represented as a string
x – first argument
y – second argument
- __init__(x, y)#
- Parameters:
name – display name of the operator
fct – function doing the operator if argument are numeric
fct_string – function represented as a string
x – first argument
y – second argument
- __repr__()#
Displays a string.
- Returns:
a string
- class mlprodict.onnxrt.shape_object.ShapeOperatorMax(x, y)#
Bases:
ShapeBinaryFctOperator
Best on each dimension.
- Parameters:
name – display name of the operator
fct – function doing the operator if argument are numeric
fct_string – function represented as a string
x – first argument
y – second argument
- __init__(x, y)#
- Parameters:
name – display name of the operator
fct – function doing the operator if argument are numeric
fct_string – function represented as a string
x – first argument
y – second argument
- __repr__()#
Displays a string.
- Returns:
a string
- class mlprodict.onnxrt.shape_object.ShapeOperatorMul(x, y)#
Bases:
ShapeBinaryOperator
Shape multiplication.
- Parameters:
name – display name of the operator
fct – function doing the operator if argument are numeric
fct_string – function represented as a string
x – first argument
y – second argument
- __init__(x, y)#
- Parameters:
name – display name of the operator
fct – function doing the operator if argument are numeric
fct_string – function represented as a string
x – first argument
y – second argument
- __repr__()#
Displays a string.
- Returns:
a string