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