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__(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.
__copyinit__
β
__copyinit__(inout self: Self, existing: Self)
Copy contructor for TensorMap.
Args:
- βexisting (
Self
): Instance of TensorMap to copy from.
__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[type: DType](self: Self, key: String, spec: TensorSpec, ptr: UnsafePointer[SIMD[type, 1], 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 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], 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1]
): The tensor pointer.
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[$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: Self, key: String) -> Buffer[$0, -31337, 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: 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: 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: Self) -> List[String, 0]
Returns all held keys.
Returns:
A list with all contained keys.
__len__
β
__len__(self: Self) -> Int
Gets number of elements in the map.
Returns:
Number of elements the map contains.
__str__
β
__str__(self: 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!
If you'd like to share more information, please report an issue on GitHub
π What went wrong?