Skip to main content

Output

Enum Output 

Source
pub enum Output<'a> {
    Owned(Tensor),
    Borrowed(TensorRead<'a>),
}
Expand description

One output of crate::Runtime::run.

A value the program computed is returned as a new tensor with a compact layout. An output that is just one of the inputs, or a view of one, is returned as that input’s view instead of a copy; Rust’s borrow rules keep the input alive for as long as the output is used.

§Examples

use tenferro_runtime::Output;
use tenferro_tensor::{Tensor, TensorRead};

let tensor = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0]).unwrap();
let output = Output::Borrowed(TensorRead::from_tensor(&tensor));
assert_eq!(output.read().shape(), &[2]);
let owned = Output::Owned(Tensor::from_vec_col_major(vec![1], vec![3.0_f64]).unwrap());
assert!(owned.into_owned().is_some());

Variants§

§

Owned(Tensor)

A tensor the program computed.

§

Borrowed(TensorRead<'a>)

One of the inputs, or a view of one, returned without a copy.

Implementations§

Source§

impl<'a> Output<'a>

Source

pub fn read(&self) -> TensorRead<'_>

Read the output, owned or borrowed.

§Examples
use tenferro_runtime::Output;
use tenferro_tensor::Tensor;
let output = Output::Owned(Tensor::from_vec_col_major(vec![1], vec![1.0_f64]).unwrap());
assert_eq!(output.read().shape(), &[1]);
Source

pub fn into_owned(self) -> Option<Tensor>

The owned tensor, or None for a borrowed output.

§Examples
use tenferro_runtime::Output;
use tenferro_tensor::{Tensor, TensorRead};
let tensor = Tensor::from_vec_col_major(vec![1], vec![1.0_f64]).unwrap();
assert!(Output::Borrowed(TensorRead::from_tensor(&tensor)).into_owned().is_none());
Source

pub fn into_tensor(self, engine: &mut dyn Engine) -> Result<Tensor>

The output as an owned tensor, copying a borrowed output on engine.

§Examples
use tenferro_runtime::Output;
use tenferro_tensor::{Engine, Tensor};

fn owned(output: Output<'_>, engine: &mut dyn Engine) -> tenferro_tensor::Result<Tensor> {
    output.into_tensor(engine)
}
§Errors

Returns tenferro_tensor::Error::BackendFailure or tenferro_tensor::Error::BackendSource when copying a borrowed output through the engine fails; an owned output never fails.

Trait Implementations§

Source§

impl Debug for Output<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Output<'a>

§

impl<'a> !UnwindSafe for Output<'a>

§

impl<'a> Freeze for Output<'a>

§

impl<'a> Send for Output<'a>

§

impl<'a> Sync for Output<'a>

§

impl<'a> Unpin for Output<'a>

§

impl<'a> UnsafeUnpin for Output<'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.