argmin_math/ndarray_m/zero.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::{ArgminZero, ArgminZeroLike};
9use num_traits::Zero;
10
11impl<T> ArgminZeroLike for ndarray::Array1<T>
12where
13 T: Zero + ArgminZero + Clone,
14{
15 #[inline]
16 fn zero_like(&self) -> ndarray::Array1<T> {
17 ndarray::Array1::zeros(self.raw_dim())
18 }
19
20 // #[inline]
21 // fn zero() -> ndarray::Array1<T> {
22 // ndarray::Array1::zeros(0)
23 // }
24}
25
26impl<T> ArgminZeroLike for ndarray::Array2<T>
27where
28 T: Zero + ArgminZero + Clone,
29{
30 #[inline]
31 fn zero_like(&self) -> ndarray::Array2<T> {
32 ndarray::Array2::zeros(self.raw_dim())
33 }
34
35 // #[inline]
36 // fn zero() -> ndarray::Array2<T> {
37 // ndarray::Array2::zeros((0, 0))
38 // }
39}
40
41// All code that does not depend on a linked ndarray-linalg backend can still be tested as normal.
42// To avoid dublicating tests and to allow convenient testing of functionality that does not need ndarray-linalg the tests are still included here.
43// The tests expect the name for the crate containing the tested functions to be argmin_math
44#[cfg(test)]
45use crate as argmin_math;
46include!(concat!(
47 env!("CARGO_MANIFEST_DIR"),
48 "/ndarray-tests-src/zero.rs"
49));