Mojo struct
TensorShape
A space efficient representation of a tensor shape. This struct implements value semantics and owns its underlying data.
Implemented traitsβ
AnyType
,
CollectionElement
,
Copyable
,
EqualityComparable
,
Formattable
,
Movable
,
Stringable
Methodsβ
__init__
β
__init__(inout self: Self)
Default initializer for TensorShape.
__init__(inout self: Self, shapes: Tuple[element_types])
Initializes a TensorShape from the values provided.
Args:
- βshapes (
Tuple[element_types]
): The shapes to initialize the shape with.
__init__(inout self: Self, *shapes: Int)
Initializes a TensorShape from the values provided.
Args:
- β*shapes (
Int
): The shapes to initialize the shape with.
__init__(inout self: Self, shapes: VariadicList[Int])
Initializes a TensorShape from the values provided.
Args:
- βshapes (
VariadicList[Int]
): The shapes to initialize the shape with.
__init__(inout self: Self, shapes: List[Int, hint_trivial_type])
Initializes a TensorShape from the list provided.
Args:
- βshapes (
List[Int, hint_trivial_type]
): The list to initialize the shape with.
__init__[rank: Int](inout self: Self, shapes: StaticIntTuple[rank])
Initializes a TensorShape from the values provided.
Parameters:
- βrank (
Int
): The rank.
Args:
- βshapes (
StaticIntTuple[rank]
): The shapes to initialize the shape with.
__copyinit__
β
__copyinit__(inout self: Self, other: Self)
Creates a deep copy of an existing shape.
Args:
- βother (
Self
): The shape to copy.
__moveinit__
β
__moveinit__(inout self: Self, owned existing: Self)
Move initializer for the shape.
Args:
- βexisting (
Self
): The shape to move.
__del__
β
__del__(owned self: Self)
Delete the shape and release any owned memory.
__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 TensorShape to compare against.
Returns:
True if the two shapes 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 TensorShape to compare against.
Returns:
True if the two shapes are the not the same and False otherwise.
rank
β
rank(self: Self) -> Int
Gets the rank of the shape.
Returns:
The rank of the shape.
num_elements
β
num_elements(self: Self) -> Int
Gets the total number of elements in the shape.
Returns:
The total number of elements in the shape.
__repr__
β
__repr__(self: Self) -> String
Returns the string representation of the shape.
Returns:
The string representation of the shape.
__str__
β
__str__(self: Self) -> String
Returns the string representation of the shape.
Returns:
The string representation of the shape.
format_to
β
format_to(self: Self, inout writer: Formatter)
Formats this TensorShape to the provided formatter.
Args:
- βwriter (
Formatter
): The formatter to write to.
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?