Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Added scalar bitwise ops (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao authored Jan 24, 2022
1 parent 684c259 commit 5d67fc9
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/compute/bitwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::array::PrimitiveArray;
use crate::compute::arity::{binary, unary};
use crate::types::NativeType;

/// Performs `OR` operation on two arrays.
/// Performs `OR` operation on two [`PrimitiveArray`]s.
/// # Panic
/// This function errors when the arrays have different lengths.
pub fn or<T>(lhs: &PrimitiveArray<T>, rhs: &PrimitiveArray<T>) -> PrimitiveArray<T>
Expand All @@ -15,7 +15,7 @@ where
binary(lhs, rhs, lhs.data_type().clone(), |a, b| a | b)
}

/// Performs `XOR` operation between two arrays.
/// Performs `XOR` operation between two [`PrimitiveArray`]s.
/// # Panic
/// This function errors when the arrays have different lengths.
pub fn xor<T>(lhs: &PrimitiveArray<T>, rhs: &PrimitiveArray<T>) -> PrimitiveArray<T>
Expand All @@ -25,7 +25,7 @@ where
binary(lhs, rhs, lhs.data_type().clone(), |a, b| a ^ b)
}

/// Performs `AND` operation on two arrays.
/// Performs `AND` operation on two [`PrimitiveArray`]s.
/// # Panic
/// This function panics when the arrays have different lengths.
pub fn and<T>(lhs: &PrimitiveArray<T>, rhs: &PrimitiveArray<T>) -> PrimitiveArray<T>
Expand All @@ -43,3 +43,33 @@ where
let op = move |a: T| !a;
unary(array, op, array.data_type().clone())
}

/// Performs `OR` operation between a [`PrimitiveArray`] and scalar.
/// # Panic
/// This function errors when the arrays have different lengths.
pub fn or_scalar<T>(lhs: &PrimitiveArray<T>, rhs: &T) -> PrimitiveArray<T>
where
T: NativeType + BitOr<Output = T>,
{
unary(lhs, |a| a | *rhs, lhs.data_type().clone())
}

/// Performs `XOR` operation between a [`PrimitiveArray`] and scalar.
/// # Panic
/// This function errors when the arrays have different lengths.
pub fn xor_scalar<T>(lhs: &PrimitiveArray<T>, rhs: &T) -> PrimitiveArray<T>
where
T: NativeType + BitXor<Output = T>,
{
unary(lhs, |a| a ^ *rhs, lhs.data_type().clone())
}

/// Performs `AND` operation between a [`PrimitiveArray`] and scalar.
/// # Panic
/// This function panics when the arrays have different lengths.
pub fn and_scalar<T>(lhs: &PrimitiveArray<T>, rhs: &T) -> PrimitiveArray<T>
where
T: NativeType + BitAnd<Output = T>,
{
unary(lhs, |a| a & *rhs, lhs.data_type().clone())
}

0 comments on commit 5d67fc9

Please sign in to comment.