Mojo struct
AnyTensor
A type erased tensor representation that is useful for situations where we need variadics of tensors.
Implemented traitsβ
AnyType
,
CollectionElement
,
Copyable
,
Formattable
,
Movable
Methodsβ
__init__
β
__init__(inout self: Self)
Default constructor for AnyTensor.
__init__(inout self: Self, owned device_tensor: DeviceTensor)
Creates AnyTensor from a DeviceTensor.
Args:
- βdevice_tensor (
DeviceTensor
): DeviceTensor to construct AnyTensor from.
__init__[type: DType, rank: Int](inout self: Self, owned tensor: Tensor[type, rank])
Creates AnyTensor from a Tensor.
Args:
- βtensor (
Tensor[type, rank]
): Tensor to construct AnyTensor from.
__moveinit__
β
__moveinit__(inout self: Self, owned existing: Self)
Move constructor for AnyTensor.
Args:
- βexisting (
Self
): Instance to move from.
__del__
β
__del__(owned self: Self)
Destructor for AnyTensor.
get_rank
β
get_rank(self: Self) -> Int
Gets rank of the tensor.
Returns:
Rank of the tensor.
spec
β
spec(self: Self) -> TensorSpec
Gets the spec of the tensor.
Returns:
Spec of the tensor.
to_device_tensor
β
to_device_tensor(owned self: Self) -> DeviceTensor
Consumes this AnyTensor and converts it into a device tensor.
Returns:
DeviceTensor representation of AnyTensor.
to_tensor
β
to_tensor[type: DType, rank: Int](owned self: Self) -> Tensor[$0, $1]
Consumes this anytensor and convert it into a tensor.
Parameters:
- βtype (
DType
): Type of tensor. - βrank (
Int
): Rank of tensor.
Returns:
Tensor representation of AnyTensor.
take
β
take(inout self: Self) -> Self
The returned value takes self's resources and replaces them with default initialized values.
Returns:
Newly constructed anytensor that takes storage from this.
__str__
β
__str__(self: Self) -> String
Gets the tensor as a string.
Returns:
A compact string of the tensor.
format_to
β
format_to(self: Self, inout writer: Formatter)
Formats this Tensor 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?