image_dwt/
aggregate.rs

1use ndarray::{Array2, Array3};
2
3pub trait Aggregate {
4    fn min(&self) -> f32;
5    fn max(&self) -> f32;
6}
7
8impl Aggregate for Array2<f32> {
9    fn min(&self) -> f32 {
10        *self
11            .iter()
12            .reduce(|current, previous| {
13                if current < previous {
14                    current
15                } else {
16                    previous
17                }
18            })
19            .unwrap()
20    }
21
22    fn max(&self) -> f32 {
23        *self
24            .iter()
25            .reduce(|current, previous| {
26                if current > previous {
27                    current
28                } else {
29                    previous
30                }
31            })
32            .unwrap()
33    }
34}
35
36impl Aggregate for Array3<f32> {
37    fn min(&self) -> f32 {
38        *self
39            .iter()
40            .reduce(|current, previous| {
41                if current < previous {
42                    current
43                } else {
44                    previous
45                }
46            })
47            .unwrap()
48    }
49
50    fn max(&self) -> f32 {
51        *self
52            .iter()
53            .reduce(|current, previous| {
54                if current > previous {
55                    current
56                } else {
57                    previous
58                }
59            })
60            .unwrap()
61    }
62}