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"
|
||||
version = "2.0.0-rc.9"
|
||||
edition = "2021"
|
||||
rust-version = "1.70"
|
||||
rust-version = "1.72"
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/pykeio/ort"
|
||||
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;
|
||||
|
||||
|
||||
22
src/lib.rs
22
src/lib.rs
@@ -24,6 +24,8 @@ pub(crate) mod logging;
|
||||
pub mod memory;
|
||||
pub mod metadata;
|
||||
pub mod operator;
|
||||
#[macro_use]
|
||||
pub(crate) mod private;
|
||||
pub mod session;
|
||||
pub mod tensor;
|
||||
#[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())
|
||||
}
|
||||
|
||||
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)]
|
||||
mod test {
|
||||
use std::ffi::CString;
|
||||
|
||||
@@ -33,7 +33,6 @@ impl KernelAttributes {
|
||||
Self(NonNull::from(unsafe { &*info }))
|
||||
}
|
||||
|
||||
#[allow(private_bounds)]
|
||||
pub fn get<'s, T: GetKernelAttribute<'s>>(&'s self, name: impl AsRef<str>) -> Option<T> {
|
||||
let name = CString::new(name.as_ref()).ok()?;
|
||||
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>
|
||||
where
|
||||
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.
|
||||
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
|
||||
/// C++ (i.e., every type except `String`).
|
||||
pub trait PrimitiveTensorElementType: IntoTensorElementType {
|
||||
crate::private_trait!();
|
||||
private_trait!();
|
||||
}
|
||||
|
||||
macro_rules! impl_type_trait {
|
||||
@@ -132,11 +132,11 @@ macro_rules! impl_type_trait {
|
||||
TensorElementType::$variant
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
impl PrimitiveTensorElementType for $type_ {
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -164,7 +164,7 @@ impl IntoTensorElementType for String {
|
||||
TensorElementType::String
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
/// 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();
|
||||
#[cfg(not(target_family = "windows"))]
|
||||
let model_path: Vec<c_char> = model_path
|
||||
.as_encoded_bytes()
|
||||
.as_bytes()
|
||||
.iter()
|
||||
.chain(std::iter::once(&b'\0'))
|
||||
.map(|b| *b as c_char)
|
||||
|
||||
@@ -20,7 +20,7 @@ use crate::{
|
||||
};
|
||||
|
||||
pub trait MapValueTypeMarker: ValueTypeMarker {
|
||||
crate::private_trait!();
|
||||
private_trait!();
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -30,10 +30,10 @@ impl ValueTypeMarker for DynMapValueType {
|
||||
"DynMap".to_string()
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
impl MapValueTypeMarker for DynMapValueType {
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
impl DowncastableTarget for DynMapValueType {
|
||||
@@ -41,7 +41,7 @@ impl DowncastableTarget for DynMapValueType {
|
||||
matches!(dtype, ValueType::Map { .. })
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
#[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())
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
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> {
|
||||
@@ -65,7 +65,7 @@ impl<K: IntoTensorElementType + Debug + Clone + Hash + Eq, V: IntoTensorElementT
|
||||
}
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
pub type DynMap = Value<DynMapValueType>;
|
||||
|
||||
@@ -14,7 +14,7 @@ use crate::{
|
||||
};
|
||||
|
||||
pub trait SequenceValueTypeMarker: ValueTypeMarker {
|
||||
crate::private_trait!();
|
||||
private_trait!();
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -24,10 +24,10 @@ impl ValueTypeMarker for DynSequenceValueType {
|
||||
"DynSequence".to_string()
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
impl SequenceValueTypeMarker for DynSequenceValueType {
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
impl DowncastableTarget for DynSequenceValueType {
|
||||
@@ -35,7 +35,7 @@ impl DowncastableTarget for DynSequenceValueType {
|
||||
matches!(dtype, ValueType::Sequence { .. })
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -45,10 +45,10 @@ impl<T: ValueTypeMarker + DowncastableTarget + Debug + ?Sized> ValueTypeMarker f
|
||||
format!("Sequence<{}>", T::format())
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
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> {
|
||||
@@ -59,7 +59,7 @@ impl<T: ValueTypeMarker + DowncastableTarget + Debug + ?Sized> DowncastableTarge
|
||||
}
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
pub type DynSequence = Value<DynSequenceValueType>;
|
||||
|
||||
@@ -3,6 +3,7 @@ use std::{
|
||||
ffi,
|
||||
fmt::Debug,
|
||||
marker::PhantomData,
|
||||
mem::size_of,
|
||||
ptr::{self, NonNull},
|
||||
sync::Arc
|
||||
};
|
||||
@@ -438,20 +439,20 @@ pub trait TensorArrayData<I> {
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn ref_parts(&self) -> Result<(Vec<i64>, &[I], Option<Box<dyn Any>>)>;
|
||||
|
||||
crate::private_trait!();
|
||||
private_trait!();
|
||||
}
|
||||
|
||||
pub trait TensorArrayDataMut<I>: TensorArrayData<I> {
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn ref_parts_mut(&mut self) -> Result<(Vec<i64>, &mut [I], Option<Box<dyn Any>>)>;
|
||||
|
||||
crate::private_trait!();
|
||||
private_trait!();
|
||||
}
|
||||
|
||||
pub trait OwnedTensorArrayData<I> {
|
||||
fn into_parts(self) -> Result<TensorArrayDataParts<I>>;
|
||||
|
||||
crate::private_trait!();
|
||||
private_trait!();
|
||||
}
|
||||
|
||||
pub struct TensorArrayDataParts<I> {
|
||||
@@ -531,7 +532,7 @@ impl<T: Clone + 'static, D: Dimension + 'static> TensorArrayData<T> for &CowArra
|
||||
Ok((shape, data, None))
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
#[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()))))
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
#[cfg(feature = "ndarray")]
|
||||
@@ -559,7 +560,7 @@ impl<T: Clone + 'static, D: Dimension + 'static> TensorArrayData<T> for &Array<T
|
||||
Ok((shape, data, None))
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
#[cfg(feature = "ndarray")]
|
||||
@@ -573,7 +574,7 @@ impl<T: Clone + 'static, D: Dimension + 'static> TensorArrayData<T> for &mut Arr
|
||||
Ok((shape, data, None))
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
#[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")]
|
||||
@@ -612,7 +613,7 @@ impl<T: Clone + 'static, D: Dimension + 'static> TensorArrayData<T> for ArrayVie
|
||||
Ok((shape, data, None))
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
#[cfg(feature = "ndarray")]
|
||||
@@ -626,7 +627,7 @@ impl<T: Clone + 'static, D: Dimension + 'static> TensorArrayData<T> for ArrayVie
|
||||
Ok((shape, data, None))
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
#[cfg(feature = "ndarray")]
|
||||
@@ -640,7 +641,7 @@ impl<T: Clone + 'static, D: Dimension + 'static> TensorArrayDataMut<T> for Array
|
||||
Ok((shape, data, None))
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
#[cfg(feature = "ndarray")]
|
||||
@@ -654,7 +655,7 @@ impl<T: Clone + 'static, D: Dimension + 'static> TensorArrayDataMut<T> for &mut
|
||||
Ok((shape, data, None))
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
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]>) {
|
||||
@@ -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]>) {
|
||||
@@ -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()))))
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
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()))))
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
@@ -46,8 +46,6 @@ impl<Type: TensorValueTypeMarker + ?Sized> Value<Type> {
|
||||
#[cfg(feature = "ndarray")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "ndarray")))]
|
||||
pub fn try_extract_tensor<T: PrimitiveTensorElementType>(&self) -> Result<ndarray::ArrayViewD<'_, T>> {
|
||||
use crate::AsPointer;
|
||||
|
||||
match self.dtype() {
|
||||
ValueType::Tensor { ty, dimensions, .. } => {
|
||||
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};
|
||||
|
||||
pub trait TensorValueTypeMarker: ValueTypeMarker {
|
||||
crate::private_trait!();
|
||||
private_trait!();
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -23,10 +23,10 @@ impl ValueTypeMarker for DynTensorValueType {
|
||||
"DynTensor".to_string()
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
impl TensorValueTypeMarker for DynTensorValueType {
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -36,10 +36,10 @@ impl<T: IntoTensorElementType + Debug> ValueTypeMarker for TensorValueType<T> {
|
||||
format!("Tensor<{}>", T::into_tensor_element_type())
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
impl<T: IntoTensorElementType + Debug> TensorValueTypeMarker for TensorValueType<T> {
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
/// A tensor [`Value`] whose data type is unknown.
|
||||
@@ -61,7 +61,7 @@ impl DowncastableTarget for DynTensorValueType {
|
||||
matches!(dtype, ValueType::Tensor { .. })
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@@ -248,14 +248,14 @@ pub trait ValueTypeMarker {
|
||||
#[doc(hidden)]
|
||||
fn format() -> String;
|
||||
|
||||
crate::private_trait!();
|
||||
private_trait!();
|
||||
}
|
||||
|
||||
/// Represents a type that a [`DynValue`] can be downcast to.
|
||||
pub trait DowncastableTarget: ValueTypeMarker {
|
||||
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`
|
||||
@@ -264,7 +264,7 @@ impl DowncastableTarget for DynValueTypeMarker {
|
||||
true
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
/// The dynamic type marker, used for values which can be of any type.
|
||||
@@ -275,16 +275,16 @@ impl ValueTypeMarker for DynValueTypeMarker {
|
||||
"DynValue".to_string()
|
||||
}
|
||||
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
impl MapValueTypeMarker for DynValueTypeMarker {
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
impl SequenceValueTypeMarker for DynValueTypeMarker {
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
impl TensorValueTypeMarker for DynValueTypeMarker {
|
||||
crate::private_impl!();
|
||||
private_impl!();
|
||||
}
|
||||
|
||||
unsafe impl<Type: ValueTypeMarker + ?Sized> Send for Value<Type> {}
|
||||
|
||||
Reference in New Issue
Block a user