argmin_math/ndarray_m/eye.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::ArgminEye;
9use ndarray::Array2;
10
11macro_rules! make_eye {
12 ($t:ty) => {
13 impl ArgminEye for Array2<$t> {
14 #[inline]
15 fn eye_like(&self) -> Array2<$t> {
16 // TODO: Should return an error!
17 assert!(self.is_square());
18 ndarray::Array2::eye(self.dim().0)
19 }
20
21 #[inline]
22 fn eye(n: usize) -> Array2<$t> {
23 ndarray::Array2::eye(n)
24 }
25 }
26 };
27}
28
29make_eye!(i8);
30make_eye!(i16);
31make_eye!(i32);
32make_eye!(i64);
33make_eye!(u8);
34make_eye!(u16);
35make_eye!(u32);
36make_eye!(u64);
37make_eye!(f32);
38make_eye!(f64);
39
40// All code that does not depend on a linked ndarray-linalg backend can still be tested as normal.
41// To avoid dublicating tests and to allow convenient testing of functionality that does not need ndarray-linalg the tests are still included here.
42// The tests expect the name for the crate containing the tested functions to be argmin_math
43#[cfg(test)]
44use crate as argmin_math;
45include!(concat!(
46 env!("CARGO_MANIFEST_DIR"),
47 "/ndarray-tests-src/eye.rs"
48));