argmin_math/ndarray_m/
sub.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::ArgminSub;
9use ndarray::{Array1, Array2};
10use num_complex::Complex;
11
12macro_rules! make_sub {
13    ($t:ty) => {
14        impl ArgminSub<$t, Array1<$t>> for Array1<$t> {
15            #[inline]
16            fn sub(&self, other: &$t) -> Array1<$t> {
17                self - *other
18            }
19        }
20
21        impl ArgminSub<Array1<$t>, Array1<$t>> for $t {
22            #[inline]
23            fn sub(&self, other: &Array1<$t>) -> Array1<$t> {
24                *self - other
25            }
26        }
27
28        impl ArgminSub<Array1<$t>, Array1<$t>> for Array1<$t> {
29            #[inline]
30            fn sub(&self, other: &Array1<$t>) -> Array1<$t> {
31                self - other
32            }
33        }
34
35        impl ArgminSub<Array2<$t>, Array2<$t>> for Array2<$t> {
36            #[inline]
37            fn sub(&self, other: &Array2<$t>) -> Array2<$t> {
38                self - other
39            }
40        }
41
42        impl ArgminSub<$t, Array2<$t>> for Array2<$t> {
43            #[inline]
44            fn sub(&self, other: &$t) -> Array2<$t> {
45                self - *other
46            }
47        }
48    };
49}
50
51make_sub!(i8);
52make_sub!(i16);
53make_sub!(i32);
54make_sub!(i64);
55make_sub!(u8);
56make_sub!(u16);
57make_sub!(u32);
58make_sub!(u64);
59make_sub!(f32);
60make_sub!(f64);
61make_sub!(Complex<f32>);
62make_sub!(Complex<f64>);
63
64// All code that does not depend on a linked ndarray-linalg backend can still be tested as normal.
65// To avoid dublicating tests and to allow convenient testing of functionality that does not need ndarray-linalg the tests are still included here.
66// The tests expect the name for the crate containing the tested functions to be argmin_math
67#[cfg(test)]
68use crate as argmin_math;
69include!(concat!(
70    env!("CARGO_MANIFEST_DIR"),
71    "/ndarray-tests-src/sub.rs"
72));