Skip to content

Commit

Permalink
make polynomial mul completely generic so it can return a different v…
Browse files Browse the repository at this point in the history
…alue from the arg
  • Loading branch information
xoloki committed Oct 9, 2024
1 parent 2b6d213 commit 50adba3
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,22 @@ impl<Param, Arg> Index<usize> for Polynomial<Param, Arg> {
}
}

impl<Param, Arg, T> Mul<T> for Polynomial<Param, Arg>
impl<Param, Arg, Operand, OpResult> Mul<Operand> for Polynomial<Param, Arg>
where
Param: Clone + Zero + Random + Add + AddAssign<<Arg as Mul<Param>>::Output> + Mul<T>,
Arg: Clone + One + Mul<T> + Mul<Param> + MulAssign,
T: Clone + Zero + Random + Add + AddAssign<<Arg as Mul<T>>::Output>,
Vec<T>: FromIterator<<Param as Mul<T>>::Output>,
Param: Clone
+ Zero
+ Random
+ Add
+ AddAssign<<Arg as Mul<Param>>::Output>
+ Mul<Operand, Output = OpResult>,
Arg: Clone + One + Mul<OpResult> + Mul<Param> + MulAssign,
Operand: Clone,
OpResult: Clone + Zero + Random + Add + AddAssign<<Arg as Mul<OpResult>>::Output>,
Vec<OpResult>: FromIterator<<Param as Mul<Operand>>::Output>,
{
type Output = Polynomial<T, Arg>;
fn mul(self, x: T) -> Self::Output {
let params: Vec<T> = self.params.iter().map(|p| p.clone() * x.clone()).collect();
type Output = Polynomial<OpResult, Arg>;
fn mul(self, x: Operand) -> Self::Output {
let params: Vec<OpResult> = self.params.iter().map(|p| p.clone() * x.clone()).collect();
Polynomial::new(params)
}
}
Expand Down

0 comments on commit 50adba3

Please sign in to comment.