concision_core/activate/impls/
impl_binary.rs1use crate::activate::{Heavyside, utils::heavyside};
6use ndarray::{Array, ArrayBase, Data, Dimension};
7
8macro_rules! impl_heavyside {
9 ($($ty:ty),* $(,)*) => {
10 $(impl_heavyside!(@impl $ty);)*
11 };
12 (@impl $ty:ty) => {
13 impl Heavyside for $ty {
14 type Output = $ty;
15
16 fn heavyside(self) -> Self::Output {
17 heavyside(self)
18 }
19 }
20 };
21}
22
23impl_heavyside!(
24 f32, f64, i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize,
25);
26
27impl<A, B, S, D> Heavyside for ArrayBase<S, D>
28where
29 A: Clone + Heavyside<Output = B>,
30 D: Dimension,
31 S: Data<Elem = A>,
32{
33 type Output = Array<B, D>;
34
35 fn heavyside(self) -> Self::Output {
36 self.mapv(Heavyside::heavyside)
37 }
38}
39
40impl<'a, A, B, S, D> Heavyside for &'a ArrayBase<S, D>
41where
42 A: Clone + Heavyside<Output = B>,
43 D: Dimension,
44 S: Data<Elem = A>,
45{
46 type Output = Array<B, D>;
47
48 fn heavyside(self) -> Self::Output {
49 self.mapv(Heavyside::heavyside)
50 }
51}