#[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: WThe destination.
§
alpha: ContractionScalarScale applied to the operation result.
§
beta: ContractionScalarScale applied to the previous contents of out.
Implementations§
Source§impl<W> Dest<W>
impl<W> Dest<W>
Sourcepub fn overwrite(out: impl Into<W>) -> Self
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);Sourcepub fn accumulate(out: impl Into<W>) -> Self
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);Sourcepub fn scaled(
out: impl Into<W>,
alpha: impl Into<ContractionScalar>,
beta: impl Into<ContractionScalar>,
) -> Self
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);Sourcepub fn mode(&self) -> DestMode
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);Sourcepub fn target(&self) -> &W
pub fn target(&self) -> &W
Borrow the destination.
§Examples
use tenferro_tensor::Dest;
let dest = Dest::Accumulate(7);
assert_eq!(*dest.target(), 7);Sourcepub fn into_target(self) -> W
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§
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> 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