use crate::ScaletError;
use crate::spetrum_arith::SpectrumArithmeticFactory;
use num_traits::{AsPrimitive, MulAdd, Num, Zero};
use pxfm::{
f_exp, f_exp2, f_exp2f, f_expf, f_log2, f_log2f, f_pow, f_powf, f_rsqrt, f_rsqrtf, f_sincos,
f_sincosf,
};
use std::fmt::{Debug, Display};
use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub};
use std::sync::Arc;
use zaft::{FftDirection, FftExecutor, Zaft};
pub trait CwtSample:
MulAdd<Self, Output = Self>
+ AddAssign
+ MulAssign
+ 'static
+ Copy
+ Clone
+ Send
+ Sync
+ Num
+ Default
+ Neg<Output = Self>
+ Add<Self, Output = Self>
+ Mul<Self, Output = Self>
+ Div<Self, Output = Self>
+ Sub<Self, Output = Self>
+ Debug
+ Display
+ Zero
+ PartialOrd
+ AsPrimitive<usize>
+ AsPrimitive<isize>
+ AsPrimitive<f32>
+ SpectrumArithmeticFactory
{
fn pow(self, other: Self) -> Self;
fn exp(self) -> Self;
fn exp2(self) -> Self;
fn rsqrt(self) -> Self;
fn log2(self) -> Self;
fn ceil(self) -> Self;
fn floor(self) -> Self;
fn fract(self) -> Self;
fn min(self, other: Self) -> Self;
fn max(self, other: Self) -> Self;
fn abs(self) -> Self;
fn sqrt(self) -> Self;
fn copysign(self, other: Self) -> Self;
fn make_fft(
length: usize,
fft_direction: FftDirection,
) -> Result<Arc<dyn FftExecutor<Self> + Send + Sync>, ScaletError>;
fn sincos(self) -> (Self, Self);
const NEG_INFINITY: Self;
const INFINITY: Self;
const PI: Self;
const FRAC_1_PI: Self;
const TWO_PI: Self;
const TWO_SQRT_BY_PI_POWER_0_25: Self;
const TWO_S2_OVER_3_PI_POWER_M0_25: Self;
const TWO_OVER_5_SQ_PI_POWER_M0_25: Self;
}
impl CwtSample for f32 {
#[inline]
fn pow(self, other: Self) -> Self {
f_powf(self, other)
}
#[inline]
fn exp(self) -> Self {
f_expf(self)
}
#[inline]
fn exp2(self) -> Self {
f_exp2f(self)
}
#[inline]
fn rsqrt(self) -> Self {
f_rsqrtf(self)
}
#[inline]
fn log2(self) -> Self {
f_log2f(self)
}
#[inline]
fn ceil(self) -> Self {
f32::ceil(self)
}
#[inline]
fn floor(self) -> Self {
f32::floor(self)
}
#[inline]
fn fract(self) -> Self {
f32::fract(self)
}
#[inline]
fn abs(self) -> Self {
f32::abs(self)
}
#[inline]
fn min(self, other: Self) -> Self {
f32::min(self, other)
}
#[inline]
fn max(self, other: Self) -> Self {
f32::max(self, other)
}
#[inline]
fn sqrt(self) -> Self {
f32::sqrt(self)
}
#[inline]
fn copysign(self, other: Self) -> Self {
f32::copysign(self, other)
}
#[inline]
fn sincos(self) -> (Self, Self) {
f_sincosf(self)
}
fn make_fft(
length: usize,
fft_direction: FftDirection,
) -> Result<Arc<dyn FftExecutor<Self> + Send + Sync>, ScaletError> {
match fft_direction {
FftDirection::Forward => {
Zaft::make_forward_fft_f32(length).map_err(|x| ScaletError::FftError(x.to_string()))
}
FftDirection::Inverse => {
Zaft::make_inverse_fft_f32(length).map_err(|x| ScaletError::FftError(x.to_string()))
}
}
}
const INFINITY: Self = f32::INFINITY;
const NEG_INFINITY: Self = f32::NEG_INFINITY;
const PI: Self = f32::from_bits(0x40490fdb);
const FRAC_1_PI: Self = f32::from_bits(0x3ea2f983);
const TWO_PI: Self = f32::from_bits(0x40c90fdb);
const TWO_SQRT_BY_PI_POWER_0_25: Self = f32::from_bits(0x3ff0ff58);
const TWO_S2_OVER_3_PI_POWER_M0_25: Self = f32::from_bits(0x3f9d00ab);
const TWO_OVER_5_SQ_PI_POWER_M0_25: Self = f32::from_bits(0x3f2bfcdd);
}
impl CwtSample for f64 {
#[inline]
fn pow(self, other: Self) -> Self {
f_pow(self, other)
}
#[inline]
fn exp(self) -> Self {
f_exp(self)
}
#[inline]
fn exp2(self) -> Self {
f_exp2(self)
}
#[inline]
fn rsqrt(self) -> Self {
f_rsqrt(self)
}
#[inline]
fn log2(self) -> Self {
f_log2(self)
}
#[inline]
fn ceil(self) -> Self {
f64::ceil(self)
}
#[inline]
fn floor(self) -> Self {
f64::floor(self)
}
#[inline]
fn fract(self) -> Self {
f64::fract(self)
}
#[inline]
fn abs(self) -> Self {
f64::abs(self)
}
#[inline]
fn min(self, other: Self) -> Self {
f64::min(self, other)
}
#[inline]
fn max(self, other: Self) -> Self {
f64::max(self, other)
}
#[inline]
fn sqrt(self) -> Self {
f64::sqrt(self)
}
#[inline]
fn copysign(self, other: Self) -> Self {
f64::copysign(self, other)
}
#[inline]
fn sincos(self) -> (Self, Self) {
f_sincos(self)
}
fn make_fft(
length: usize,
fft_direction: FftDirection,
) -> Result<Arc<dyn FftExecutor<Self> + Send + Sync>, ScaletError> {
match fft_direction {
FftDirection::Forward => {
Zaft::make_forward_fft_f64(length).map_err(|x| ScaletError::FftError(x.to_string()))
}
FftDirection::Inverse => {
Zaft::make_inverse_fft_f64(length).map_err(|x| ScaletError::FftError(x.to_string()))
}
}
}
const INFINITY: Self = f64::INFINITY;
const NEG_INFINITY: Self = f64::NEG_INFINITY;
const FRAC_1_PI: Self = f64::from_bits(0x3fd45f306dc9c883);
const PI: Self = f64::from_bits(0x400921fb54442d18);
const TWO_PI: Self = f64::from_bits(0x401921fb54442d18);
const TWO_SQRT_BY_PI_POWER_0_25: Self = f64::from_bits(0x3ffe1feb0eafec2d);
const TWO_S2_OVER_3_PI_POWER_M0_25: Self = f64::from_bits(0x3ff3a0155e202ded);
const TWO_OVER_5_SQ_PI_POWER_M0_25: Self = f64::from_bits(0x3fe57f9b91b1c6bb);
}