Skip to main content

tensor_map

Holds the input and output tensors for a model.

TensorMap

Maps inputs and outputs to their respective names and can be used to supply and receive data to Max Engine model.

Implemented traits:

AnyType, SizedRaising

Methods:

__init__

__init__(inout self: Self, ctx: CRuntimeContext, lib: DLHandle, owned session: InferenceSession)

Internal only. Use InferenceSession.new_tensor_map for external use.

Creates a new instance of tensor map.

Args:

  • ctx (CRuntimeContext): Context of API.
  • lib (DLHandle): Handle to library.
  • session (InferenceSession): Copy of InferenceSession from which this instance was created.

__init__(inout self: Self, ptr: CTensorMap, lib: DLHandle, owned session: InferenceSession)

Internal only. Use InferenceSession.new_tensor_map for external use.

Creates a new instance of tensor map.

Args:

  • ptr (CTensorMap): C API pointer of TensorMap.
  • lib (DLHandle): Handle to library.
  • session (InferenceSession): Copy of InferenceSession from which this instance was created.

__moveinit__

__moveinit__(inout self: Self, owned existing: Self)

Move contructor for TensorMap.

Args:

  • existing (Self): Instance of TensorMap to move from.

__del__

__del__(owned self: Self)

Destructor for the tensor map.

borrow

borrow[type: DType](self: Self, key: String, value: Tensor[type])

Borrow the given tensor into the map at the key location. User needs to make sure tensor is alive for the duration of map.

Parameters:

  • type (DType): DType of tensor being borrowed.

Args:

  • key (String): Name of tensor in map.
  • value (Tensor[type]): Tensor to be held in map.

borrow(self: Self, key: String, value: EngineTensorView)

Borrow the given tensor view into the map at the key location. User needs to make sure tensor backing the view is alive for the duration of map.

Args:

  • key (String): Name of tensor in map.
  • value (EngineTensorView): View of a tensor.

borrow(self: Self, key: String, value: EngineNumpyView)

Borrow the given numpy view into the map at the key location. User needs to make sure numpy array backing the view is alive for the duration of map.

Args:

  • key (String): Name of numpy array in map.
  • value (EngineNumpyView): View of a numpy array.

borrow(self: Self, key: String, value: Value)

Borrow the given value into the map at the key location.

User needs to make sure value is alive for the duration of the map.

Args:

  • key (String): Name of value in map.
  • value (Value): Value to insert into map.

get

get[type: DType](self: Self, key: String) -> Tensor[type]

Gets the tensor / numpy array indicated by the key. The value is copied and returned to the user.

Parameters:

  • type (DType): DType of tensor to be returned.

Args:

  • key (String): Name of tensor / numpy array in the map.

Returns:

A copy of tensor help by the map.

buffer

buffer[type: DType](self: Self, key: String) -> Buffer[type, Dim(), 0]

Gets a buffer to the tensor pointed by the key.

Parameters:

  • type (DType): DType of buffer to be returned.

Args:

  • key (String): Name in TensorMap.

Returns:

Buffer of the tensor pointed by the key.

get_value

get_value(self: Self, key: String) -> Value

Gets the value pointed by the key.

Args:

  • key (String): Name in TensorMap.

Returns:

Value pointed by the key.

__len__

__len__(self: Self) -> Int

Gets number of elements in the map.

Returns:

Number of elements the map contains.