argmin_math/nalgebra_m/
conj.rs1use crate::{Allocator, ArgminConj};
9
10use nalgebra::{base::dimension::Dim, DefaultAllocator, OMatrix, SimdComplexField};
11
12impl<N, R, C> ArgminConj for OMatrix<N, R, C>
13where
14 N: SimdComplexField,
15 R: Dim,
16 C: Dim,
17 DefaultAllocator: Allocator<N, R, C>,
18{
19 #[inline]
20 fn conj(&self) -> OMatrix<N, R, C> {
21 self.conjugate()
22 }
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28 use approx::assert_relative_eq;
29 use nalgebra::Vector3;
30 use num_complex::Complex;
31 use paste::item;
32
33 macro_rules! make_test {
34 ($t:ty) => {
35 item! {
36 #[test]
37 fn [<test_conj_complex_nalgebra_ $t>]() {
38 let a = Vector3::new(
39 Complex::new(1 as $t, 2 as $t),
40 Complex::new(4 as $t, -3 as $t),
41 Complex::new(8 as $t, 0 as $t)
42 );
43 let b = Vector3::new(
44 Complex::new(1 as $t, -2 as $t),
45 Complex::new(4 as $t, 3 as $t),
46 Complex::new(8 as $t, 0 as $t)
47 );
48 let res = <Vector3<Complex<$t>> as ArgminConj>::conj(&a);
49 for i in 0..3 {
50 assert_relative_eq!(b[i].re, res[i].re, epsilon = $t::EPSILON);
51 assert_relative_eq!(b[i].im, res[i].im, epsilon = $t::EPSILON);
52 }
53 }
54 }
55
56 item! {
57 #[test]
58 fn [<test_conj_nalgebra_ $t>]() {
59 let a = Vector3::new(1 as $t, 4 as $t, 8 as $t);
60 let b = Vector3::new(1 as $t, 4 as $t, 8 as $t);
61 let res = <Vector3<$t> as ArgminConj>::conj(&a);
62 for i in 0..3 {
63 assert_relative_eq!(b[i], res[i], epsilon = $t::EPSILON);
64 }
65 }
66 }
67 };
68 }
69
70 make_test!(f32);
71 make_test!(f64);
72}