Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//! convert module has the trait for conversion of Inputs ConstructTensor.
 
use crate::{memory::MemoryInfo, OrtError};
use onnxruntime_sys::{OrtAllocator, OrtValue};
use std::fmt::Debug;
 
/// The Input type for Rust onnxruntime Session::run
pub trait ConstructTensor: Debug {
    /// Constuct an OrtTensor Input using the `MemoryInfo` and a raw pointer to the `OrtAllocator`.
    fn construct<'a>(
        &'a mut self,
        memory_info: &MemoryInfo,
        allocator: *mut OrtAllocator,
    ) -> Result<Box<dyn InputTensor + 'a>, OrtError>;
}
 
/// Allows the return value of ConstructTensor::construct
/// to be generic.
pub trait InputTensor {
    /// The input tensor's shape
    fn shape(&self) -> &[usize];
 
    /// The input tensor's ptr
    fn ptr(&self) -> *mut OrtValue;
}
 
impl<'a, T> From<T> for Box<dyn ConstructTensor + 'a>
where
    T: ConstructTensor + 'a,
{
    fn from(other: T) -> Self {
        Box::new(other)
    }
}