Skip to main content

BorrowedTensor

Struct BorrowedTensor 

Source
pub struct BorrowedTensor<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> BorrowedTensor<'a>

Source

pub fn from_f32(_data: &'a [f32], shape: &[usize]) -> Result<Self>

Examples found in repository?
examples/load_and_predict.rs (line 18)
7fn main() {
8    let model_path = std::env::args()
9        .nth(1)
10        .unwrap_or_else(|| "tests/fixtures/test_linear.mlmodelc".to_string());
11
12    println!("Loading model: {model_path}");
13    let model = Model::load(&model_path, ComputeUnits::All).expect("Failed to load model");
14
15    // Create a simple input tensor
16    let input_data = vec![1.0f32, 2.0, 3.0, 4.0];
17    let tensor =
18        BorrowedTensor::from_f32(&input_data, &[1, 4]).expect("Failed to create tensor");
19
20    println!("Running prediction...");
21    let prediction = model.predict(&[("input", &tensor)]).expect("Prediction failed");
22
23    let (output, shape) = prediction.get_f32("output").expect("Failed to get output");
24    println!("Output shape: {shape:?}");
25    println!("Output data: {output:?}");
26}
Source

pub fn from_i32(_data: &'a [i32], shape: &[usize]) -> Result<Self>

Source

pub fn from_f64(_data: &'a [f64], shape: &[usize]) -> Result<Self>

Source

pub fn from_f16_bits(_data: &'a [u16], shape: &[usize]) -> Result<Self>

Source

pub fn from_i16(_data: &'a [i16], shape: &[usize]) -> Result<Self>

Source

pub fn from_i8(_data: &'a [i8], shape: &[usize]) -> Result<Self>

Source

pub fn from_u32(_data: &'a [u32], shape: &[usize]) -> Result<Self>

Source

pub fn from_u16(_data: &'a [u16], shape: &[usize]) -> Result<Self>

Source

pub fn from_u8(_data: &'a [u8], shape: &[usize]) -> Result<Self>

Source

pub fn shape(&self) -> &[usize]

Source

pub fn data_type(&self) -> DataType

Source

pub fn element_count(&self) -> usize

Source

pub fn size_bytes(&self) -> usize

Trait Implementations§

Source§

impl<'a> Debug for BorrowedTensor<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl AsMultiArray for BorrowedTensor<'_>

Available on non-Apple only.

Auto Trait Implementations§

§

impl<'a> Freeze for BorrowedTensor<'a>

§

impl<'a> RefUnwindSafe for BorrowedTensor<'a>

§

impl<'a> Send for BorrowedTensor<'a>

§

impl<'a> Sync for BorrowedTensor<'a>

§

impl<'a> Unpin for BorrowedTensor<'a>

§

impl<'a> UnsafeUnpin for BorrowedTensor<'a>

§

impl<'a> UnwindSafe for BorrowedTensor<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.