1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use std::cmp::Ordering;
use crate::prelude::{Array, ArrayBase, Numeric};
impl <N: Numeric> PartialEq for Array<N> {
fn eq(&self, other: &Self) -> bool {
compare_shape(self, other);
self.elements.iter()
.zip(&other.elements)
.all(|(a, b)| a == b)
}
}
impl <N: Numeric> PartialOrd for Array<N> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
compare_shape(self, other);
self.elements.partial_cmp(&other.elements)
}
fn lt(&self, other: &Self) -> bool {
compare_shape(self, other);
self.elements.lt(&other.elements)
}
fn le(&self, other: &Self) -> bool {
compare_shape(self, other);
self.elements.le(&other.elements)
}
fn gt(&self, other: &Self) -> bool {
compare_shape(self, other);
self.elements.gt(&other.elements)
}
fn ge(&self, other: &Self) -> bool {
compare_shape(self, other);
self.elements.ge(&other.elements)
}
}
fn compare_shape<N: Numeric>(arr1: &Array<N>, arr2: &Array<N>) {
assert_eq!(
arr1.get_shape(), arr2.get_shape(),
"Cannot compare arrays of different shape: {:?} and {:?}", arr1.shape, arr2.shape
);
}