haar_lib/algebra/
affine_sum.rs1pub use crate::algebra::{action::Action, affine::Affine, dual::Dual, 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 AffineSum<T, U = T>(PhantomData<(T, U)>);
10
11impl<T, U> Action for AffineSum<T, U>
12where
13 Sum<T>: Monoid,
14 Affine<U>: Monoid,
15 T: Add<Output = T> + Mul<Output = T> + TryFrom<U, Error: Debug>,
16 U: Mul<Output = U> + TryFrom<usize, Error: Debug>,
17{
18 type Output = Sum<T>;
19 type Lazy = Dual<Affine<U>>;
20
21 fn convert(value: Self::Output, lazy: Self::Lazy, len: usize) -> Self::Output {
22 let len = U::try_from(len).unwrap();
23 let Dual(lazy) = lazy;
24 Sum(T::try_from(lazy.0).unwrap() * value.0 + T::try_from(lazy.1 * len).unwrap())
25 }
26}