Trait dfdx::tensor_ops::TryStack

source ·
pub trait TryStack: Sized {
    type Stacked;
    type Err: Debug;

    // Required method
    fn try_stack(self) -> Result<Self::Stacked, Self::Err>;

    // Provided method
    fn stack(self) -> Self::Stacked { ... }
}
Expand description

Stack an array or vec of tensors together along a new dimension.

An array of tensors will be turned into a Const dim, and a Vec of tensors will be turned into a usize dim.

Pytorch equivalent torch.stack.

Stacking with an array:

let a: Tensor<Rank2<3, 4>, f32, _> = dev.zeros();
let b: Tensor<Rank2<3, 4>, f32, _> = dev.zeros();
let _: Tensor<Rank3<2, 3, 4>, f32, _> = [a, b].stack();

Stacking with a vec:

let a: Tensor<Rank2<3, 4>, f32, _> = dev.zeros();
let b: Tensor<Rank2<3, 4>, f32, _> = dev.zeros();
let _: Tensor<(usize, Const<3>, Const<4>), f32, _> = vec![a, b].stack();

Required Associated Types§

Required Methods§

source

fn try_stack(self) -> Result<Self::Stacked, Self::Err>

Fallible version of TryStack::stack

Provided Methods§

source

fn stack(self) -> Self::Stacked

Stack an array or vec of tensors together along a new dimension.

Implementations on Foreign Types§

source§

impl<S, E: Dtype, D: StackKernel<E>, T, const N: usize> TryStack for [Tensor<S, E, D, T>; N]where S: AddDim<Const<N>> + Shape, T: Tape<E, D>,

§

type Stacked = Tensor<<S as AddDim<Const<N>>>::Larger, E, D, T>

§

type Err = <D as HasErr>::Err

source§

fn try_stack(self) -> Result<Self::Stacked, Self::Err>

source§

impl<A: TryStack, B: TryStack<Err = A::Err>> TryStack for (A, B)

§

type Stacked = (<A as TryStack>::Stacked, <B as TryStack>::Stacked)

§

type Err = <A as TryStack>::Err

source§

fn try_stack(self) -> Result<Self::Stacked, Self::Err>

source§

impl<S, E: Dtype, D: StackKernel<E>, T> TryStack for Vec<Tensor<S, E, D, T>>where S: AddDim<usize> + Shape, T: Tape<E, D>,

§

type Stacked = Tensor<<S as AddDim<usize>>::Larger, E, D, T>

§

type Err = <D as HasErr>::Err

source§

fn try_stack(self) -> Result<Self::Stacked, Self::Err>

Implementors§