haar_lib/algebra/
add_sum.rs1pub use crate::algebra::{action::Action, sum::Sum, traits::*};
3use std::fmt::Debug;
4use std::marker::PhantomData;
5use std::ops::{Add, Mul};
6
7#[derive(Copy, Clone, Default, Debug, PartialEq, Eq)]
9pub struct AddSum<T, U = T>(PhantomData<(T, U)>);
10
11impl<T, U> Action for AddSum<T, U>
12where
13 Sum<T>: Monoid,
14 Sum<U>: Monoid,
15 T: Add<Output = T> + TryFrom<U, Error: Debug>,
16 U: Mul<Output = U> + TryFrom<usize, Error: Debug>,
17{
18 type Output = Sum<T>;
19 type Lazy = Sum<U>;
20
21 fn convert(value: Self::Output, lazy: Self::Lazy, len: usize) -> Self::Output {
22 Sum(value.0 + T::try_from(lazy.0 * U::try_from(len).unwrap()).unwrap())
23 }
24}