Skip to main content

Dest

Enum Dest 

Source
#[non_exhaustive]
pub enum Dest<W> { Overwrite(W), Accumulate(W), Scaled { out: W, alpha: ContractionScalar, beta: ContractionScalar, }, }
Expand description

Where an _into operation writes, and how it combines with what is there.

W is TensorWrite<'a> for dtype-erased outputs and TypedTensorWrite<'a, T> for typed outputs.

§Examples

use tenferro_tensor::{Dest, DestMode, Tensor, TensorWrite};

let mut out = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?;
let dest: Dest<TensorWrite<'_>> = Dest::scaled(&mut out, 2.0_f64, 0.5_f64);
assert_eq!(dest.mode(), DestMode::Scaled);
assert_eq!(dest.target().shape(), &[2]);

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Overwrite(W)

out = op(...); the previous contents are never read.

§

Accumulate(W)

out = op(...) + out.

§

Scaled

out = alpha * op(...) + beta * out; with beta == 0 the previous contents are never read (NaN or -0 in out does not leak).

Fields

§out: W

The destination.

§alpha: ContractionScalar

Scale applied to the operation result.

§beta: ContractionScalar

Scale applied to the previous contents of out.

Implementations§

Source§

impl<W> Dest<W>

Source

pub fn overwrite(out: impl Into<W>) -> Self

Build an Dest::Overwrite destination.

§Examples
use tenferro_tensor::{Dest, DestMode, Tensor, TensorWrite};

let mut t = Tensor::from_vec_col_major(vec![1], vec![0.0_f64])?;
let dest: Dest<TensorWrite<'_>> = Dest::overwrite(&mut t);
assert_eq!(dest.mode(), DestMode::Overwrite);
Source

pub fn accumulate(out: impl Into<W>) -> Self

Build an Dest::Accumulate destination.

§Examples
use tenferro_tensor::{Dest, DestMode, Tensor, TensorWrite};

let mut t = Tensor::from_vec_col_major(vec![1], vec![0.0_f64])?;
let dest: Dest<TensorWrite<'_>> = Dest::accumulate(&mut t);
assert_eq!(dest.mode(), DestMode::Accumulate);
Source

pub fn scaled( out: impl Into<W>, alpha: impl Into<ContractionScalar>, beta: impl Into<ContractionScalar>, ) -> Self

Build a Dest::Scaled destination, out = alpha * op + beta * out.

§Examples
use tenferro_tensor::{Dest, DestMode, Tensor, TensorWrite};

let mut t = Tensor::from_vec_col_major(vec![1], vec![0.0_f64])?;
let dest: Dest<TensorWrite<'_>> = Dest::scaled(&mut t, 1.0_f64, 0.0_f64);
assert_eq!(dest.mode(), DestMode::Scaled);
Source

pub fn mode(&self) -> DestMode

Return which variant this destination is, without its target.

§Examples
use tenferro_tensor::{Dest, DestMode};

let dest = Dest::Overwrite(());
assert_eq!(dest.mode(), DestMode::Overwrite);
Source

pub fn target(&self) -> &W

Borrow the destination.

§Examples
use tenferro_tensor::Dest;

let dest = Dest::Accumulate(7);
assert_eq!(*dest.target(), 7);
Source

pub fn into_target(self) -> W

Consume the destination and return its target.

§Examples
use tenferro_tensor::Dest;

assert_eq!(Dest::Overwrite(7).into_target(), 7);

Trait Implementations§

Source§

impl<W: Debug> Debug for Dest<W>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<W> Freeze for Dest<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for Dest<W>
where W: RefUnwindSafe,

§

impl<W> Send for Dest<W>
where W: Send,

§

impl<W> Sync for Dest<W>
where W: Sync,

§

impl<W> Unpin for Dest<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for Dest<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for Dest<W>
where W: UnwindSafe,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.