Skip to main content

value

Types for values that can be passed in and out of engine models.

Value

Owns a single reference to a value passed in or out of a model.

Implemented traits:

AnyType

Methods:

__init__

__init__(inout self: Self, ptr: CValue, lib: DLHandle, owned session: InferenceSession)

Internal use only.

To create values yourself, use new_*_value methods on InferenceSession.

Args:

  • ptr (CValue): Internal use only.
  • lib (DLHandle): Internal use only.
  • session (InferenceSession): Internal use only.

__moveinit__

__moveinit__(inout self: Self, owned existing: Self)

Take ownership of the value contained in another Value.

Args:

  • existing (Self): The value to take ownership of.

__del__

__del__(owned self: Self)

Dispose of this reference to this value.

as_tensor_copy

as_tensor_copy[type: DType](self: Self) -> Tensor[type]

Return a copy of the tensor contained in this value.

Raises: If the value is not a tensor, or the dtype of the tensor value is mismatched with the provided type.

Parameters:

  • type (DType): The expected DType of the tensor.

Returns:

A copy of the tensor contained in this value.

as_bool

as_bool(self: Self) -> Bool

Get the boolean contained in this value.

The result is undefined if this value is not a boolean.

Returns:

Boolean contained in this value.

as_list

as_list(self: Self) -> List

Borrow the list contained in this value.

Ownership of the list is not transferred. User must ensure the value outlives the list.

Returns:

A List borrowing the internal storage of this value.

List

Uncounted reference to underlying storage of a list Value.

The user must take special care not to allow the underlying Value from which this list was obtained to be destroyed prior to being done with the List. However, items within the list are separately reference-counted, so it is safe to use an item retrieved from the list after the list itself has been destroyed, or to destroy an item that was appended to a list (provided, however, that if the item itself is borrowing data (e.g. a tensor), that that underlying data must remain present).

Implemented traits:

AnyType, Sized

Methods:

__init__

__init__(inout self: Self, ptr: CList, lib: DLHandle, owned session: InferenceSession)

Internal use only.

To create lists yourself, use InferenceSession.new_list_value and then use Value.as_list on the resulting value.

Args:

  • ptr (CList): Internal use only.
  • lib (DLHandle): Internal use only.
  • session (InferenceSession): Internal use only.

__moveinit__

__moveinit__(inout self: Self, owned existing: Self)

Create a new List pointing at the internals of another List.

Lists do not own anything and are borrowed from the internal storage of a Value, so the user must continue to take care to ensure that the Value the original List was sourced from continues to outlive this new List object.

Args:

  • existing (Self): The List to represent.

__del__

__del__(owned self: Self)

Release the handle to this list.

The underlying storage remains owned by the Value from which this List was obtained.

__getitem__

__getitem__(self: Self, index: Int) -> Value

Get the value at an index of the list.

The returned Value owns a new reference to the underlying storage of the value, and so the returned item Value may be safely used even after the list (and value containing the list) are destroyed.

Raises: If the index is out of bounds.

Args:

  • index (Int): The index of the item to retrieve within the list.

Returns:

A new reference to an existing value within the list.

__len__

__len__(self: Self) -> Int

Get the length of the list.

Returns:

The length of the list.

append

append(self: Self, value: Value)

Append a Value to the list.

The list will own a new reference to the value, so it is safe to allow value to be destroyed after this operation.

Args:

  • value (Value): The value to append to the list.