polars_compute/comparisons/
scalar.rs

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use arrow::array::PrimitiveArray;
use arrow::bitmap::Bitmap;
use polars_utils::total_ord::TotalOrd;

use super::{TotalEqKernel, TotalOrdKernel};
use crate::NotSimdPrimitive;

impl<T: NotSimdPrimitive + TotalOrd> TotalEqKernel for PrimitiveArray<T> {
    type Scalar = T;

    fn tot_eq_kernel(&self, other: &Self) -> Bitmap {
        assert!(self.len() == other.len());
        self.values()
            .iter()
            .zip(other.values().iter())
            .map(|(l, r)| l.tot_eq(r))
            .collect()
    }

    fn tot_ne_kernel(&self, other: &Self) -> Bitmap {
        assert!(self.len() == other.len());
        self.values()
            .iter()
            .zip(other.values().iter())
            .map(|(l, r)| l.tot_ne(r))
            .collect()
    }

    fn tot_eq_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        self.values().iter().map(|l| l.tot_eq(other)).collect()
    }

    fn tot_ne_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        self.values().iter().map(|l| l.tot_ne(other)).collect()
    }
}

impl<T: NotSimdPrimitive + TotalOrd> TotalOrdKernel for PrimitiveArray<T> {
    type Scalar = T;

    fn tot_lt_kernel(&self, other: &Self) -> Bitmap {
        assert!(self.len() == other.len());
        self.values()
            .iter()
            .zip(other.values().iter())
            .map(|(l, r)| l.tot_lt(r))
            .collect()
    }

    fn tot_le_kernel(&self, other: &Self) -> Bitmap {
        assert!(self.len() == other.len());
        self.values()
            .iter()
            .zip(other.values().iter())
            .map(|(l, r)| l.tot_le(r))
            .collect()
    }

    fn tot_lt_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        self.values().iter().map(|l| l.tot_lt(other)).collect()
    }

    fn tot_le_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        self.values().iter().map(|l| l.tot_le(other)).collect()
    }

    fn tot_gt_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        self.values().iter().map(|l| l.tot_gt(other)).collect()
    }

    fn tot_ge_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {
        self.values().iter().map(|l| l.tot_ge(other)).collect()
    }
}