Skip to main content

tensor

Implements functionalities useful for giving input to Max Engine model for execution.

NamedTensor

A named input tensor.

Fields:

  • name (String): Name of the tensor.

Implemented traits:

AnyType, Copyable, Movable

Methods:

__init__

__init__[dtype: DType](inout self: Self, owned name: String, owned tensor: Tensor[dtype])

Creates a NamedTensor owning the tensor with a reference count.

Parameters:

  • dtype (DType): Data type of the tensor to own.

Args:

  • name (String): Name of the tensor.
  • tensor (Tensor[dtype]): Tensor to take ownership of.

EngineTensorView

A non-owning register_passable view of a tensor that does runtime type checking.

CAUTION: Make sure the source tensor outlives the view.

Implemented traits:

AnyType, Copyable, Movable

Methods:

__init__

__init__[type: DType](inout tensor: Tensor[type]) -> Self

Creates a non-owning view of given Tensor.

Parameters:

  • type (DType): DType of the tensor.

Args:

  • tensor (Tensor[type]): Tensor backing the view.

Returns:

An instance of EngineTensorView of given tensor.

data

data[type: DType](self: Self) -> DTypePointer[type, 0]

Returns pointer to the start of tensor.

Raises: If the given type does not match the type of tensor.

Parameters:

  • type (DType): Expected type of tensor.

Returns:

DTypePointer of given type.

data(self: Self) -> DTypePointer[invalid, 0]

Returns type erased pointer to the start of tensor.

Returns:

DTypePointer of invalid type.

spec

spec(self: Self) -> TensorSpec

Returns the spec of tensor backing the view.

Returns:

Stdlib TensorSpec of the tensor.

EngineNumpyView

A register_passable view of a numpy array.

Keeps its own reference to the NumPy PythonObject, so there is no need to manually keep the Python object alive after construction.

Implemented traits:

AnyType, Copyable, Movable

Methods:

__init__

__init__(inout self: Self, tensor: PythonObject)

Creates a non-owning view of given numpy array.

Args:

  • tensor (PythonObject): Numpy Array backing the view.

data

data(self: Self) -> DTypePointer[invalid, 0]

Returns type erased pointer to the start of numpy array.

Returns:

DTypePointer of given type.

dtype

dtype(self: Self) -> DType

Get DataType of the array backing the view.

Returns:

DataType of the array backing the view.

spec

spec(self: Self) -> TensorSpec

Returns the spec of numpy array backing the view.

Returns:

Numpy array spec in format of Stdlib TensorSpec.