Facts and Dimensions

class tract.fact.InferenceFact(ptr)[source]

Tract inference fact, to be used with InferenceModel.

It can represent partial type and shape information of a Tensor during model analysis.

dump() str[source]

Return a human-readable representation of the fact.

class tract.fact.Fact(ptr)[source]

Tract-core fact, to be used with Model.

It always contains the full shape (sometimes using symbolic dimensions) and item type. In some situation it can also contain the constant value of the associated tensor.

datum_type() int[source]

Return the element type of the fact as a DatumType integer.

rank() int[source]

Return the number of dimensions (axes) of the tensor.

dim(axis: int) Dim[source]

Return the Dim for the given axis.

dump() str[source]

Return a human-readable representation of the fact.

dims()[source]

Return a list of Dim for all axes.

class tract.dim.Dim(ptr)[source]

A possibly symbolic dimension of a tensor.

Dimensions can be concrete integers or symbolic expressions (e.g. N, N+1). Use to_int64() to extract a concrete value, or eval() to substitute symbols.

dump() str[source]

Return a human-readable representation of the dimension.

eval(values: Dict[str, int]) Dim[source]

Substitute symbols by concrete values and return the resulting dimension.

to_int64() int[source]

Convert to a concrete integer. Raises if the dimension is symbolic.