You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/10/05 20:08:13 UTC
[GitHub] [arrow-rs] tustvold opened a new pull request, #2818: Fix i256 checked multiplication
tustvold opened a new pull request, #2818:
URL: https://github.com/apache/arrow-rs/pull/2818
# 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.
-->
Part of #2637
# 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.
-->
The previous version was failing to correctly detect overflow.
# 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.
-->
There may be a smart way to detect signed overflow correctly, but trying to think about this just did my head in. The simple solution is to take the absolute value, perform the arithmetic and convert back. I think this is fine, and if someone has a use-case where this becomes a major performance bottleneck we can revisit.
# Are there any user-facing changes?
No
<!--
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] tustvold merged pull request #2818: Fix i256 checked multiplication
Posted by GitBox <gi...@apache.org>.
tustvold merged PR #2818:
URL: https://github.com/apache/arrow-rs/pull/2818
--
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] ursabot commented on pull request #2818: Fix i256 checked multiplication
Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #2818:
URL: https://github.com/apache/arrow-rs/pull/2818#issuecomment-1269350582
Benchmark runs are scheduled for baseline = 24e9b7c5ce76f1f46a95ef4bb8cfd2d55943221b and contender = a0a263f7cbe26ee7d72ecacd0e47a8c05279e5bd. a0a263f7cbe26ee7d72ecacd0e47a8c05279e5bd is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/1c28ba12bb214456a2381b370456388e...41916814505d4d358eb10e549b5b5e63/)
[Skipped :warning: Benchmarking of arrow-rs-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/a0e7fc4b088045b59ae0bb3316ffe7b5...a65ba347f2af404aad35fa336f6c6ef7/)
[Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/6a198fceed36452db189ba6f2447ecab...7dffd93d201b44f2b2eb0dd0e2bec576/)
[Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/d6feb60366df4abf8b1d1c785c180ec2...cd7b942c733043ca8342c14d6d480ad5/)
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
--
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 pull request #2818: Fix i256 checked multiplication
Posted by GitBox <gi...@apache.org>.
tustvold commented on PR #2818:
URL: https://github.com/apache/arrow-rs/pull/2818#issuecomment-1269000890
I plan to give this another once over with fresh eyes in the morning, and then get this in.
--
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 #2818: Fix i256 checked multiplication
Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2818:
URL: https://github.com/apache/arrow-rs/pull/2818#discussion_r988887254
##########
arrow-buffer/src/bigint.rs:
##########
@@ -303,8 +350,106 @@ mod tests {
}
}
+ /// Tests operations against the two provided [`i256`]
+ fn test_ops(il: i256, ir: i256) {
+ let bl = BigInt::from_signed_bytes_le(&il.to_le_bytes());
+ let br = BigInt::from_signed_bytes_le(&ir.to_le_bytes());
+
+ // Comparison
+ assert_eq!(il.cmp(&ir), bl.cmp(&br), "{} cmp {}", bl, br);
+
+ // To i128
+ assert_eq!(il.to_i128(), bl.to_i128(), "{}", bl);
+ assert_eq!(ir.to_i128(), br.to_i128(), "{}", br);
+
+ // Absolute value
+ let (abs, overflow) = i256::from_bigint_with_overflow(bl.abs());
+ assert_eq!(il.wrapping_abs(), abs);
+ assert_eq!(il.checked_abs().is_none(), overflow);
+
+ let (abs, overflow) = i256::from_bigint_with_overflow(br.abs());
+ assert_eq!(ir.wrapping_abs(), abs);
+ assert_eq!(ir.checked_abs().is_none(), overflow);
+
+ // Addition
+ let actual = il.wrapping_add(ir);
+ let (expected, overflow) =
+ i256::from_bigint_with_overflow(bl.clone() + br.clone());
+ assert_eq!(actual, expected);
+
+ let checked = il.checked_add(ir);
+ match overflow {
+ true => assert!(checked.is_none()),
+ false => assert_eq!(checked.unwrap(), actual),
+ }
+
+ // Subtraction
+ let actual = il.wrapping_sub(ir);
+ let (expected, overflow) =
+ i256::from_bigint_with_overflow(bl.clone() - br.clone());
+ assert_eq!(actual.to_string(), expected.to_string());
+
+ let checked = il.checked_sub(ir);
+ match overflow {
+ true => assert!(checked.is_none()),
+ false => assert_eq!(checked.unwrap(), actual),
+ }
+
+ // Multiplication
+ let actual = il.wrapping_mul(ir);
+ let (expected, overflow) =
+ i256::from_bigint_with_overflow(bl.clone() * br.clone());
+ assert_eq!(actual.to_string(), expected.to_string());
+
+ let checked = il.checked_mul(ir);
+ match overflow {
+ true => assert!(
+ checked.is_none(),
+ "{} * {} = {} vs {} * {} = {}",
+ il,
+ ir,
+ actual,
+ bl,
+ br,
+ expected
+ ),
+ false => assert_eq!(
+ checked.unwrap(),
+ actual,
+ "{} * {} = {} vs {} * {} = {}",
+ il,
+ ir,
+ actual,
+ bl,
+ br,
+ expected
+ ),
+ }
+ }
+
#[test]
fn test_i256() {
+ let candidates = [
+ i256::from_parts(0, 0),
+ i256::from_parts(0, 1),
+ i256::from_parts(0, -1),
+ i256::from_parts(u128::MAX, 1),
Review Comment:
thanks -- this is much easier to ensure coverage
--
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