use super::super::meta;
use super::{
ComplexFreqVec, ComplexTimeVec, DataDomain, Domain, DspVec, GenDspVec, MetaData, NumberSpace,
RealFreqVec, RealTimeVec, ResizeOps, ToSlice, Vector,
};
use crate::numbers::*;
pub trait RededicateOps<Other>: RededicateForceOps<Other>
where
Other: MetaData,
{
fn rededicate_from(origin: Other) -> Self;
}
pub trait RededicateForceOps<Other> {
fn rededicate_from_force(origin: Other) -> Self;
fn rededicate_with_runtime_data(origin: Other, is_complex: bool, domain: DataDomain) -> Self;
}
pub trait RededicateToOps<Other>
where
Other: MetaData,
{
fn rededicate(self) -> Other;
}
pub trait ToRealResult {
type RealResult;
}
pub trait ToComplexResult {
type ComplexResult;
}
pub trait ToTimeResult {
type TimeResult;
}
pub trait ToFreqResult {
type FreqResult;
}
pub trait ToRealTimeResult {
type RealTimeResult;
}
impl<S, T> ToRealResult for ComplexTimeVec<S, T>
where
S: ToSlice<T>,
T: RealNumber,
{
type RealResult = RealTimeVec<S, T>;
}
impl<S, T> ToRealResult for ComplexFreqVec<S, T>
where
S: ToSlice<T>,
T: RealNumber,
{
type RealResult = RealFreqVec<S, T>;
}
impl<S, T> ToRealResult for GenDspVec<S, T>
where
S: ToSlice<T>,
T: RealNumber,
{
type RealResult = GenDspVec<S, T>;
}
impl<S, T> ToComplexResult for RealTimeVec<S, T>
where
S: ToSlice<T>,
T: RealNumber,
{
type ComplexResult = ComplexTimeVec<S, T>;
}
impl<S, T> ToComplexResult for RealFreqVec<S, T>
where
S: ToSlice<T>,
T: RealNumber,
{
type ComplexResult = ComplexFreqVec<S, T>;
}
impl<S, T> ToComplexResult for GenDspVec<S, T>
where
S: ToSlice<T>,
T: RealNumber,
{
type ComplexResult = GenDspVec<S, T>;
}
impl<S, T> ToTimeResult for ComplexFreqVec<S, T>
where
S: ToSlice<T>,
T: RealNumber,
{
type TimeResult = ComplexTimeVec<S, T>;
}
impl<S, T> ToTimeResult for GenDspVec<S, T>
where
S: ToSlice<T>,
T: RealNumber,
{
type TimeResult = GenDspVec<S, T>;
}
impl<S, T> ToFreqResult for RealTimeVec<S, T>
where
S: ToSlice<T>,
T: RealNumber,
{
type FreqResult = ComplexFreqVec<S, T>;
}
impl<S, T> ToFreqResult for ComplexTimeVec<S, T>
where
S: ToSlice<T>,
T: RealNumber,
{
type FreqResult = ComplexFreqVec<S, T>;
}
impl<S, T> ToFreqResult for GenDspVec<S, T>
where
S: ToSlice<T>,
T: RealNumber,
{
type FreqResult = GenDspVec<S, T>;
}
impl<S, T> ToRealTimeResult for ComplexFreqVec<S, T>
where
S: ToSlice<T>,
T: RealNumber,
{
type RealTimeResult = RealTimeVec<S, T>;
}
impl<S, T> ToRealTimeResult for GenDspVec<S, T>
where
S: ToSlice<T>,
T: RealNumber,
{
type RealTimeResult = GenDspVec<S, T>;
}
impl<S, T, N, D> RededicateForceOps<DspVec<S, T, N, D>> for RealTimeVec<S, T>
where
S: ToSlice<T>,
T: RealNumber,
N: NumberSpace,
D: Domain,
{
fn rededicate_from_force(origin: DspVec<S, T, N, D>) -> Self {
RealTimeVec {
data: origin.data,
delta: origin.delta,
domain: meta::Time,
number_space: meta::Real,
valid_len: origin.valid_len,
multicore_settings: origin.multicore_settings,
}
}
fn rededicate_with_runtime_data(origin: DspVec<S, T, N, D>, _: bool, _: DataDomain) -> Self {
Self::rededicate_from_force(origin)
}
}
impl<S, T, N, D> RededicateForceOps<DspVec<S, T, N, D>> for RealFreqVec<S, T>
where
S: ToSlice<T>,
T: RealNumber,
N: NumberSpace,
D: Domain,
{
fn rededicate_from_force(origin: DspVec<S, T, N, D>) -> Self {
RealFreqVec {
data: origin.data,
delta: origin.delta,
domain: meta::Freq,
number_space: meta::Real,
valid_len: origin.valid_len,
multicore_settings: origin.multicore_settings,
}
}
fn rededicate_with_runtime_data(origin: DspVec<S, T, N, D>, _: bool, _: DataDomain) -> Self {
Self::rededicate_from_force(origin)
}
}
impl<S, T, N, D> RededicateForceOps<DspVec<S, T, N, D>> for ComplexTimeVec<S, T>
where
S: ToSlice<T>,
T: RealNumber,
N: NumberSpace,
D: Domain,
{
fn rededicate_from_force(origin: DspVec<S, T, N, D>) -> Self {
ComplexTimeVec {
data: origin.data,
delta: origin.delta,
domain: meta::Time,
number_space: meta::Complex,
valid_len: origin.valid_len,
multicore_settings: origin.multicore_settings,
}
}
fn rededicate_with_runtime_data(origin: DspVec<S, T, N, D>, _: bool, _: DataDomain) -> Self {
Self::rededicate_from_force(origin)
}
}
impl<S, T, N, D> RededicateForceOps<DspVec<S, T, N, D>> for ComplexFreqVec<S, T>
where
S: ToSlice<T>,
T: RealNumber,
N: NumberSpace,
D: Domain,
{
fn rededicate_from_force(origin: DspVec<S, T, N, D>) -> Self {
ComplexFreqVec {
data: origin.data,
delta: origin.delta,
domain: meta::Freq,
number_space: meta::Complex,
valid_len: origin.valid_len,
multicore_settings: origin.multicore_settings,
}
}
fn rededicate_with_runtime_data(origin: DspVec<S, T, N, D>, _: bool, _: DataDomain) -> Self {
Self::rededicate_from_force(origin)
}
}
impl<S, T, N, D> RededicateForceOps<DspVec<S, T, N, D>> for GenDspVec<S, T>
where
S: ToSlice<T>,
T: RealNumber,
N: NumberSpace,
D: Domain,
{
fn rededicate_from_force(origin: DspVec<S, T, N, D>) -> Self {
let domain = origin.domain();
let is_complex = origin.is_complex();
GenDspVec {
data: origin.data,
delta: origin.delta,
domain: meta::TimeOrFreq {
domain_current: domain,
},
number_space: meta::RealOrComplex {
is_complex_current: is_complex,
},
valid_len: origin.valid_len,
multicore_settings: origin.multicore_settings,
}
}
fn rededicate_with_runtime_data(
origin: DspVec<S, T, N, D>,
is_complex: bool,
domain: DataDomain,
) -> Self {
let mut result = Self::rededicate_from_force(origin);
result.number_space.is_complex_current = is_complex;
result.domain.domain_current = domain;
result
}
}
impl<S, T, N, D, O> RededicateOps<O> for DspVec<S, T, N, D>
where
S: ToSlice<T>,
T: RealNumber,
DspVec<S, T, N, D>: RededicateForceOps<O>,
N: NumberSpace,
D: Domain,
O: Vector<T>,
{
fn rededicate_from(origin: O) -> Self {
let is_complex = origin.is_complex();
let domain = origin.domain();
let mut result = Self::rededicate_from_force(origin);
if result.is_complex() != is_complex && result.domain() != domain {
result
.resize(0)
.expect("Setting size to 0 should always succeed");
}
result
}
}
impl<S, T, N, D, O> RededicateToOps<O> for DspVec<S, T, N, D>
where
S: ToSlice<T>,
T: RealNumber,
N: NumberSpace,
D: Domain,
O: Vector<T> + RededicateOps<Self>,
{
fn rededicate(self) -> O {
O::rededicate_from(self)
}
}