You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Weijun-H (via GitHub)" <gi...@apache.org> on 2023/04/27 17:42:53 UTC

[GitHub] [arrow-rs] Weijun-H opened a new pull request, #4148: feat: support bitwise shift left/right

Weijun-H opened a new pull request, #4148:
URL: https://github.com/apache/arrow-rs/pull/4148

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #2741
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking change` label.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] Weijun-H commented on a diff in pull request #4148: feat: support `bitwise` shift left/right

Posted by "Weijun-H (via GitHub)" <gi...@apache.org>.
Weijun-H commented on code in PR #4148:
URL: https://github.com/apache/arrow-rs/pull/4148#discussion_r1180185165


##########
arrow-arith/src/bitwise.rs:
##########
@@ -143,6 +177,24 @@ mod tests {
         Ok(())
     }
 
+    #[test]

Review Comment:
   > Shift operations (<<, >>) on a value of width N can be passed a shift value >= N. It is unclear what behaviour should result from this, so the shift value is unconditionally masked to be modulo N to ensure that the argument is always in range.
   I found the reason here https://github.com/rust-lang/rfcs/blob/master/text/0560-integer-overflow.md



##########
arrow-arith/src/bitwise.rs:
##########
@@ -143,6 +177,24 @@ mod tests {
         Ok(())
     }
 
+    #[test]

Review Comment:
   > Shift operations (<<, >>) on a value of width N can be passed a shift value >= N. It is unclear what behaviour should result from this, so the shift value is unconditionally masked to be modulo N to ensure that the argument is always in range.
   
   I found the reason here https://github.com/rust-lang/rfcs/blob/master/text/0560-integer-overflow.md



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] Weijun-H commented on a diff in pull request #4148: feat: support `bitwise` shift left/right

Posted by "Weijun-H (via GitHub)" <gi...@apache.org>.
Weijun-H commented on code in PR #4148:
URL: https://github.com/apache/arrow-rs/pull/4148#discussion_r1180163599


##########
arrow-arith/src/bitwise.rs:
##########
@@ -143,6 +177,24 @@ mod tests {
         Ok(())
     }
 
+    #[test]

Review Comment:
   This makes sense, as `wrapping_shr` would shift the position would be the remainder of the type. So `wrapping_shr(3_i32, 32) == 3` and `wrapping_shr(3_i32, 33) == 1`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] Weijun-H commented on a diff in pull request #4148: feat: support `bitwise` shift left/right

Posted by "Weijun-H (via GitHub)" <gi...@apache.org>.
Weijun-H commented on code in PR #4148:
URL: https://github.com/apache/arrow-rs/pull/4148#discussion_r1180166573


##########
arrow-arith/src/bitwise.rs:
##########
@@ -143,6 +177,24 @@ mod tests {
         Ok(())
     }
 
+    #[test]

Review Comment:
   It seems like a rotation shift. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] Weijun-H commented on a diff in pull request #4148: feat: support `bitwise` shift left/right

Posted by "Weijun-H (via GitHub)" <gi...@apache.org>.
Weijun-H commented on code in PR #4148:
URL: https://github.com/apache/arrow-rs/pull/4148#discussion_r1180120001


##########
arrow-arith/src/bitwise.rs:
##########
@@ -143,6 +177,24 @@ mod tests {
         Ok(())
     }
 
+    #[test]

Review Comment:
   I add a test for it. It should be `0`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] Weijun-H commented on a diff in pull request #4148: feat: support `bitwise` shift left/right

Posted by "Weijun-H (via GitHub)" <gi...@apache.org>.
Weijun-H commented on code in PR #4148:
URL: https://github.com/apache/arrow-rs/pull/4148#discussion_r1180166573


##########
arrow-arith/src/bitwise.rs:
##########
@@ -143,6 +177,24 @@ mod tests {
         Ok(())
     }
 
+    #[test]

Review Comment:
   It seems like a rotation shift. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4148: feat: support `bitwise` shift left/right

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4148:
URL: https://github.com/apache/arrow-rs/pull/4148#discussion_r1180107023


##########
arrow-arith/src/bitwise.rs:
##########
@@ -143,6 +177,24 @@ mod tests {
         Ok(())
     }
 
+    #[test]

Review Comment:
   Is it worth adding a test of what happens if you shift by more than the number of bits?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold merged pull request #4148: feat: support `bitwise` shift left/right

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold merged PR #4148:
URL: https://github.com/apache/arrow-rs/pull/4148


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4148: feat: support `bitwise` shift left/right

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4148:
URL: https://github.com/apache/arrow-rs/pull/4148#discussion_r1180129184


##########
arrow-arith/src/bitwise.rs:
##########
@@ -143,6 +177,24 @@ mod tests {
         Ok(())
     }
 
+    #[test]

Review Comment:
   Are you sure? https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=0bc4c3229b2ffd98a64eaf71573d0199



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] alamb commented on a diff in pull request #4148: feat: support `bitwise` shift left/right

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #4148:
URL: https://github.com/apache/arrow-rs/pull/4148#discussion_r1180465375


##########
arrow-arith/src/bitwise.rs:
##########
@@ -17,7 +17,9 @@
 
 use crate::arity::{binary, unary};
 use arrow_array::*;
+use arrow_buffer::ArrowNativeType;
 use arrow_schema::ArrowError;
+use num::traits::{WrappingShl, WrappingShr};

Review Comment:
   this is great -- when I looked into doing this in DataFusion I noticed these traits weren't in `std` -- 100% for finding them in `num` 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org