Tensor

class tract.tensor.DatumType(*values)[source]
class tract.tensor.Tensor(ptr)[source]

A multidimensional array of typed data, the fundamental data carrier in tract.

Tensors flow in and out of models: they are the inputs you feed to Runnable.run() and the outputs you get back. On the Python side, convert to and from numpy arrays with to_numpy() and from_numpy().

from_numpy() → Tensor[source]

Builds a tensor from a numpy array, preserving its rank.

numpy.ascontiguousarray promotes 0-d arrays to rank 1, so the original rank is restored afterwards: a scalar input must stay a scalar to match a rank-0 fact.

to_numpy() → array[source]

Builds a numpy array equivalent to the data in this tensor.

into_numpy() → array[source]

Same as to_numpy(), but drop the tensor content once the numpy array is built.