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>
impl<'a> Output<'a>
Sourcepub fn read(&self) -> TensorRead<'_>
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]);Sourcepub fn into_owned(self) -> Option<Tensor>
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());Sourcepub fn into_tensor(self, engine: &mut dyn Engine) -> Result<Tensor>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more