Type Alias ort::DynTensor

source ·
pub type DynTensor = Value<DynTensorValueType>;

Aliased Type§

struct DynTensor { /* private fields */ }

Implementations§

source§

impl DynTensor

source

pub fn from_string_array<T: Utf8Data>( allocator: &Allocator, input: impl IntoValueTensor<Item = T> ) -> Result<DynTensor>

Construct a Value from an array of strings.

Just like numeric tensors, string tensor Values can be created from:

  • (with feature ndarray) a shared reference to a ndarray::CowArray (&CowArray<'_, T, D>);
  • (with feature ndarray) a mutable/exclusive reference to an ndarray::ArcArray (&mut ArcArray<T, D>);
  • (with feature ndarray) an owned ndarray::Array;
  • (with feature ndarray) a borrowed view of another array, as an ndarray::ArrayView (ArrayView<'_, T, D>);
  • a tuple of (dimensions, data) where:
    • dimensions is one of Vec<I>, [I] or &[I], where I is i64 or usize;
    • and data is one of Vec<T>, Box<[T]>, Arc<Box<[T]>>, or &[T].
// You'll need to obtain an `Allocator` from a session in order to create string tensors.
let allocator = session.allocator();

// Create a string tensor from a raw data vector
let data = vec!["hello", "world"];
let value = Value::from_string_array(allocator, ([data.len()], data.into_boxed_slice()))?;

// Create a string tensor from an `ndarray::Array`
#[cfg(feature = "ndarray")]
let value = Value::from_string_array(
	allocator,
	ndarray::Array::from_shape_vec((1,), vec!["document".to_owned()]).unwrap()
)?;

Note that string data will always be copied, no matter what form the data is provided in.

Trait Implementations§

source§

impl<'i, 'v, T: IntoTensorElementType + Debug + Clone + 'static, D: Dimension + 'static> TryFrom<&'i ArrayBase<CowRepr<'v, T>, D>> for DynTensor
where 'i: 'v,

Available on crate feature ndarray only.
§

type Error = Error

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

fn try_from(arr: &'i CowArray<'v, T, D>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<T: IntoTensorElementType + Debug + Clone + 'static, D: Dimension + 'static> TryFrom<&mut ArrayBase<OwnedArcRepr<T>, D>> for DynTensor

Available on crate feature ndarray only.
§

type Error = Error

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

fn try_from(value: &mut ArcArray<T, D>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<T: IntoTensorElementType + Debug + Clone + 'static, I: ToDimensions> TryFrom<(I, &[T])> for DynTensor

§

type Error = Error

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

fn try_from(value: (I, &[T])) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<T: IntoTensorElementType + Debug + Clone + 'static, I: ToDimensions> TryFrom<(I, Arc<Box<[T]>>)> for DynTensor

§

type Error = Error

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

fn try_from(value: (I, Arc<Box<[T]>>)) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<T: IntoTensorElementType + Debug + Clone + 'static, I: ToDimensions> TryFrom<(I, Box<[T]>)> for DynTensor

§

type Error = Error

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

fn try_from(value: (I, Box<[T]>)) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<T: IntoTensorElementType + Debug + Clone + 'static, I: ToDimensions> TryFrom<(I, Vec<T>)> for DynTensor

§

type Error = Error

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

fn try_from(value: (I, Vec<T>)) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<T: IntoTensorElementType + Debug + Clone + 'static, D: Dimension + 'static> TryFrom<ArrayBase<OwnedRepr<T>, D>> for DynTensor

Available on crate feature ndarray only.
§

type Error = Error

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

fn try_from(value: Array<T, D>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'v, T: IntoTensorElementType + Debug + Clone + 'static, D: Dimension + 'static> TryFrom<ArrayBase<ViewRepr<&'v T>, D>> for DynTensor

Available on crate feature ndarray only.
§

type Error = Error

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

fn try_from(arr: ArrayView<'v, T, D>) -> Result<Self, Self::Error>

Performs the conversion.