argmin_math/ndarray_m/
conj.rs

1// Copyright 2018-2024 argmin developers
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7
8use crate::ArgminConj;
9use ndarray::{Array1, Array2};
10use num_complex::Complex;
11
12macro_rules! make_conj {
13    ($t:ty) => {
14        impl ArgminConj for Array1<$t> {
15            #[inline]
16            fn conj(&self) -> Array1<$t> {
17                self.iter().map(|a| <$t as ArgminConj>::conj(a)).collect()
18            }
19        }
20
21        impl ArgminConj for Array2<$t> {
22            #[inline]
23            fn conj(&self) -> Array2<$t> {
24                let n = self.shape();
25                let mut out = self.clone();
26                for i in 0..n[0] {
27                    for j in 0..n[1] {
28                        out[(i, j)] = out[(i, j)].conj();
29                    }
30                }
31                out
32            }
33        }
34    };
35}
36
37make_conj!(i8);
38make_conj!(i16);
39make_conj!(i32);
40make_conj!(i64);
41make_conj!(f32);
42make_conj!(f64);
43make_conj!(Complex<i8>);
44make_conj!(Complex<i16>);
45make_conj!(Complex<i32>);
46make_conj!(Complex<i64>);
47make_conj!(Complex<f32>);
48make_conj!(Complex<f64>);
49
50// All code that does not depend on a linked ndarray-linalg backend can still be tested as normal.
51// To avoid dublicating tests and to allow convenient testing of functionality that does not need ndarray-linalg the tests are still included here.
52// The tests expect the name for the crate containing the tested functions to be argmin_math
53#[cfg(test)]
54use crate as argmin_math;
55include!(concat!(
56    env!("CARGO_MANIFEST_DIR"),
57    "/ndarray-tests-src/conj.rs"
58));