use num_complex::Complex;
use num_traits::{Float, FloatConst, NumAssign};
use crate::traits::{ ComplexFloatIterable, ExtendableIterable };
pub fn pad_clone<F, I>(x: &I, padding: Complex<F>, n: usize) -> I
where
F: Float + FloatConst + NumAssign + 'static,
I: ComplexFloatIterable<F>
{
let pad_iter = core::iter::repeat(padding).take(n);
I::from_iter(x.iter().cloned().chain(pad_iter))
}
pub fn pad_to_nearest_power_of_two_clone<F, I>(x: &I, padding: Complex<F>) -> I
where
F: Float + FloatConst + NumAssign + 'static,
I: ComplexFloatIterable<F> + Clone,
{
let n = x.iter().len();
if n.is_power_of_two() {
x.clone()
} else {
pad_clone(x, padding, n.next_power_of_two() - n) }
}
pub fn zero_pad_clone<F, I>(x: &I, n: usize) -> I
where
F: Float + FloatConst + NumAssign + 'static,
I: ComplexFloatIterable<F>
{
pad_clone(x, Complex::new(F::zero(), F::zero()), n)
}
pub fn zero_pad_to_nearest_power_of_two_clone<F, I>(x: &I) -> I
where
F: Float + FloatConst + NumAssign + 'static,
I: ComplexFloatIterable<F> + Clone
{
pad_to_nearest_power_of_two_clone(x, Complex::new(F::zero(), F::zero()))
}
pub fn pad_inplace<F, I>(x: &mut I, padding: Complex<F>, n: usize)
where
F: Float + FloatConst + NumAssign + 'static,
I: ComplexFloatIterable<F> + ExtendableIterable
{
let pad_iter = core::iter::repeat(padding).take(n);
for p in pad_iter {
x.push(p)
}
}
pub fn zero_pad_inplace<F, I>(x: &mut I, n: usize)
where
F: Float + FloatConst + NumAssign + 'static,
I: ComplexFloatIterable<F> + ExtendableIterable
{
pad_inplace(x, Complex::new(F::zero(), F::zero()), n)
}
pub fn pad_to_nearest_power_of_two_inplace<F, I>(x: &mut I, padding: Complex<F>)
where
F: Float + FloatConst + NumAssign + 'static,
I: ComplexFloatIterable<F> + ExtendableIterable
{
let n = x.iter().len();
if !n.is_power_of_two() {
pad_inplace(x, padding, n.next_power_of_two() - n) }
}
pub fn zero_pad_to_nearest_power_of_two_inplace<F, I>(x: &mut I)
where
F: Float + FloatConst + NumAssign + 'static,
I: ComplexFloatIterable<F> + ExtendableIterable
{
pad_to_nearest_power_of_two_inplace(x, Complex::new(F::zero(), F::zero()))
}