polars_arrow/compute/
bitwise.rs1use std::ops::{BitAnd, BitOr, BitXor, Not};
3
4use crate::array::PrimitiveArray;
5use crate::compute::arity::{binary, unary};
6use crate::types::NativeType;
7
8pub fn or<T>(lhs: &PrimitiveArray<T>, rhs: &PrimitiveArray<T>) -> PrimitiveArray<T>
12where
13 T: NativeType + BitOr<Output = T>,
14{
15 binary(lhs, rhs, lhs.dtype().clone(), |a, b| a | b)
16}
17
18pub fn xor<T>(lhs: &PrimitiveArray<T>, rhs: &PrimitiveArray<T>) -> PrimitiveArray<T>
22where
23 T: NativeType + BitXor<Output = T>,
24{
25 binary(lhs, rhs, lhs.dtype().clone(), |a, b| a ^ b)
26}
27
28pub fn and<T>(lhs: &PrimitiveArray<T>, rhs: &PrimitiveArray<T>) -> PrimitiveArray<T>
32where
33 T: NativeType + BitAnd<Output = T>,
34{
35 binary(lhs, rhs, lhs.dtype().clone(), |a, b| a & b)
36}
37
38pub fn not<T>(array: &PrimitiveArray<T>) -> PrimitiveArray<T>
40where
41 T: NativeType + Not<Output = T>,
42{
43 let op = move |a: T| !a;
44 unary(array, op, array.dtype().clone())
45}
46
47pub fn or_scalar<T>(lhs: &PrimitiveArray<T>, rhs: &T) -> PrimitiveArray<T>
51where
52 T: NativeType + BitOr<Output = T>,
53{
54 unary(lhs, |a| a | *rhs, lhs.dtype().clone())
55}
56
57pub fn xor_scalar<T>(lhs: &PrimitiveArray<T>, rhs: &T) -> PrimitiveArray<T>
61where
62 T: NativeType + BitXor<Output = T>,
63{
64 unary(lhs, |a| a ^ *rhs, lhs.dtype().clone())
65}
66
67pub fn and_scalar<T>(lhs: &PrimitiveArray<T>, rhs: &T) -> PrimitiveArray<T>
71where
72 T: NativeType + BitAnd<Output = T>,
73{
74 unary(lhs, |a| a & *rhs, lhs.dtype().clone())
75}