1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
use {RealNumber, array_to_complex_mut};
use multicore_support::*;
use simd_extensions::Simd;
use numbers::*;
use super::super::{Vector, DspVec, ToSliceMut, MetaData, Domain,
                   ComplexNumberSpace};
pub trait ComplexOps<T>
    where T: RealNumber
{
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    fn multiply_complex_exponential(&mut self, a: T, b: T);
    
    
    
    
    
    
    
    
    
    
    
    
    
    fn conj(&mut self);
}
macro_rules! assert_complex {
    ($self_: ident) => {
        if !$self_.is_complex() {
            $self_.number_space.to_real();
            $self_.valid_len = 0;
        }
    }
}
impl<S, T, N, D> ComplexOps<T> for DspVec<S, T, N, D>
    where S: ToSliceMut<T>,
          T: RealNumber,
          N: ComplexNumberSpace,
          D: Domain
{
    fn multiply_complex_exponential(&mut self, a: T, b: T) {
        assert_complex!(self);
        let a = a * self.delta();
        let b = b * self.delta();
        let data_length = self.len();
        let mut array = self.data.to_slice_mut();
        Chunk::execute_with_range(Complexity::Small,
                                  &self.multicore_settings,
                                  &mut array[0..data_length],
                                  T::Reg::len(),
                                  (a, b),
                                  move |array, range, args| {
            let two = T::one() + T::one();
            let (a, b) = args;
            let mut exponential =
                Complex::<T>::from_polar(&T::one(), &b) *
                Complex::<T>::from_polar(&T::one(),
                                         &(a * T::from(range.start).unwrap() / two));
            let increment = Complex::<T>::from_polar(&T::one(), &a);
            let array = array_to_complex_mut(array);
            for complex in array {
                *complex = (*complex) * exponential;
                exponential = exponential * increment;
            }
        });
    }
    fn conj(&mut self) {
        assert_complex!(self);
        let factor = T::Reg::from_complex(Complex::<T>::new(T::one(), -T::one()));
        self.simd_complex_operation(|x, y| x * y, |x, _| x.conj(), factor, Complexity::Small)
    }
}