Path: blob/main/crates/polars-compute/src/comparisons/mod.rs
6939 views
use arrow::array::Array;1use arrow::bitmap::{self, Bitmap};23pub trait TotalEqKernel: Sized + Array {4type Scalar: ?Sized;56// These kernels ignore validity entirely (results for nulls are unspecified7// but initialized).8fn tot_eq_kernel(&self, other: &Self) -> Bitmap;9fn tot_ne_kernel(&self, other: &Self) -> Bitmap;10fn tot_eq_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap;11fn tot_ne_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap;1213// These kernels treat null as any other value equal to itself but unequal14// to anything else.15fn tot_eq_missing_kernel(&self, other: &Self) -> Bitmap {16let q = self.tot_eq_kernel(other);17match (self.validity(), other.validity()) {18(None, None) => q,19(None, Some(r)) => &q & r,20(Some(l), None) => &q & l,21(Some(l), Some(r)) => bitmap::ternary(&q, l, r, |q, l, r| (q & l & r) | !(l | r)),22}23}2425fn tot_ne_missing_kernel(&self, other: &Self) -> Bitmap {26let q = self.tot_ne_kernel(other);27match (self.validity(), other.validity()) {28(None, None) => q,29(None, Some(r)) => &q | &!r,30(Some(l), None) => &q | &!l,31(Some(l), Some(r)) => bitmap::ternary(&q, l, r, |q, l, r| (q & l & r) | (l ^ r)),32}33}34fn tot_eq_missing_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {35let q = self.tot_eq_kernel_broadcast(other);36if let Some(valid) = self.validity() {37bitmap::binary(&q, valid, |q, v| q & v)38} else {39q40}41}4243fn tot_ne_missing_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap {44let q = self.tot_ne_kernel_broadcast(other);45if let Some(valid) = self.validity() {46bitmap::binary(&q, valid, |q, v| q | !v)47} else {48q49}50}51}5253// Low-level comparison kernel.54pub trait TotalOrdKernel: Sized + Array {55type Scalar: ?Sized;5657// These kernels ignore validity entirely (results for nulls are unspecified58// but initialized).59fn tot_lt_kernel(&self, other: &Self) -> Bitmap;60fn tot_le_kernel(&self, other: &Self) -> Bitmap;61fn tot_gt_kernel(&self, other: &Self) -> Bitmap {62other.tot_lt_kernel(self)63}64fn tot_ge_kernel(&self, other: &Self) -> Bitmap {65other.tot_le_kernel(self)66}6768// These kernels ignore validity entirely (results for nulls are unspecified69// but initialized).70fn tot_lt_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap;71fn tot_le_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap;72fn tot_gt_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap;73fn tot_ge_kernel_broadcast(&self, other: &Self::Scalar) -> Bitmap;74}7576mod binary;77mod boolean;78mod dictionary;79mod dyn_array;80mod list;81mod null;82mod scalar;83mod struct_;84mod utf8;85mod view;8687#[cfg(feature = "simd")]88mod _simd_dtypes {89use arrow::types::{days_ms, f16, i256, months_days_ns};9091use crate::NotSimdPrimitive;9293impl NotSimdPrimitive for f16 {}94impl NotSimdPrimitive for i256 {}95impl NotSimdPrimitive for days_ms {}96impl NotSimdPrimitive for months_days_ns {}97}9899#[cfg(feature = "simd")]100mod simd;101102#[cfg(feature = "dtype-array")]103mod array;104105106