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
,
Movable
,
Stringable
,
Writable
Methods
__init__
__init__(out self)
Default initializer for TensorShape.
__init__(out 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__(out 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__(out 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__(out 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__(out 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.
__getitem__
__getitem__(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, 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, 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) -> Int
Gets the rank of the spec.
Returns:
The rank of the spec.
dtype
dtype(self) -> DType
Gets the DType of the spec.
Returns:
The DType of the spec.
num_elements
num_elements(self) -> Int
Gets the total number of elements in the spec.
Returns:
The total number of elements in the spec.
bytecount
bytecount(self) -> Int
Gets the total byte count.
Returns:
The total byte count.
__repr__
__repr__(self) -> String
Returns the string representation of the spec.
Returns:
The string representation of the spec.
__str__
__str__(self) -> String
Returns the string representation of the spec.
Returns:
The string representation of the spec.
write_to
write_to[W: Writer](self, inout writer: W)
Formats this TensorSpec to the provided Writer.
Parameters:
- W (
Writer
): A type conforming to the Writable trait.
Args:
- writer (
W
): The object to write to.
from_bytes
static from_bytes(data: UnsafePointer[SIMD[uint8, 1]]) -> Self
Create a TensorSpec object from serialized bytes.
Args:
- data (
UnsafePointer[SIMD[uint8, 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!