Skip to content
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

add lt_bool, lt_eq_bool, gt_bool, gt_eq_bool #860

Merged
merged 1 commit into from
Oct 25, 2021

Conversation

jimexist
Copy link
Member

@jimexist jimexist commented Oct 25, 2021

Which issue does this PR close?

Following #844
Closes #861

Rationale for this change

add lt_bool, lt_eq_bool, gt_bool, gt_eq_bool

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Oct 25, 2021
@Dandandan
Copy link
Contributor

Looks good! I think we should add the scalar versions too (lt_bool_scalar, etc)?

@jimexist
Copy link
Member Author

jimexist commented Oct 25, 2021

Looks good! I think we should add the scalar versions too (lt_bool_scalar, etc)?

i don't think we need.

  1. lt_bool_scalar(arr, true) is just eq_bool_scalar(arr, false)
  2. lt_bool_scalar(arr, false) is just all false
  3. and so on

@codecov-commenter
Copy link

Codecov Report

Merging #860 (191289c) into master (3ea0e18) will decrease coverage by 0.00%.
The diff coverage is 97.29%.

❗ Current head 191289c differs from pull request most recent head 2903c7d. Consider uploading reports for the commit 2903c7d to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #860      +/-   ##
==========================================
- Coverage   82.67%   82.66%   -0.01%     
==========================================
  Files         168      168              
  Lines       48129    48172      +43     
==========================================
+ Hits        39792    39823      +31     
- Misses       8337     8349      +12     
Impacted Files Coverage Δ
arrow/src/compute/kernels/comparison.rs 94.10% <97.29%> (-1.45%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3ea0e18...2903c7d. Read the comment docs.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this PR, we will perhaps need to update eq_dyn and the other kernels introduced in #858 to support BooleanArray as well

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👨‍🍳 ❤️ -- very nice @jimexist -- thank you

/// Perform `left == right` operation on [`BooleanArray`]
fn eq_bool(left: &BooleanArray, right: &BooleanArray) -> Result<BooleanArray> {
#[inline]
fn binary_boolean_op<F>(
Copy link
Contributor

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 op is performed 64 bits at a time withu64 (aka so it is not possible to use a < b for example, to implement lt_bool)


/// Perform `left < right` operation on [`BooleanArray`]
fn lt_bool(left: &BooleanArray, right: &BooleanArray) -> Result<BooleanArray> {
binary_boolean_op(left, right, |a, b| ((!a) & b))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

the truth table shows it to be true:

a b a < b
t f f
t f f
f t t
f t f

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)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be done with two operations rather than three via (!a | b) but I suspect the compiler will do that transformation if it is useful


/// 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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise could also be written like (a | !b)

@alamb
Copy link
Contributor

alamb commented Oct 26, 2021

After this PR, we will perhaps need to update eq_dyn and the other kernels introduced in #858 to support BooleanArray as well

FWIW I double checked at #858 includes support for BooleanArray 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add boolean lt, gt, leq, geq kernels
4 participants