Mojo struct
AnyMemory
A generic representation which can either be a Driver Tensor or Mojo object.
Implemented traitsβ
AnyType
,
CollectionElement
,
Copyable
,
Formattable
,
Movable
Methodsβ
__init__
β
__init__(inout self: Self)
Default constructor for AnyMemory.
__init__(inout self: Self, owned device_tensor: DeviceTensor)
Creates AnyMemory from a DeviceTensor.
Args:
- βdevice_tensor (
DeviceTensor
): DeviceTensor to construct AnyMemory from.
__init__[type: DType, rank: Int](inout self: Self, owned tensor: Tensor[type, rank])
Creates AnyMemory from a Tensor.
Args:
- βtensor (
Tensor[type, rank]
): Tensor to construct AnyMemory from.
__init__(inout self: Self, owned tensor: AnyTensor)
Creates AnyMemory from a AnyTensor.
Args:
- βtensor (
AnyTensor
): AnyTensor to construct AnyMemory from.
__init__(inout self: Self, owned value: AnyMojoValue)
Creates AnyMemory from AnyMojoValue.
Args:
- βvalue (
AnyMojoValue
): AnyMojoValue to construct AnyMemory from.
is_tensor
β
is_tensor(self: Self) -> Bool
Check whether this contains a tensor.
Returns:
True if contains tensor.
take_tensor
β
take_tensor(inout self: Self) -> AnyTensor
Take tensor from object. Further access to this object is undefined behavior.
Returns:
The tensor inside the memory as AnyTensor.
take
β
take(inout self: Self) -> Self
The returned value takes self's resources and replaces them with default initialized values.
Returns:
Newly constructed AnyMemory that takes storage from this.
to_device_tensor
β
to_device_tensor(owned self: Self) -> DeviceTensor
Consume this object and produces and instance of DeviceTensor. Only valid if this was created from DeviceTensor.
Returns:
DeviceTensor representation of AnyMemory.
to
β
to[T: Movable](owned self: Self) -> $0
Consume this object and produces an instance of T. This doesn't do any type check beyond whether this is a AnyTensor or not, and if not assume this was created from T.
Returns:
An instance of type T.
take_value
β
take_value(inout self: Self) -> AnyMojoValue
Take value from object. Further access to this object is undefined behavior.
Returns:
The value inside the memory as AnyMojoValue.
__str__
β
__str__(self: Self) -> String
Gets this value as a string.
format_to
β
format_to(self: Self, inout writer: Formatter)
Formats the string representation of this value 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?