faer_core/complex_native/
c32conj_impl.rs

1use crate::complex_native::c32_impl::c32;
2use faer_entity::*;
3use pulp::Simd;
4
5/// 32-bit implicitly conjugated complex floating point type.
6#[allow(non_camel_case_types)]
7#[derive(Copy, Clone, PartialEq)]
8#[repr(C)]
9pub struct c32conj {
10    /// Real part.
11    pub re: f32,
12    /// Imaginary part.
13    pub neg_im: f32,
14}
15
16unsafe impl bytemuck::Zeroable for c32conj {}
17unsafe impl bytemuck::Pod for c32conj {}
18
19impl core::fmt::Debug for c32conj {
20    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
21        self.re.fmt(f)?;
22        let im_abs = self.neg_im.faer_abs();
23        if self.neg_im.is_sign_positive() {
24            f.write_str(" - ")?;
25            im_abs.fmt(f)?;
26        } else {
27            f.write_str(" + ")?;
28            im_abs.fmt(f)?;
29        }
30        f.write_str(" * I")
31    }
32}
33
34impl core::fmt::Display for c32conj {
35    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
36        <Self as core::fmt::Debug>::fmt(self, f)
37    }
38}
39
40unsafe impl Entity for c32conj {
41    type Unit = Self;
42    type Index = u32;
43    type SimdUnit<S: Simd> = S::c32s;
44    type SimdMask<S: Simd> = S::m32s;
45    type SimdIndex<S: Simd> = S::u32s;
46    type Group = IdentityGroup;
47    type Iter<I: Iterator> = I;
48
49    type PrefixUnit<'a, S: Simd> = pulp::Prefix<'a, num_complex::Complex32, S, S::m32s>;
50    type SuffixUnit<'a, S: Simd> = pulp::Suffix<'a, num_complex::Complex32, S, S::m32s>;
51    type PrefixMutUnit<'a, S: Simd> = pulp::PrefixMut<'a, num_complex::Complex32, S, S::m32s>;
52    type SuffixMutUnit<'a, S: Simd> = pulp::SuffixMut<'a, num_complex::Complex32, S, S::m32s>;
53
54    const N_COMPONENTS: usize = 1;
55    const UNIT: GroupCopyFor<Self, ()> = ();
56
57    #[inline(always)]
58    fn faer_first<T>(group: GroupFor<Self, T>) -> T {
59        group
60    }
61
62    #[inline(always)]
63    fn faer_from_units(group: GroupFor<Self, Self::Unit>) -> Self {
64        group
65    }
66
67    #[inline(always)]
68    fn faer_into_units(self) -> GroupFor<Self, Self::Unit> {
69        self
70    }
71
72    #[inline(always)]
73    fn faer_as_ref<T>(group: &GroupFor<Self, T>) -> GroupFor<Self, &T> {
74        group
75    }
76
77    #[inline(always)]
78    fn faer_as_mut<T>(group: &mut GroupFor<Self, T>) -> GroupFor<Self, &mut T> {
79        group
80    }
81
82    #[inline(always)]
83    fn faer_as_ptr<T>(group: *mut GroupFor<Self, T>) -> GroupFor<Self, *mut T> {
84        group
85    }
86
87    #[inline(always)]
88    fn faer_map_impl<T, U>(
89        group: GroupFor<Self, T>,
90        f: &mut impl FnMut(T) -> U,
91    ) -> GroupFor<Self, U> {
92        (*f)(group)
93    }
94
95    #[inline(always)]
96    fn faer_map_with_context<Ctx, T, U>(
97        ctx: Ctx,
98        group: GroupFor<Self, T>,
99        f: &mut impl FnMut(Ctx, T) -> (Ctx, U),
100    ) -> (Ctx, GroupFor<Self, U>) {
101        (*f)(ctx, group)
102    }
103
104    #[inline(always)]
105    fn faer_zip<T, U>(
106        first: GroupFor<Self, T>,
107        second: GroupFor<Self, U>,
108    ) -> GroupFor<Self, (T, U)> {
109        (first, second)
110    }
111    #[inline(always)]
112    fn faer_unzip<T, U>(zipped: GroupFor<Self, (T, U)>) -> (GroupFor<Self, T>, GroupFor<Self, U>) {
113        zipped
114    }
115
116    #[inline(always)]
117    fn faer_into_iter<I: IntoIterator>(iter: GroupFor<Self, I>) -> Self::Iter<I::IntoIter> {
118        iter.into_iter()
119    }
120}
121
122unsafe impl Conjugate for c32conj {
123    type Conj = c32;
124    type Canonical = c32;
125
126    #[inline(always)]
127    fn canonicalize(self) -> Self::Canonical {
128        c32 {
129            re: self.re,
130            im: -self.neg_im,
131        }
132    }
133}