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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
macro_rules! define_complex_operations_forward { (from: $name:ident, to: $gen_type:ident, complex: $complex_type:ident, real_partner: $real_partner:ident, $($data_type:ident),*) => { $( impl ComplexVectorOperations<$data_type> for $name<$data_type> { type RealPartner = $real_partner<$data_type>; fn complex_data(&self) -> &[Complex<$data_type>] { self.to_gen_borrow().complex_data() } fn complex_offset(self, offset: Complex<$data_type>) -> VecResult<Self> { Self::from_genres(self.to_gen().complex_offset(offset)) } fn complex_scale(self, factor: Complex<$data_type>) -> VecResult<Self> { Self::from_genres(self.to_gen().complex_scale(factor)) } fn multiply_complex_exponential(self, a: $data_type, b: $data_type) -> VecResult<Self> { Self::from_genres(self.to_gen().multiply_complex_exponential(a, b)) } fn magnitude(self) -> VecResult<Self::RealPartner> { Self::RealPartner::from_genres(self.to_gen().magnitude()) } fn get_magnitude(&self, destination: &mut Self::RealPartner) -> VoidResult { self.to_gen_borrow().get_magnitude(destination.to_gen_mut_borrow()) } fn magnitude_squared(self) -> VecResult<Self::RealPartner> { Self::RealPartner::from_genres(self.to_gen().magnitude_squared()) } fn complex_conj(self) -> VecResult<Self> { Self::from_genres(self.to_gen().complex_conj()) } fn to_real(self) -> VecResult<Self::RealPartner> { Self::RealPartner::from_genres(self.to_gen().to_real()) } fn to_imag(self) -> VecResult<Self::RealPartner> { Self::RealPartner::from_genres(self.to_gen().to_imag()) } fn get_real(&self, destination: &mut Self::RealPartner) -> VoidResult { self.to_gen_borrow().get_real(destination.to_gen_mut_borrow()) } fn get_imag(&self, destination: &mut Self::RealPartner) -> VoidResult { self.to_gen_borrow().get_imag(destination.to_gen_mut_borrow()) } fn phase(self) -> VecResult<Self::RealPartner> { Self::RealPartner::from_genres(self.to_gen().phase()) } fn get_phase(&self, destination: &mut Self::RealPartner) -> VoidResult { self.to_gen_borrow().get_phase(destination.to_gen_mut_borrow()) } fn complex_dot_product(&self, factor: &Self) -> ScalarResult<Complex<$data_type>> { self.to_gen_borrow().complex_dot_product(&factor.to_gen_borrow()) } fn complex_statistics(&self) -> Statistics<Complex<$data_type>> { self.to_gen_borrow().complex_statistics() } fn complex_statistics_splitted(&self, len: usize) -> Vec<Statistics<Complex<$data_type>>> { self.to_gen_borrow().complex_statistics_splitted(len) } fn get_real_imag(&self, real: &mut Self::RealPartner, imag: &mut Self::RealPartner) -> VoidResult { self.to_gen_borrow().get_real_imag(real.to_gen_mut_borrow(), imag.to_gen_mut_borrow()) } fn get_mag_phase(&self, mag: &mut Self::RealPartner, phase: &mut Self::RealPartner) -> VoidResult { self.to_gen_borrow().get_mag_phase(mag.to_gen_mut_borrow(), phase.to_gen_mut_borrow()) } fn set_real_imag(self, real: &Self::RealPartner, imag: &Self::RealPartner) -> VecResult<Self> { Self::from_genres(self.to_gen().set_real_imag(real.to_gen_borrow(), imag.to_gen_borrow())) } fn set_mag_phase(self, mag: &Self::RealPartner, phase: &Self::RealPartner) -> VecResult<Self> { Self::from_genres(self.to_gen().set_mag_phase(mag.to_gen_borrow(), phase.to_gen_borrow())) } } impl $name<$data_type> { fn to_gen(self) -> $gen_type<$data_type> { unsafe { mem::transmute(self) } } fn to_gen_borrow(&self) -> &$gen_type<$data_type> { unsafe { mem::transmute(self) } } fn from_gen(other: $gen_type<$data_type>) -> Self { unsafe { mem::transmute(other) } } fn from_genres(other: VecResult<$gen_type<$data_type>>) -> VecResult<Self> { match other { Ok(v) => Ok($name::<$data_type>::from_gen(v)), Err((r, v)) => Err((r, $name::<$data_type>::from_gen(v))) } } } impl Scale<Complex<$data_type>> for $name<$data_type> { fn scale(self, offset: Complex<$data_type>) -> VecResult<Self> { self.complex_scale(offset) } } impl Offset<Complex<$data_type>> for $name<$data_type> { fn offset(self, offset: Complex<$data_type>) -> VecResult<Self> { self.complex_offset(offset) } } )* } }