Mojo struct
TensorSpec
A space efficient representation of a tensor shape and dtype. This struct implements value semantics and owns its underlying data.
Fieldsβ
- βshape (
TensorShape
): The underlying shape of the specification.
Implemented traitsβ
AnyType
,
CollectionElement
,
Copyable
,
EqualityComparable
,
Formattable
,
Movable
,
Stringable
Methodsβ
__init__
β
__init__(inout self: Self)
Default initializer for TensorShape.
__init__(inout self: Self, type: DType, *shapes: Int)
Initializes a Tensorspec from the dtype and shapes provided.
Args:
- βtype (
DType
): The dtype of the specification. - β*shapes (
Int
): The shapes to initialize the shape with.
__init__(inout self: Self, type: DType, shape: Tuple[element_types])
Initializes a Tensorspec from the dtype and shapes provided.
Args:
- βtype (
DType
): The dtype of the specification. - βshape (
Tuple[element_types]
): The shapes to initialize the shape with.
__init__(inout self: Self, type: DType, shapes: VariadicList[Int])
Initializes a Tensorspec from the dtype and shapes provided.
Args:
- βtype (
DType
): The dtype of the specification. - βshapes (
VariadicList[Int]
): The shapes to initialize the shape with.
__init__(inout self: Self, type: DType, shapes: List[Int, hint_trivial_type])
Initializes a Tensorspec from the dtype and shapes provided.
Args:
- βtype (
DType
): The dtype of the specification. - βshapes (
List[Int, hint_trivial_type]
): The shapes to initialize the shape with.
__init__(inout self: Self, type: DType, owned shape: TensorShape)
Initializes a Tensorspec from the dtype and shape provided.
Args:
- βtype (
DType
): The dtype of the specification. - βshape (
TensorShape
): The shapes to initialize the shape with.
__copyinit__
β
__copyinit__(inout self: Self, other: Self)
Creates a deep copy of an existing spec.
Args:
- βother (
Self
): The spec to copy.
__moveinit__
β
__moveinit__(inout self: Self, owned existing: Self)
Move initializer for the spec.
Args:
- βexisting (
Self
): The spec to move.
__getitem__
β
__getitem__(self: Self, index: Int) -> Int
Gets the dimension at the specified index.
Args:
- βindex (
Int
): The dimension index.
Returns:
The dimension at the specified index.
__eq__
β
__eq__(self: Self, other: Self) -> Bool
Returns True if the two values are the same and False otherwise.
Args:
- βother (
Self
): The other TensorSpec to compare against.
Returns:
True if the two specs are the same and False otherwise.
__ne__
β
__ne__(self: Self, other: Self) -> Bool
Returns True if the two values are not the same and False otherwise.
Args:
- βother (
Self
): The other TensorSpec to compare against.
Returns:
True if the two specs are the not the same and False otherwise.
rank
β
rank(self: Self) -> Int
Gets the rank of the spec.
Returns:
The rank of the spec.
dtype
β
dtype(self: Self) -> DType
Gets the DType of the spec.
Returns:
The DType of the spec.
num_elements
β
num_elements(self: Self) -> Int
Gets the total number of elements in the spec.
Returns:
The total number of elements in the spec.
bytecount
β
bytecount(self: Self) -> Int
Gets the total byte count.
Returns:
The total byte count.
__repr__
β
__repr__(self: Self) -> String
Returns the string representation of the spec.
Returns:
The string representation of the spec.
__str__
β
__str__(self: Self) -> String
Returns the string representation of the spec.
Returns:
The string representation of the spec.
format_to
β
format_to(self: Self, inout writer: Formatter)
Formats this TensorSpec to the provided formatter.
Args:
- βwriter (
Formatter
): The formatter to write to.
from_bytes
β
static from_bytes(data: UnsafePointer[SIMD[uint8, 1], 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1]) -> Self
Create a TensorSpec object from serialized bytes.
Args:
- βdata (
UnsafePointer[SIMD[uint8, 1], 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1]
): UnsafePointer to serialized bytes.
Returns:
Given bytes as TensorSpec.
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?