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