Enum ort::SessionInputValue

source ·
pub enum SessionInputValue<'v> {
    ViewMut(ValueRefMut<'v, DynValueTypeMarker>),
    View(ValueRef<'v, DynValueTypeMarker>),
    Owned(Value<DynValueTypeMarker>),
}

Variants§

Methods from Deref<Target = Value>§

source

pub fn try_extract_map<K: IntoTensorElementType + Clone + Hash + Eq, V: IntoTensorElementType + Clone>( &self, allocator: &Allocator ) -> Result<HashMap<K, V>>

source

pub fn extract_map(&self, allocator: &Allocator) -> HashMap<K, V>

source

pub fn upcast_ref(&self) -> DynMapRef<'_>

Converts from a strongly-typed Map<K, V> to a reference to a type-erased DynMap.

source

pub fn try_extract_sequence<'s, OtherType: ValueTypeMarker + DowncastableTarget + Debug + Sized>( &'s self, allocator: &Allocator ) -> Result<Vec<ValueRef<'s, OtherType>>>

source

pub fn extract_sequence<'s>( &'s self, allocator: &Allocator ) -> Vec<ValueRef<'s, T>>

source

pub fn upcast_ref(&self) -> DynSequenceRef<'_>

Converts from a strongly-typed Sequence<T> to a reference to a type-erased DynSequence.

source

pub fn try_extract_tensor<T: IntoTensorElementType>( &self ) -> Result<ArrayViewD<'_, T>>

Available on crate feature ndarray only.

Attempt to extract the underlying data of type T into a read-only ndarray::ArrayView.

See also:

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:

source

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:

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:

source

pub fn try_extract_string_tensor(&self) -> Result<ArrayD<String>>

Available on crate feature 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);
source

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]);
source

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]);
source

pub fn extract_tensor(&self) -> ArrayViewD<'_, T>

Available on crate feature 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);
source

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]);
source

pub fn data_ptr(&self) -> Result<*const c_void>

Returns a pointer to the tensor’s data.

source

pub fn memory_info(&self) -> Result<MemoryInfo>

Returns information about the device this tensor is allocated on.

source

pub fn upcast_ref(&self) -> DynTensorRef<'_>

Converts from a strongly-typed Tensor<T> to a reference to a type-erased DynTensor.

source

pub fn dtype(&self) -> Result<ValueType>

Returns the data type of this Value.

source

pub fn ptr(&self) -> *mut OrtValue

Returns the underlying ort_sys::OrtValue pointer.

source

pub fn view(&self) -> ValueRef<'_, Type>

Create a view of this value’s data.

source

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()?);
source

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>.

Trait Implementations§

source§

impl<'v> Deref for SessionInputValue<'v>

§

type Target = Value

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'v, T: ValueTypeMarker + ?Sized> From<Value<T>> for SessionInputValue<'v>

source§

fn from(value: Value<T>) -> Self

Converts to this type from the input type.
source§

impl<'v, T: ValueTypeMarker + ?Sized> From<ValueRef<'v, T>> for SessionInputValue<'v>

source§

fn from(value: ValueRef<'v, T>) -> Self

Converts to this type from the input type.
source§

impl<'v, T: ValueTypeMarker + ?Sized> From<ValueRefMut<'v, T>> for SessionInputValue<'v>

source§

fn from(value: ValueRefMut<'v, T>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'v> Freeze for SessionInputValue<'v>

§

impl<'v> !RefUnwindSafe for SessionInputValue<'v>

§

impl<'v> Send for SessionInputValue<'v>

§

impl<'v> !Sync for SessionInputValue<'v>

§

impl<'v> Unpin for SessionInputValue<'v>

§

impl<'v> !UnwindSafe for SessionInputValue<'v>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more