mirror of
https://github.com/pykeio/ort
synced 2026-04-25 16:34:55 +02:00
feat: msrv 1.72
This commit is contained in:
@@ -32,7 +32,7 @@ name = "ort"
|
|||||||
description = "A safe Rust wrapper for ONNX Runtime 1.20 - Optimize and accelerate machine learning inference & training"
|
description = "A safe Rust wrapper for ONNX Runtime 1.20 - Optimize and accelerate machine learning inference & training"
|
||||||
version = "2.0.0-rc.9"
|
version = "2.0.0-rc.9"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.70"
|
rust-version = "1.72"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
repository = "https://github.com/pykeio/ort"
|
repository = "https://github.com/pykeio/ort"
|
||||||
homepage = "https://ort.pyke.io/"
|
homepage = "https://ort.pyke.io/"
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
use std::hash::{BuildHasher, Hasher, RandomState};
|
use std::{
|
||||||
|
collections::hash_map::RandomState,
|
||||||
|
hash::{BuildHasher, Hasher}
|
||||||
|
};
|
||||||
|
|
||||||
pub mod dirs;
|
pub mod dirs;
|
||||||
|
|
||||||
|
|||||||
22
src/lib.rs
22
src/lib.rs
@@ -24,6 +24,8 @@ pub(crate) mod logging;
|
|||||||
pub mod memory;
|
pub mod memory;
|
||||||
pub mod metadata;
|
pub mod metadata;
|
||||||
pub mod operator;
|
pub mod operator;
|
||||||
|
#[macro_use]
|
||||||
|
pub(crate) mod private;
|
||||||
pub mod session;
|
pub mod session;
|
||||||
pub mod tensor;
|
pub mod tensor;
|
||||||
#[cfg(feature = "training")]
|
#[cfg(feature = "training")]
|
||||||
@@ -247,26 +249,6 @@ pub(crate) fn char_p_to_string(raw: *const c_char) -> Result<String> {
|
|||||||
Ok(c_string.to_string_lossy().to_string())
|
Ok(c_string.to_string_lossy().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct PrivateTraitMarker;
|
|
||||||
|
|
||||||
macro_rules! private_trait {
|
|
||||||
() => {
|
|
||||||
#[doc(hidden)]
|
|
||||||
#[allow(private_interfaces)]
|
|
||||||
fn _private() -> crate::PrivateTraitMarker;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
macro_rules! private_impl {
|
|
||||||
() => {
|
|
||||||
#[allow(private_interfaces)]
|
|
||||||
fn _private() -> crate::PrivateTraitMarker {
|
|
||||||
crate::PrivateTraitMarker
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
pub(crate) use private_impl;
|
|
||||||
pub(crate) use private_trait;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ impl KernelAttributes {
|
|||||||
Self(NonNull::from(unsafe { &*info }))
|
Self(NonNull::from(unsafe { &*info }))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(private_bounds)]
|
|
||||||
pub fn get<'s, T: GetKernelAttribute<'s>>(&'s self, name: impl AsRef<str>) -> Option<T> {
|
pub fn get<'s, T: GetKernelAttribute<'s>>(&'s self, name: impl AsRef<str>) -> Option<T> {
|
||||||
let name = CString::new(name.as_ref()).ok()?;
|
let name = CString::new(name.as_ref()).ok()?;
|
||||||
T::get_from(self.0.as_ptr(), name.as_ptr())
|
T::get_from(self.0.as_ptr(), name.as_ptr())
|
||||||
@@ -106,7 +105,7 @@ impl AsPointer for KernelAttributes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait GetKernelAttribute<'s> {
|
pub trait GetKernelAttribute<'s> {
|
||||||
fn get_from(info: *mut ort_sys::OrtKernelInfo, name: *const ort_sys::c_char) -> Option<Self>
|
fn get_from(info: *mut ort_sys::OrtKernelInfo, name: *const ort_sys::c_char) -> Option<Self>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
|
|||||||
15
src/private.rs
Normal file
15
src/private.rs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
pub struct PrivateTraitMarker;
|
||||||
|
|
||||||
|
macro_rules! private_trait {
|
||||||
|
() => {
|
||||||
|
#[doc(hidden)]
|
||||||
|
fn _private() -> crate::private::PrivateTraitMarker;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
macro_rules! private_impl {
|
||||||
|
() => {
|
||||||
|
fn _private() -> crate::private::PrivateTraitMarker {
|
||||||
|
crate::private::PrivateTraitMarker
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -116,13 +116,13 @@ pub trait IntoTensorElementType {
|
|||||||
/// Returns the ONNX tensor element data type corresponding to the given Rust type.
|
/// Returns the ONNX tensor element data type corresponding to the given Rust type.
|
||||||
fn into_tensor_element_type() -> TensorElementType;
|
fn into_tensor_element_type() -> TensorElementType;
|
||||||
|
|
||||||
crate::private_trait!();
|
private_trait!();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A superset of [`IntoTensorElementType`] that represents traits whose underlying memory is identical between Rust and
|
/// A superset of [`IntoTensorElementType`] that represents traits whose underlying memory is identical between Rust and
|
||||||
/// C++ (i.e., every type except `String`).
|
/// C++ (i.e., every type except `String`).
|
||||||
pub trait PrimitiveTensorElementType: IntoTensorElementType {
|
pub trait PrimitiveTensorElementType: IntoTensorElementType {
|
||||||
crate::private_trait!();
|
private_trait!();
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_type_trait {
|
macro_rules! impl_type_trait {
|
||||||
@@ -132,11 +132,11 @@ macro_rules! impl_type_trait {
|
|||||||
TensorElementType::$variant
|
TensorElementType::$variant
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PrimitiveTensorElementType for $type_ {
|
impl PrimitiveTensorElementType for $type_ {
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -164,7 +164,7 @@ impl IntoTensorElementType for String {
|
|||||||
TensorElementType::String
|
TensorElementType::String
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adapter for common Rust string types to ONNX strings.
|
/// Adapter for common Rust string types to ONNX strings.
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ pub fn path_to_os_char(path: impl AsRef<Path>) -> OsCharArray {
|
|||||||
let model_path: Vec<u16> = model_path.encode_wide().chain(std::iter::once(0)).collect();
|
let model_path: Vec<u16> = model_path.encode_wide().chain(std::iter::once(0)).collect();
|
||||||
#[cfg(not(target_family = "windows"))]
|
#[cfg(not(target_family = "windows"))]
|
||||||
let model_path: Vec<c_char> = model_path
|
let model_path: Vec<c_char> = model_path
|
||||||
.as_encoded_bytes()
|
.as_bytes()
|
||||||
.iter()
|
.iter()
|
||||||
.chain(std::iter::once(&b'\0'))
|
.chain(std::iter::once(&b'\0'))
|
||||||
.map(|b| *b as c_char)
|
.map(|b| *b as c_char)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub trait MapValueTypeMarker: ValueTypeMarker {
|
pub trait MapValueTypeMarker: ValueTypeMarker {
|
||||||
crate::private_trait!();
|
private_trait!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -30,10 +30,10 @@ impl ValueTypeMarker for DynMapValueType {
|
|||||||
"DynMap".to_string()
|
"DynMap".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
impl MapValueTypeMarker for DynMapValueType {
|
impl MapValueTypeMarker for DynMapValueType {
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DowncastableTarget for DynMapValueType {
|
impl DowncastableTarget for DynMapValueType {
|
||||||
@@ -41,7 +41,7 @@ impl DowncastableTarget for DynMapValueType {
|
|||||||
matches!(dtype, ValueType::Map { .. })
|
matches!(dtype, ValueType::Map { .. })
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -51,10 +51,10 @@ impl<K: IntoTensorElementType + Debug + Clone + Hash + Eq, V: IntoTensorElementT
|
|||||||
format!("Map<{}, {}>", K::into_tensor_element_type(), V::into_tensor_element_type())
|
format!("Map<{}, {}>", K::into_tensor_element_type(), V::into_tensor_element_type())
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
impl<K: IntoTensorElementType + Debug + Clone + Hash + Eq, V: IntoTensorElementType + Debug> MapValueTypeMarker for MapValueType<K, V> {
|
impl<K: IntoTensorElementType + Debug + Clone + Hash + Eq, V: IntoTensorElementType + Debug> MapValueTypeMarker for MapValueType<K, V> {
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: IntoTensorElementType + Debug + Clone + Hash + Eq, V: IntoTensorElementType + Debug> DowncastableTarget for MapValueType<K, V> {
|
impl<K: IntoTensorElementType + Debug + Clone + Hash + Eq, V: IntoTensorElementType + Debug> DowncastableTarget for MapValueType<K, V> {
|
||||||
@@ -65,7 +65,7 @@ impl<K: IntoTensorElementType + Debug + Clone + Hash + Eq, V: IntoTensorElementT
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type DynMap = Value<DynMapValueType>;
|
pub type DynMap = Value<DynMapValueType>;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub trait SequenceValueTypeMarker: ValueTypeMarker {
|
pub trait SequenceValueTypeMarker: ValueTypeMarker {
|
||||||
crate::private_trait!();
|
private_trait!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -24,10 +24,10 @@ impl ValueTypeMarker for DynSequenceValueType {
|
|||||||
"DynSequence".to_string()
|
"DynSequence".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
impl SequenceValueTypeMarker for DynSequenceValueType {
|
impl SequenceValueTypeMarker for DynSequenceValueType {
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DowncastableTarget for DynSequenceValueType {
|
impl DowncastableTarget for DynSequenceValueType {
|
||||||
@@ -35,7 +35,7 @@ impl DowncastableTarget for DynSequenceValueType {
|
|||||||
matches!(dtype, ValueType::Sequence { .. })
|
matches!(dtype, ValueType::Sequence { .. })
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -45,10 +45,10 @@ impl<T: ValueTypeMarker + DowncastableTarget + Debug + ?Sized> ValueTypeMarker f
|
|||||||
format!("Sequence<{}>", T::format())
|
format!("Sequence<{}>", T::format())
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
impl<T: ValueTypeMarker + DowncastableTarget + Debug + ?Sized> SequenceValueTypeMarker for SequenceValueType<T> {
|
impl<T: ValueTypeMarker + DowncastableTarget + Debug + ?Sized> SequenceValueTypeMarker for SequenceValueType<T> {
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ValueTypeMarker + DowncastableTarget + Debug + ?Sized> DowncastableTarget for SequenceValueType<T> {
|
impl<T: ValueTypeMarker + DowncastableTarget + Debug + ?Sized> DowncastableTarget for SequenceValueType<T> {
|
||||||
@@ -59,7 +59,7 @@ impl<T: ValueTypeMarker + DowncastableTarget + Debug + ?Sized> DowncastableTarge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type DynSequence = Value<DynSequenceValueType>;
|
pub type DynSequence = Value<DynSequenceValueType>;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use std::{
|
|||||||
ffi,
|
ffi,
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
|
mem::size_of,
|
||||||
ptr::{self, NonNull},
|
ptr::{self, NonNull},
|
||||||
sync::Arc
|
sync::Arc
|
||||||
};
|
};
|
||||||
@@ -438,20 +439,20 @@ pub trait TensorArrayData<I> {
|
|||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
fn ref_parts(&self) -> Result<(Vec<i64>, &[I], Option<Box<dyn Any>>)>;
|
fn ref_parts(&self) -> Result<(Vec<i64>, &[I], Option<Box<dyn Any>>)>;
|
||||||
|
|
||||||
crate::private_trait!();
|
private_trait!();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TensorArrayDataMut<I>: TensorArrayData<I> {
|
pub trait TensorArrayDataMut<I>: TensorArrayData<I> {
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
fn ref_parts_mut(&mut self) -> Result<(Vec<i64>, &mut [I], Option<Box<dyn Any>>)>;
|
fn ref_parts_mut(&mut self) -> Result<(Vec<i64>, &mut [I], Option<Box<dyn Any>>)>;
|
||||||
|
|
||||||
crate::private_trait!();
|
private_trait!();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait OwnedTensorArrayData<I> {
|
pub trait OwnedTensorArrayData<I> {
|
||||||
fn into_parts(self) -> Result<TensorArrayDataParts<I>>;
|
fn into_parts(self) -> Result<TensorArrayDataParts<I>>;
|
||||||
|
|
||||||
crate::private_trait!();
|
private_trait!();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TensorArrayDataParts<I> {
|
pub struct TensorArrayDataParts<I> {
|
||||||
@@ -531,7 +532,7 @@ impl<T: Clone + 'static, D: Dimension + 'static> TensorArrayData<T> for &CowArra
|
|||||||
Ok((shape, data, None))
|
Ok((shape, data, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "ndarray")]
|
#[cfg(feature = "ndarray")]
|
||||||
@@ -545,7 +546,7 @@ impl<T: Clone + 'static, D: Dimension + 'static> TensorArrayData<T> for ArcArray
|
|||||||
Ok((shape, data, Some(Box::new(self.clone()))))
|
Ok((shape, data, Some(Box::new(self.clone()))))
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "ndarray")]
|
#[cfg(feature = "ndarray")]
|
||||||
@@ -559,7 +560,7 @@ impl<T: Clone + 'static, D: Dimension + 'static> TensorArrayData<T> for &Array<T
|
|||||||
Ok((shape, data, None))
|
Ok((shape, data, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "ndarray")]
|
#[cfg(feature = "ndarray")]
|
||||||
@@ -573,7 +574,7 @@ impl<T: Clone + 'static, D: Dimension + 'static> TensorArrayData<T> for &mut Arr
|
|||||||
Ok((shape, data, None))
|
Ok((shape, data, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "ndarray")]
|
#[cfg(feature = "ndarray")]
|
||||||
@@ -598,7 +599,7 @@ impl<T: Clone + 'static, D: Dimension + 'static> OwnedTensorArrayData<T> for Arr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "ndarray")]
|
#[cfg(feature = "ndarray")]
|
||||||
@@ -612,7 +613,7 @@ impl<T: Clone + 'static, D: Dimension + 'static> TensorArrayData<T> for ArrayVie
|
|||||||
Ok((shape, data, None))
|
Ok((shape, data, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "ndarray")]
|
#[cfg(feature = "ndarray")]
|
||||||
@@ -626,7 +627,7 @@ impl<T: Clone + 'static, D: Dimension + 'static> TensorArrayData<T> for ArrayVie
|
|||||||
Ok((shape, data, None))
|
Ok((shape, data, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "ndarray")]
|
#[cfg(feature = "ndarray")]
|
||||||
@@ -640,7 +641,7 @@ impl<T: Clone + 'static, D: Dimension + 'static> TensorArrayDataMut<T> for Array
|
|||||||
Ok((shape, data, None))
|
Ok((shape, data, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "ndarray")]
|
#[cfg(feature = "ndarray")]
|
||||||
@@ -654,7 +655,7 @@ impl<T: Clone + 'static, D: Dimension + 'static> TensorArrayDataMut<T> for &mut
|
|||||||
Ok((shape, data, None))
|
Ok((shape, data, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Clone + 'static, D: ToDimensions> TensorArrayData<T> for (D, &[T]) {
|
impl<T: Clone + 'static, D: ToDimensions> TensorArrayData<T> for (D, &[T]) {
|
||||||
@@ -663,7 +664,7 @@ impl<T: Clone + 'static, D: ToDimensions> TensorArrayData<T> for (D, &[T]) {
|
|||||||
Ok((shape, self.1, None))
|
Ok((shape, self.1, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Clone + 'static, D: ToDimensions> TensorArrayData<T> for (D, &mut [T]) {
|
impl<T: Clone + 'static, D: ToDimensions> TensorArrayData<T> for (D, &mut [T]) {
|
||||||
@@ -672,7 +673,7 @@ impl<T: Clone + 'static, D: ToDimensions> TensorArrayData<T> for (D, &mut [T]) {
|
|||||||
Ok((shape, self.1, None))
|
Ok((shape, self.1, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Clone + 'static, D: ToDimensions> TensorArrayDataMut<T> for (D, &mut [T]) {
|
impl<T: Clone + 'static, D: ToDimensions> TensorArrayDataMut<T> for (D, &mut [T]) {
|
||||||
@@ -681,7 +682,7 @@ impl<T: Clone + 'static, D: ToDimensions> TensorArrayDataMut<T> for (D, &mut [T]
|
|||||||
Ok((shape, self.1, None))
|
Ok((shape, self.1, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Clone + 'static, D: ToDimensions> OwnedTensorArrayData<T> for (D, Vec<T>) {
|
impl<T: Clone + 'static, D: ToDimensions> OwnedTensorArrayData<T> for (D, Vec<T>) {
|
||||||
@@ -697,7 +698,7 @@ impl<T: Clone + 'static, D: ToDimensions> OwnedTensorArrayData<T> for (D, Vec<T>
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Clone + 'static, D: ToDimensions> OwnedTensorArrayData<T> for (D, Box<[T]>) {
|
impl<T: Clone + 'static, D: ToDimensions> OwnedTensorArrayData<T> for (D, Box<[T]>) {
|
||||||
@@ -713,7 +714,7 @@ impl<T: Clone + 'static, D: ToDimensions> OwnedTensorArrayData<T> for (D, Box<[T
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Clone + 'static, D: ToDimensions> TensorArrayData<T> for (D, Arc<[T]>) {
|
impl<T: Clone + 'static, D: ToDimensions> TensorArrayData<T> for (D, Arc<[T]>) {
|
||||||
@@ -723,7 +724,7 @@ impl<T: Clone + 'static, D: ToDimensions> TensorArrayData<T> for (D, Arc<[T]>) {
|
|||||||
Ok((shape, data, Some(Box::new(self.1.clone()))))
|
Ok((shape, data, Some(Box::new(self.1.clone()))))
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Clone + 'static, D: ToDimensions> TensorArrayData<T> for (D, Arc<Box<[T]>>) {
|
impl<T: Clone + 'static, D: ToDimensions> TensorArrayData<T> for (D, Arc<Box<[T]>>) {
|
||||||
@@ -733,5 +734,5 @@ impl<T: Clone + 'static, D: ToDimensions> TensorArrayData<T> for (D, Arc<Box<[T]
|
|||||||
Ok((shape, data, Some(Box::new(self.1.clone()))))
|
Ok((shape, data, Some(Box::new(self.1.clone()))))
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ impl<Type: TensorValueTypeMarker + ?Sized> Value<Type> {
|
|||||||
#[cfg(feature = "ndarray")]
|
#[cfg(feature = "ndarray")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "ndarray")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "ndarray")))]
|
||||||
pub fn try_extract_tensor<T: PrimitiveTensorElementType>(&self) -> Result<ndarray::ArrayViewD<'_, T>> {
|
pub fn try_extract_tensor<T: PrimitiveTensorElementType>(&self) -> Result<ndarray::ArrayViewD<'_, T>> {
|
||||||
use crate::AsPointer;
|
|
||||||
|
|
||||||
match self.dtype() {
|
match self.dtype() {
|
||||||
ValueType::Tensor { ty, dimensions, .. } => {
|
ValueType::Tensor { ty, dimensions, .. } => {
|
||||||
let mem = self.memory_info();
|
let mem = self.memory_info();
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use super::{DowncastableTarget, DynValue, Value, ValueRef, ValueRefMut, ValueTyp
|
|||||||
use crate::{AsPointer, error::Result, memory::MemoryInfo, ortsys, tensor::IntoTensorElementType};
|
use crate::{AsPointer, error::Result, memory::MemoryInfo, ortsys, tensor::IntoTensorElementType};
|
||||||
|
|
||||||
pub trait TensorValueTypeMarker: ValueTypeMarker {
|
pub trait TensorValueTypeMarker: ValueTypeMarker {
|
||||||
crate::private_trait!();
|
private_trait!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -23,10 +23,10 @@ impl ValueTypeMarker for DynTensorValueType {
|
|||||||
"DynTensor".to_string()
|
"DynTensor".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
impl TensorValueTypeMarker for DynTensorValueType {
|
impl TensorValueTypeMarker for DynTensorValueType {
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -36,10 +36,10 @@ impl<T: IntoTensorElementType + Debug> ValueTypeMarker for TensorValueType<T> {
|
|||||||
format!("Tensor<{}>", T::into_tensor_element_type())
|
format!("Tensor<{}>", T::into_tensor_element_type())
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
impl<T: IntoTensorElementType + Debug> TensorValueTypeMarker for TensorValueType<T> {
|
impl<T: IntoTensorElementType + Debug> TensorValueTypeMarker for TensorValueType<T> {
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A tensor [`Value`] whose data type is unknown.
|
/// A tensor [`Value`] whose data type is unknown.
|
||||||
@@ -61,7 +61,7 @@ impl DowncastableTarget for DynTensorValueType {
|
|||||||
matches!(dtype, ValueType::Tensor { .. })
|
matches!(dtype, ValueType::Tensor { .. })
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Type: TensorValueTypeMarker + ?Sized> Value<Type> {
|
impl<Type: TensorValueTypeMarker + ?Sized> Value<Type> {
|
||||||
@@ -215,7 +215,7 @@ impl<T: IntoTensorElementType + Debug> DowncastableTarget for TensorValueType<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: IntoTensorElementType + Debug> From<Value<TensorValueType<T>>> for DynValue {
|
impl<T: IntoTensorElementType + Debug> From<Value<TensorValueType<T>>> for DynValue {
|
||||||
|
|||||||
@@ -248,14 +248,14 @@ pub trait ValueTypeMarker {
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn format() -> String;
|
fn format() -> String;
|
||||||
|
|
||||||
crate::private_trait!();
|
private_trait!();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a type that a [`DynValue`] can be downcast to.
|
/// Represents a type that a [`DynValue`] can be downcast to.
|
||||||
pub trait DowncastableTarget: ValueTypeMarker {
|
pub trait DowncastableTarget: ValueTypeMarker {
|
||||||
fn can_downcast(dtype: &ValueType) -> bool;
|
fn can_downcast(dtype: &ValueType) -> bool;
|
||||||
|
|
||||||
crate::private_trait!();
|
private_trait!();
|
||||||
}
|
}
|
||||||
|
|
||||||
// this implementation is used in case we want to extract `DynValue`s from a [`Sequence`]; see `try_extract_sequence`
|
// this implementation is used in case we want to extract `DynValue`s from a [`Sequence`]; see `try_extract_sequence`
|
||||||
@@ -264,7 +264,7 @@ impl DowncastableTarget for DynValueTypeMarker {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The dynamic type marker, used for values which can be of any type.
|
/// The dynamic type marker, used for values which can be of any type.
|
||||||
@@ -275,16 +275,16 @@ impl ValueTypeMarker for DynValueTypeMarker {
|
|||||||
"DynValue".to_string()
|
"DynValue".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
impl MapValueTypeMarker for DynValueTypeMarker {
|
impl MapValueTypeMarker for DynValueTypeMarker {
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
impl SequenceValueTypeMarker for DynValueTypeMarker {
|
impl SequenceValueTypeMarker for DynValueTypeMarker {
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
impl TensorValueTypeMarker for DynValueTypeMarker {
|
impl TensorValueTypeMarker for DynValueTypeMarker {
|
||||||
crate::private_impl!();
|
private_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<Type: ValueTypeMarker + ?Sized> Send for Value<Type> {}
|
unsafe impl<Type: ValueTypeMarker + ?Sized> Send for Value<Type> {}
|
||||||
|
|||||||
Reference in New Issue
Block a user