haar_lib/algebra/
affine.rs

1//! 一次関数の合成
2pub use crate::algebra::traits::*;
3pub use crate::num::one_zero::*;
4use std::ops::{Add, Mul};
5
6/// 一次関数の合成を演算とする代数的構造
7#[derive(Clone, Copy, Default, Debug, PartialEq, Eq)]
8pub struct Affine<T>(pub T, pub T);
9
10impl<T> Set for Affine<T> {}
11
12impl<T: Add<Output = T> + Mul<Output = T> + Copy> BinaryOp for Affine<T> {
13    fn op(self, b: Self) -> Self {
14        Self(self.0 * b.0, self.0 * b.1 + self.1)
15    }
16}
17
18impl<T: One + Zero + Copy> Identity for Affine<T> {
19    fn id() -> Self {
20        Self(T::one(), T::zero())
21    }
22}
23
24impl<T> Associative for Affine<T> {}