#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Reduction {
#[default]
Mean,
Sum,
None,
}
pub trait ReductionMode: Clone + Default + 'static {
fn as_enum() -> Reduction;
}
#[derive(Debug, Clone, Copy, Default)]
pub struct Mean;
impl ReductionMode for Mean {
fn as_enum() -> Reduction {
Reduction::Mean
}
}
#[derive(Debug, Clone, Copy, Default)]
pub struct Sum;
impl ReductionMode for Sum {
fn as_enum() -> Reduction {
Reduction::Sum
}
}
#[derive(Debug, Clone, Copy, Default)]
pub struct NoneReduction;
impl ReductionMode for NoneReduction {
fn as_enum() -> Reduction {
Reduction::None
}
}
pub trait MseReductionShape<S: crate::shapes::Shape> {
type Output: crate::shapes::Shape;
}
impl<S: crate::shapes::Shape> MseReductionShape<S> for Mean {
type Output = crate::shapes::Nil;
}
impl<S: crate::shapes::Shape> MseReductionShape<S> for Sum {
type Output = crate::shapes::Nil;
}
impl<S: crate::shapes::Shape> MseReductionShape<S> for NoneReduction {
type Output = S;
}
pub trait CrossEntropyReductionShape<S: crate::shapes::Shape> {
type Output: crate::shapes::Shape;
}
impl<S: crate::shapes::Shape> CrossEntropyReductionShape<S> for Mean {
type Output = crate::shapes::Nil;
}
impl<S: crate::shapes::Shape> CrossEntropyReductionShape<S> for Sum {
type Output = crate::shapes::Nil;
}
impl<
S: crate::shapes::Shape
+ crate::shapes::shape_ops::ReduceAt<crate::shapes::idx::Next<crate::shapes::idx::Here>>,
> CrossEntropyReductionShape<S> for NoneReduction
{
type Output = <S as crate::shapes::shape_ops::ReduceAt<
crate::shapes::idx::Next<crate::shapes::idx::Here>,
>>::Output;
}
pub trait BceReductionShape<S: crate::shapes::Shape> {
type Output: crate::shapes::Shape;
}
impl<S: crate::shapes::Shape> BceReductionShape<S> for Mean {
type Output = crate::shapes::Nil;
}
impl<S: crate::shapes::Shape> BceReductionShape<S> for Sum {
type Output = crate::shapes::Nil;
}
impl<S: crate::shapes::Shape> BceReductionShape<S> for NoneReduction {
type Output = S;
}
pub trait L1ReductionShape<S: crate::shapes::Shape> {
type Output: crate::shapes::Shape;
}
impl<S: crate::shapes::Shape> L1ReductionShape<S> for Mean {
type Output = crate::shapes::Nil;
}
impl<S: crate::shapes::Shape> L1ReductionShape<S> for Sum {
type Output = crate::shapes::Nil;
}
impl<S: crate::shapes::Shape> L1ReductionShape<S> for NoneReduction {
type Output = S;
}