Mojo struct
EngineTensorSpec
struct EngineTensorSpec
Describes the input and output tensor specifications of a Model
.
Holds a description of the input/output tensor, given to or produced by
MAX Engine. This is similar to
TensorSpec
in the Mojo
standard library, but is specific to MAX Engine.
This is the data type returned from
Model.get_model_input_metadata()
and
Model.get_model_output_metadata()
.
Implemented traits
AnyType
,
CollectionElement
,
Copyable
,
Movable
,
Stringable
,
UnknownDestructibility
Methods
__init__
__init__(out self, ptr: CTensorSpec, lib: DLHandle, owned session: InferenceSession)
Construct EngineTensorSpec. Do not use this function directly. Use functions from InferenceSession to create EngineTensorSpec.
Args:
- ptr (
CTensorSpec
): C API pointer of TensorSpec. - lib (
DLHandle
): Handle to library. - session (
InferenceSession
): Copy of InferenceSession from which this instance was created.
__init__(out self, name: String, spec: TensorSpec, lib: DLHandle, owned session: InferenceSession)
Creates an instance of EngineTensorSpec. Do not use this function directly. Use functions from InferenceSession to create EngineTensorSpec.
Args:
- name (
String
): Name of tensor. - spec (
TensorSpec
): Descritpion of Tensor in stdlibTensorSpec
format. - lib (
DLHandle
): Handle to the library. - session (
InferenceSession
): Copy of InferenceSession from which this instance was created.
__init__(out self, name: String, shape: Optional[List[Optional[Int]]], dtype: DType, lib: DLHandle, owned session: InferenceSession)
Creates an instance of EngineTensorSpec. Do not use this function directly. Use functions from InferenceSession to create EngineTensorSpec. Note that this almost similar to another constructor. This accepts Int instead of Int64 shape types.
Args:
- name (
String
): Name of tensor. - shape (
Optional[List[Optional[Int]]]
): Shape of the tensor. - dtype (
DType
): DataType of the tensor. - lib (
DLHandle
): Handle to the library. - session (
InferenceSession
): Copy of InferenceSession from which this instance was created.
__init__(out self, name: String, shape: Optional[List[Optional[SIMD[int64, 1]]]], dtype: DType, lib: DLHandle, owned session: InferenceSession)
Creates an instance of EngineTensorSpec. Do not use this function directly. Use functions from InferenceSession to create EngineTensorSpec. Note that this almost similar to another constructor. This accepts Int64 instead of Int shape types.
Args:
- name (
String
): Name of tensor. - shape (
Optional[List[Optional[SIMD[int64, 1]]]]
): Shape of the tensor. - dtype (
DType
): DataType of the tensor. - lib (
DLHandle
): Handle to the library. - session (
InferenceSession
): Copy of InferenceSession from which this instance was created.
__copyinit__
__copyinit__(out self, other: Self)
Copy constructor for Tensor Spec.
Args:
- other (
Self
): Instance of TensorSpec to be copied.
__moveinit__
__moveinit__(out self, owned existing: Self)
Move constructor for Tensor Spec.
Args:
- existing (
Self
): Instance of TensorSpec to be moved.
__del__
__del__(owned self)
Destructor for EngineTensorSpec.
__getitem__
__getitem__(self, idx: Int) -> Optional[Int]
Get the dimension at the given index.
Args:
- idx (
Int
): Index to get the dimension.
Returns:
Dimension as integer if dimension is static, else None.
Raises:
Raise error if spec has no static rank.
rank
rank(self) -> Optional[Int]
Gets the rank of spec.
Returns:
Rank if rank is static, else None.
has_rank
has_rank(self) -> Bool
Check if the spec has static rank.
Returns:
True if spec has static rank, else False.
get_as_tensor_spec
get_as_tensor_spec(self) -> TensorSpec
Get the Mojo TensorSpec equivalent of Engine TensorSpec.
Raises Raise error if spec has dynamic rank.
Returns:
Spec in Mojo TensorSpec format.
get_name
get_name(self) -> String
Gets the name of tensor corresponding to spec.
Returns:
Name of the Tensor as String.
get_dtype
get_dtype(self) -> DType
Gets the DType of tensor corresponding to spec.
Returns:
DType of the Tensor.
get_shape
get_shape(self) -> Optional[List[Optional[Int]]]
Gets the shape of tensor corresponding to spec.
Returns:
Shape of the Tensor. Returns None if rank is dynamic.
__str__
__str__(self) -> String
Gets the String representation of Spec.
Returns:
Spec as string. This will be of format {name=<spec name>, spec=[None|shape]xdtype}
.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!