Enum ort::SessionInputValue
source · pub enum SessionInputValue<'v> {
ViewMut(ValueRefMut<'v, DynValueTypeMarker>),
View(ValueRef<'v, DynValueTypeMarker>),
Owned(Value<DynValueTypeMarker>),
}
Variants§
ViewMut(ValueRefMut<'v, DynValueTypeMarker>)
View(ValueRef<'v, DynValueTypeMarker>)
Owned(Value<DynValueTypeMarker>)
Methods from Deref<Target = Value>§
pub fn try_extract_map<K: IntoTensorElementType + Clone + Hash + Eq, V: IntoTensorElementType + Clone>( &self, allocator: &Allocator ) -> Result<HashMap<K, V>>
pub fn extract_map(&self, allocator: &Allocator) -> HashMap<K, V>
sourcepub fn upcast_ref(&self) -> DynMapRef<'_>
pub fn upcast_ref(&self) -> DynMapRef<'_>
pub fn try_extract_sequence<'s, OtherType: ValueTypeMarker + DowncastableTarget + Debug + Sized>( &'s self, allocator: &Allocator ) -> Result<Vec<ValueRef<'s, OtherType>>>
pub fn extract_sequence<'s>( &'s self, allocator: &Allocator ) -> Vec<ValueRef<'s, T>>
sourcepub fn upcast_ref(&self) -> DynSequenceRef<'_>
pub fn upcast_ref(&self) -> DynSequenceRef<'_>
Converts from a strongly-typed Sequence<T>
to a reference to a type-erased DynSequence
.
sourcepub fn try_extract_tensor<T: IntoTensorElementType>(
&self
) -> Result<ArrayViewD<'_, T>>
Available on crate feature ndarray
only.
pub fn try_extract_tensor<T: IntoTensorElementType>( &self ) -> Result<ArrayViewD<'_, T>>
ndarray
only.Attempt to extract the underlying data of type T
into a read-only ndarray::ArrayView
.
See also:
- the mutable counterpart of this function,
Tensor::try_extract_tensor_mut
. - the infallible counterpart,
Tensor::extract_tensor
, for typedTensor<T>
s. - the alternative function for strings,
Tensor::try_extract_string_tensor
.
let array = ndarray::Array4::<f32>::ones((1, 16, 16, 3));
let value = Value::from_array(array.view())?;
let extracted = value.try_extract_tensor::<f32>()?;
assert_eq!(array.into_dyn(), extracted);
§Errors
May return an error if:
- This is a
crate::DynValue
, and the value is not actually a tensor. (for typedTensor
s, use the infallibleTensor::extract_tensor
instead) - The provided type
T
does not match the tensor’s element type.
sourcepub fn try_extract_raw_tensor<T: IntoTensorElementType>(
&self
) -> Result<(Vec<i64>, &[T])>
pub fn try_extract_raw_tensor<T: IntoTensorElementType>( &self ) -> Result<(Vec<i64>, &[T])>
Attempt to extract the underlying data into a “raw” view tuple, consisting of the tensor’s dimensions and an immutable view into its data.
See also:
- the mutable counterpart of this function,
Tensor::try_extract_raw_tensor_mut
. - the infallible counterpart,
Tensor::extract_raw_tensor
, for typedTensor<T>
s. - the alternative function for strings,
Tensor::try_extract_raw_string_tensor
.
let array = vec![1_i64, 2, 3, 4, 5];
let value = Value::from_array(([array.len()], array.clone().into_boxed_slice()))?;
let (extracted_shape, extracted_data) = value.try_extract_raw_tensor::<i64>()?;
assert_eq!(extracted_data, &array);
assert_eq!(extracted_shape, [5]);
§Errors
May return an error if:
- This is a
crate::DynValue
, and the value is not actually a tensor. (for typedTensor
s, use the infallibleTensor::extract_raw_tensor
instead) - The provided type
T
does not match the tensor’s element type.
sourcepub fn try_extract_string_tensor(&self) -> Result<ArrayD<String>>
Available on crate feature ndarray
only.
pub fn try_extract_string_tensor(&self) -> Result<ArrayD<String>>
ndarray
only.Attempt to extract the underlying data into a Rust ndarray
.
let array = ndarray::Array1::from_vec(vec!["hello", "world"]);
let tensor = DynTensor::from_string_array(&allocator, array.clone())?;
let extracted = tensor.try_extract_string_tensor()?;
assert_eq!(array.into_dyn(), extracted);
sourcepub fn try_extract_raw_string_tensor(&self) -> Result<(Vec<i64>, Vec<String>)>
pub fn try_extract_raw_string_tensor(&self) -> Result<(Vec<i64>, Vec<String>)>
Attempt to extract the underlying string data into a “raw” data tuple, consisting of the tensor’s dimensions and
an owned Vec
of its data.
let array = vec!["hello", "world"];
let tensor = DynTensor::from_string_array(&allocator, ([array.len()], array.clone().into_boxed_slice()))?;
let (extracted_shape, extracted_data) = tensor.try_extract_raw_string_tensor()?;
assert_eq!(extracted_data, array);
assert_eq!(extracted_shape, [2]);
sourcepub fn shape(&self) -> Result<Vec<i64>>
pub fn shape(&self) -> Result<Vec<i64>>
Returns the shape of the tensor.
let tensor = Tensor::<f32>::new(&allocator, [1, 128, 128, 3])?;
assert_eq!(tensor.shape()?, &[1, 128, 128, 3]);
sourcepub fn extract_tensor(&self) -> ArrayViewD<'_, T>
Available on crate feature ndarray
only.
pub fn extract_tensor(&self) -> ArrayViewD<'_, T>
ndarray
only.Extracts the underlying data into a read-only ndarray::ArrayView
.
let array = ndarray::Array4::<f32>::ones((1, 16, 16, 3));
let tensor = Tensor::from_array(array.view())?;
let extracted = tensor.extract_tensor();
assert_eq!(array.into_dyn(), extracted);
sourcepub fn extract_raw_tensor(&self) -> (Vec<i64>, &[T])
pub fn extract_raw_tensor(&self) -> (Vec<i64>, &[T])
Extracts the underlying data into a “raw” view tuple, consisting of the tensor’s dimensions and an immutable view into its data.
let array = vec![1_i64, 2, 3, 4, 5];
let tensor = Tensor::from_array(([array.len()], array.clone().into_boxed_slice()))?;
let (extracted_shape, extracted_data) = tensor.extract_raw_tensor();
assert_eq!(extracted_data, &array);
assert_eq!(extracted_shape, [5]);
sourcepub fn memory_info(&self) -> Result<MemoryInfo>
pub fn memory_info(&self) -> Result<MemoryInfo>
Returns information about the device this tensor is allocated on.
sourcepub fn upcast_ref(&self) -> DynTensorRef<'_>
pub fn upcast_ref(&self) -> DynTensorRef<'_>
sourcepub fn ptr(&self) -> *mut OrtValue
pub fn ptr(&self) -> *mut OrtValue
Returns the underlying ort_sys::OrtValue
pointer.
sourcepub fn is_tensor(&self) -> Result<bool>
pub fn is_tensor(&self) -> Result<bool>
Returns true
if this value is a tensor, or false
if it is another type (sequence, map).
// Create a tensor from a raw data vector
let tensor_value = Value::from_array(([3usize], vec![1.0_f32, 2.0, 3.0].into_boxed_slice()))?;
assert!(tensor_value.is_tensor()?);
sourcepub fn downcast_ref<OtherType: ValueTypeMarker + DowncastableTarget + Debug + ?Sized>(
&self
) -> Result<ValueRef<'_, OtherType>>
pub fn downcast_ref<OtherType: ValueTypeMarker + DowncastableTarget + Debug + ?Sized>( &self ) -> Result<ValueRef<'_, OtherType>>
Attempts to downcast a dynamic value (like DynValue
or DynTensor
) to a more strongly typed reference
variant, like TensorRef<T>
.