use ruda_kernel::dsl as kernel_dsl;
use ruda_kernel::dsl::prelude::*;
pub trait CumulativeOpFamily: Send + Sync + 'static {
type CumulativeOp<C: Numeric>: CumulativeOp<C>;
}
#[ruda]
pub trait CumulativeOp<C: Numeric>: 'static + Send + Sync {
fn execute(lhs: C, rhs: C) -> C;
fn init_value(first_element: C) -> C;
}
pub(super) struct SumOp;
pub(super) struct ProdOp;
pub(super) struct MaxOp;
pub(super) struct MinOp;
impl CumulativeOpFamily for SumOp {
type CumulativeOp<C: Numeric> = Self;
}
impl CumulativeOpFamily for ProdOp {
type CumulativeOp<C: Numeric> = Self;
}
impl CumulativeOpFamily for MaxOp {
type CumulativeOp<C: Numeric> = Self;
}
impl CumulativeOpFamily for MinOp {
type CumulativeOp<C: Numeric> = Self;
}
#[ruda]
impl<N: Numeric> CumulativeOp<N> for SumOp {
fn execute(lhs: N, rhs: N) -> N {
lhs + rhs
}
fn init_value(_first_element: N) -> N {
N::zero()
}
}
#[ruda]
impl<N: Numeric> CumulativeOp<N> for ProdOp {
fn execute(lhs: N, rhs: N) -> N {
lhs * rhs
}
fn init_value(_first_element: N) -> N {
N::from_int(1)
}
}
#[ruda]
impl<N: Numeric> CumulativeOp<N> for MaxOp {
fn execute(lhs: N, rhs: N) -> N {
max(lhs, rhs)
}
fn init_value(first_element: N) -> N {
first_element
}
}
#[ruda]
impl<N: Numeric> CumulativeOp<N> for MinOp {
fn execute(lhs: N, rhs: N) -> N {
min(lhs, rhs)
}
fn init_value(first_element: N) -> N {
first_element
}
}