use ark_ff::FftField;
use ark_poly::{Evaluations, Radix2EvaluationDomain};
use rayon::prelude::*;
pub trait ExtendedEvaluations<F: FftField> {
fn scale(&self, elm: F) -> Self;
fn square(&self) -> Self;
fn pow(&self, pow: usize) -> Self;
fn shift(&self, len: usize) -> Self;
}
impl<F: FftField> ExtendedEvaluations<F> for Evaluations<F, Radix2EvaluationDomain<F>> {
fn scale(&self, elm: F) -> Self {
let mut result = self.clone();
result.evals.par_iter_mut().for_each(|coeff| *coeff *= &elm);
result
}
fn square(&self) -> Self {
let mut result = self.clone();
result.evals.par_iter_mut().for_each(|e| {
let _ = e.square_in_place();
});
result
}
fn pow(&self, pow: usize) -> Self {
let mut result = self.clone();
result
.evals
.par_iter_mut()
.for_each(|e| *e = e.pow([pow as u64]));
result
}
fn shift(&self, len: usize) -> Self {
let len = len % self.evals.len();
let mut result = self.clone();
result.evals.clear();
result.evals = self.evals[len..].to_vec();
let mut tail = self.evals[0..len].to_vec();
result.evals.append(&mut tail);
result
}
}