Add from_raw function

This commit is contained in:
Christopher Chalmers 2020-05-23 20:34:09 +01:00
parent 8abd94d828
commit 6f77c950bc
2 changed files with 10 additions and 3 deletions

View File

@ -16,7 +16,7 @@ pub use allocator::Allocator;
// note that this be come after the macro definitions (in api)
mod value;
pub use value::{Tensor, OrtType};
pub use value::{OrtType, Tensor};
macro_rules! ort_type {
($t:ident, $r:ident) => {
@ -28,6 +28,9 @@ macro_rules! ort_type {
pub fn raw(&self) -> *mut sys::$t {
self.raw
}
pub unsafe fn from_raw(raw: *mut sys::$t) -> Self {
Self { raw }
}
}
impl Drop for $t {
@ -128,7 +131,10 @@ impl SessionOptions {
Ok(SessionOptions { raw })
}
pub fn set_optimized_model_filepath(&mut self, optimized_model_filepath: &str) -> Result<&mut Self> {
pub fn set_optimized_model_filepath(
&mut self,
optimized_model_filepath: &str,
) -> Result<&mut Self> {
let optimized_model_filepath = CString::new(optimized_model_filepath)?;
unsafe {
checked_call!(

View File

@ -195,7 +195,8 @@ impl<T: OrtType> Tensor<T> {
// must be owned or will panic, don't give it negative dims
pub fn resize(&mut self, dims: Vec<i64>)
where T: Clone + Default
where
T: Clone + Default,
{
let len = dims.iter().product::<i64>();
let owned = self.owned.as_mut().expect("Tensor::resize not owned");