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!
😔 What went wrong?