-
Notifications
You must be signed in to change notification settings - Fork 1k
add lt_bool, lt_eq_bool, gt_bool, gt_eq_bool #860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -624,8 +624,15 @@ pub fn eq_utf8_scalar<OffsetSize: StringOffsetSizeTrait>( | ||||||||||||||||
| compare_op_scalar!(left, right, |a, b| a == b) | |||||||||||||||||
| } | |||||||||||||||||
|
|
|||||||||||||||||
| /// Perform `left == right` operation on [`BooleanArray`] | |||||||||||||||||
| fn eq_bool(left: &BooleanArray, right: &BooleanArray) -> Result<BooleanArray> { | |||||||||||||||||
| #[inline] | |||||||||||||||||
| fn binary_boolean_op<F>( | |||||||||||||||||
| left: &BooleanArray, | |||||||||||||||||
| right: &BooleanArray, | |||||||||||||||||
| op: F, | |||||||||||||||||
| ) -> Result<BooleanArray> | |||||||||||||||||
| where | |||||||||||||||||
| F: Copy + Fn(u64, u64) -> u64, | |||||||||||||||||
| { | |||||||||||||||||
| binary_boolean_kernel( | |||||||||||||||||
| left, | |||||||||||||||||
| right, | |||||||||||||||||
|
|
@@ -640,32 +647,40 @@ fn eq_bool(left: &BooleanArray, right: &BooleanArray) -> Result<BooleanArray> { | ||||||||||||||||
| right, | |||||||||||||||||
| right_offset_in_bits, | |||||||||||||||||
| len_in_bits, | |||||||||||||||||
| |a, b| !(a ^ b), | |||||||||||||||||
| op, | |||||||||||||||||
| ) | |||||||||||||||||
| }, | |||||||||||||||||
| ) | |||||||||||||||||
| } | |||||||||||||||||
|
|
|||||||||||||||||
| /// Perform `left == right` operation on [`BooleanArray`] | |||||||||||||||||
| fn eq_bool(left: &BooleanArray, right: &BooleanArray) -> Result<BooleanArray> { | |||||||||||||||||
| binary_boolean_op(left, right, |a, b| !(a ^ b)) | |||||||||||||||||
| } | |||||||||||||||||
|
|
|||||||||||||||||
| /// Perform `left != right` operation on [`BooleanArray`] | |||||||||||||||||
| fn neq_bool(left: &BooleanArray, right: &BooleanArray) -> Result<BooleanArray> { | |||||||||||||||||
| binary_boolean_kernel( | |||||||||||||||||
| left, | |||||||||||||||||
| right, | |||||||||||||||||
| |left: &Buffer, | |||||||||||||||||
| left_offset_in_bits: usize, | |||||||||||||||||
| right: &Buffer, | |||||||||||||||||
| right_offset_in_bits: usize, | |||||||||||||||||
| len_in_bits: usize| { | |||||||||||||||||
| bitwise_bin_op_helper( | |||||||||||||||||
| left, | |||||||||||||||||
| left_offset_in_bits, | |||||||||||||||||
| right, | |||||||||||||||||
| right_offset_in_bits, | |||||||||||||||||
| len_in_bits, | |||||||||||||||||
| |a, b| (a ^ b), | |||||||||||||||||
| ) | |||||||||||||||||
| }, | |||||||||||||||||
| ) | |||||||||||||||||
| binary_boolean_op(left, right, |a, b| (a ^ b)) | |||||||||||||||||
| } | |||||||||||||||||
|
|
|||||||||||||||||
| /// Perform `left < right` operation on [`BooleanArray`] | |||||||||||||||||
| fn lt_bool(left: &BooleanArray, right: &BooleanArray) -> Result<BooleanArray> { | |||||||||||||||||
| binary_boolean_op(left, right, |a, b| ((!a) & b)) | |||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 the truth table shows it to be true:
I checked the others as well |
|||||||||||||||||
| } | |||||||||||||||||
|
|
|||||||||||||||||
| /// Perform `left <= right` operation on [`BooleanArray`] | |||||||||||||||||
| fn lt_eq_bool(left: &BooleanArray, right: &BooleanArray) -> Result<BooleanArray> { | |||||||||||||||||
| binary_boolean_op(left, right, |a, b| !(a & (!b))) | |||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can also be done with two operations rather than three via |
|||||||||||||||||
| } | |||||||||||||||||
|
|
|||||||||||||||||
| /// Perform `left > right` operation on [`BooleanArray`] | |||||||||||||||||
| fn gt_bool(left: &BooleanArray, right: &BooleanArray) -> Result<BooleanArray> { | |||||||||||||||||
| binary_boolean_op(left, right, |a, b| (a & (!b))) | |||||||||||||||||
| } | |||||||||||||||||
|
|
|||||||||||||||||
| /// Perform `left >= right` operation on [`BooleanArray`] | |||||||||||||||||
| fn gt_eq_bool(left: &BooleanArray, right: &BooleanArray) -> Result<BooleanArray> { | |||||||||||||||||
| binary_boolean_op(left, right, |a, b| !((!a) & b)) | |||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. likewise could also be written like |
|||||||||||||||||
| } | |||||||||||||||||
|
|
|||||||||||||||||
| /// Perform `left == right` operation on [`BooleanArray`] and a scalar | |||||||||||||||||
|
|
@@ -1354,7 +1369,7 @@ mod tests { | ||||||||||||||||
| vec![Some(true), Some(false), Some(false), Some(true), Some(true), None] | |||||||||||||||||
| .into(); | |||||||||||||||||
| let b: BooleanArray = | |||||||||||||||||
| vec![Some(true), Some(true), Some(false), Some(false), None, Some(false)] | |||||||||||||||||
| vec![Some(true), Some(true), Some(false), Some(false), None, Some(false)] | |||||||||||||||||
| .into(); | |||||||||||||||||
|
|
|||||||||||||||||
| let res: Vec<Option<bool>> = neq_bool(&a, &b).unwrap().iter().collect(); | |||||||||||||||||
|
|
@@ -1365,6 +1380,74 @@ mod tests { | ||||||||||||||||
| ) | |||||||||||||||||
| } | |||||||||||||||||
|
|
|||||||||||||||||
| #[test] | |||||||||||||||||
| fn test_boolean_array_lt() { | |||||||||||||||||
| let a: BooleanArray = | |||||||||||||||||
| vec![Some(true), Some(false), Some(false), Some(true), Some(true), None] | |||||||||||||||||
| .into(); | |||||||||||||||||
| let b: BooleanArray = | |||||||||||||||||
| vec![Some(true), Some(true), Some(false), Some(false), None, Some(false)] | |||||||||||||||||
| .into(); | |||||||||||||||||
|
|
|||||||||||||||||
| let res: Vec<Option<bool>> = lt_bool(&a, &b).unwrap().iter().collect(); | |||||||||||||||||
|
|
|||||||||||||||||
| assert_eq!( | |||||||||||||||||
| res, | |||||||||||||||||
| vec![Some(false), Some(true), Some(false), Some(false), None, None] | |||||||||||||||||
| ) | |||||||||||||||||
| } | |||||||||||||||||
|
|
|||||||||||||||||
| #[test] | |||||||||||||||||
| fn test_boolean_array_lt_eq() { | |||||||||||||||||
| let a: BooleanArray = | |||||||||||||||||
| vec![Some(true), Some(false), Some(false), Some(true), Some(true), None] | |||||||||||||||||
| .into(); | |||||||||||||||||
| let b: BooleanArray = | |||||||||||||||||
| vec![Some(true), Some(true), Some(false), Some(false), None, Some(false)] | |||||||||||||||||
| .into(); | |||||||||||||||||
|
|
|||||||||||||||||
| let res: Vec<Option<bool>> = lt_eq_bool(&a, &b).unwrap().iter().collect(); | |||||||||||||||||
|
|
|||||||||||||||||
| assert_eq!( | |||||||||||||||||
| res, | |||||||||||||||||
| vec![Some(true), Some(true), Some(true), Some(false), None, None] | |||||||||||||||||
| ) | |||||||||||||||||
| } | |||||||||||||||||
|
|
|||||||||||||||||
| #[test] | |||||||||||||||||
| fn test_boolean_array_gt() { | |||||||||||||||||
| let a: BooleanArray = | |||||||||||||||||
| vec![Some(true), Some(false), Some(false), Some(true), Some(true), None] | |||||||||||||||||
| .into(); | |||||||||||||||||
| let b: BooleanArray = | |||||||||||||||||
| vec![Some(true), Some(true), Some(false), Some(false), None, Some(false)] | |||||||||||||||||
| .into(); | |||||||||||||||||
|
|
|||||||||||||||||
| let res: Vec<Option<bool>> = gt_bool(&a, &b).unwrap().iter().collect(); | |||||||||||||||||
|
|
|||||||||||||||||
| assert_eq!( | |||||||||||||||||
| res, | |||||||||||||||||
| vec![Some(false), Some(false), Some(false), Some(true), None, None] | |||||||||||||||||
| ) | |||||||||||||||||
| } | |||||||||||||||||
|
|
|||||||||||||||||
| #[test] | |||||||||||||||||
| fn test_boolean_array_gt_eq() { | |||||||||||||||||
| let a: BooleanArray = | |||||||||||||||||
| vec![Some(true), Some(false), Some(false), Some(true), Some(true), None] | |||||||||||||||||
| .into(); | |||||||||||||||||
| let b: BooleanArray = | |||||||||||||||||
| vec![Some(true), Some(true), Some(false), Some(false), None, Some(false)] | |||||||||||||||||
| .into(); | |||||||||||||||||
|
|
|||||||||||||||||
| let res: Vec<Option<bool>> = gt_eq_bool(&a, &b).unwrap().iter().collect(); | |||||||||||||||||
|
|
|||||||||||||||||
| assert_eq!( | |||||||||||||||||
| res, | |||||||||||||||||
| vec![Some(true), Some(false), Some(true), Some(true), None, None] | |||||||||||||||||
| ) | |||||||||||||||||
| } | |||||||||||||||||
|
|
|||||||||||||||||
| #[test] | |||||||||||||||||
| fn test_boolean_array_eq_scalar() { | |||||||||||||||||
| let a: BooleanArray = vec![Some(true), Some(false), None].into(); | |||||||||||||||||
|
|
|||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth a doc comment that says that
opis performed 64 bits at a time withu64(aka so it is not possible to usea < bfor example, to implementlt_bool)