Trait dfdx::tensor_ops::SumTo
source · pub trait SumTo: HasErr + HasShape {
// Required method
fn try_sum<Dst: Shape, Ax: Axes>(
self
) -> Result<Self::WithShape<Dst>, Self::Err>
where Self::Shape: ReduceShapeTo<Dst, Ax>;
// Provided method
fn sum<Dst: Shape, Ax: Axes>(self) -> Self::WithShape<Dst>
where Self::Shape: ReduceShapeTo<Dst, Ax> { ... }
}
Expand description
Reduction along multiple axes using sum
.
Required Methods§
sourcefn try_sum<Dst: Shape, Ax: Axes>(
self
) -> Result<Self::WithShape<Dst>, Self::Err>where
Self::Shape: ReduceShapeTo<Dst, Ax>,
fn try_sum<Dst: Shape, Ax: Axes>( self ) -> Result<Self::WithShape<Dst>, Self::Err>where Self::Shape: ReduceShapeTo<Dst, Ax>,
Fallible version of SumTo::sum
Provided Methods§
sourcefn sum<Dst: Shape, Ax: Axes>(self) -> Self::WithShape<Dst>where
Self::Shape: ReduceShapeTo<Dst, Ax>,
fn sum<Dst: Shape, Ax: Axes>(self) -> Self::WithShape<Dst>where Self::Shape: ReduceShapeTo<Dst, Ax>,
Sum reduction. Pytorch equivalent: t.sum(Ax)
Example reducing a single axis:
let t: Tensor<Rank2<2, 3>, f32, _> = dev.tensor([[1.0, 2.0, 3.0], [-1.0, -2.0, -3.0]]);
let r = t.sum::<Rank1<2>, _>(); // or `sum::<_, Axis<1>>()`
assert_eq!(r.array(), [6.0, -6.0]);
Reducing multiple axes:
let r = t.sum::<Rank0, _>(); // or `sum::<_, Axes2<0, 1>>()`
assert_eq!(r.array(), 0.0);