argmin_math/ndarray_m/
transpose.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
8// Note: This is not really the preferred way I think. Maybe this should also be implemented for
9// ArrayViews, which would probably make it more efficient.
10
11use crate::ArgminTranspose;
12use ndarray::{Array1, Array2};
13use num_complex::Complex;
14
15macro_rules! make_add {
16    ($t:ty) => {
17        impl ArgminTranspose<Array1<$t>> for Array1<$t> {
18            #[inline]
19            fn t(self) -> Array1<$t> {
20                self.reversed_axes()
21            }
22        }
23
24        impl ArgminTranspose<Array2<$t>> for Array2<$t> {
25            #[inline]
26            fn t(self) -> Array2<$t> {
27                self.reversed_axes()
28            }
29        }
30    };
31}
32
33make_add!(i8);
34make_add!(i16);
35make_add!(i32);
36make_add!(i64);
37make_add!(u8);
38make_add!(u16);
39make_add!(u32);
40make_add!(u64);
41make_add!(f32);
42make_add!(f64);
43make_add!(Complex<f32>);
44make_add!(Complex<f64>);
45
46// All code that does not depend on a linked ndarray-linalg backend can still be tested as normal.
47// To avoid dublicating tests and to allow convenient testing of functionality that does not need ndarray-linalg the tests are still included here.
48// The tests expect the name for the crate containing the tested functions to be argmin_math
49#[cfg(test)]
50use crate as argmin_math;
51include!(concat!(
52    env!("CARGO_MANIFEST_DIR"),
53    "/ndarray-tests-src/transpose.rs"
54));