Mojo struct
TensorMap
Maps inputs and outputs to their respective names and can be used to supply and receive data to MAX Engine model.
This is the data type returned by
Model.execute()
, and
you can also use this type for the inputs you pass in (although execute()
also supports other formats for the input).
Implemented traits
AnyType
,
CollectionElement
,
Copyable
,
Movable
,
SizedRaising
,
Stringable
Methods
__init__
__init__(out 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__(out 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.
__copyinit__
__copyinit__(out self, existing: Self)
Copy contructor for TensorMap.
Args:
- existing (
Self
): Instance of TensorMap to copy from.
__moveinit__
__moveinit__(out self, owned existing: Self)
Move contructor for TensorMap.
Args:
- existing (
Self
): Instance of TensorMap to move from.
__del__
__del__(owned self)
Destructor for the tensor map.
borrow
borrow[type: DType](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[type: DType](self, key: String, spec: TensorSpec, ptr: UnsafePointer[SIMD[type, 1]])
Borrow the given pointer into the map at the key location. User needs to make sure the backing array is alive for the duration of map.
Parameters:
- type (
DType
): DType of tensor being borrowed.
Args:
- key (
String
): Name of tensor in map. - spec (
TensorSpec
): The tensor spec. This is the standard libraryTensorSpec
. - ptr (
UnsafePointer[SIMD[type, 1]]
): The tensor pointer.
borrow(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, 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, 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, key: String) -> Tensor[$0]
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 the tensor held by the map.
buffer
buffer[type: DType](self, key: String) -> Buffer[$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_spec
get_spec(self, key: String) -> TensorSpec
Gets the spec of the tensor pointed by the key.
Args:
- key (
String
): Name in TensorMap.
Returns:
Buffer of the tensor pointed by the key, as a TensorSpec
.
get_value
get_value(self, key: String) -> Value
Gets the value pointed by the key.
Args:
- key (
String
): Name in TensorMap.
Returns:
Value
pointed by the key.
keys
keys(self) -> List[String]
Returns all held keys.
Returns:
A list with all contained keys.
__len__
__len__(self) -> Int
Gets number of elements in the map.
Returns:
Number of elements the map contains.
__str__
__str__(self) -> String
Returns a String
representation of this TensorMap
.
Returns:
A textual representation of this TensorMap
.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!