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

Simplify ArrowNativeType #2841

Merged
merged 4 commits into from Oct 8, 2022
Merged

Conversation

tustvold
Copy link
Contributor

@tustvold tustvold commented Oct 7, 2022

Which issue does this PR close?

Closes #.

Rationale for this change

#2840 made this public, prior to releasing lets take the opportunity to clean it up a a bit.

What changes are included in this PR?

Tweaks the signature of ArrowNativeType, reduces the constraints on some kernels, and cleans up the documentation

Are there any user-facing changes?

No, ArrowNativeTypeOp is not yet public, and this only removes constraints from public methods

@tustvold tustvold requested a review from viirya October 7, 2022 10:03
Comment on lines -41 to -45
+ Add<Output = Self>
+ Sub<Output = Self>
+ Mul<Output = Self>
+ Div<Output = Self>
+ Rem<Output = Self>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing these ensures that kernels are correctly selecting either the wrapping or checked variants

Copy link
Member

Choose a reason for hiding this comment

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

Hm, I don't get this correctly. Why removing these can ensure that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ensure might be too strong, but if writing a generic function using this as a type constraint the default implementations won't be available. For example, it caught that the SIMD kernels were using the default %

+ Mul<Output = Self>
+ Div<Output = Self>
+ Rem<Output = Self>
+ Zero
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opted to remove this as it avoids committing to using the num traits in our public API

+ private::Sealed
{
fn add_checked(self, rhs: Self) -> Result<Self> {
Ok(self + rhs)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I perpetually found the default definitions confusing, moving them into the separate macros makes it clear what applies to what types


fn mod_wrapping(self, rhs: Self) -> Self {
self % rhs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As evidence of the confusion, these are the defaults for the integer types, whereas the above are the defaults for floating point types 😅

///
/// For floating point types, overflow and division by zero follows normal floating point rules
///
/// For integer types overflow will wrap around. Division by zero will currently panic, although
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I plan to address this in a follow up, the current kernel is effectively useless for integer types

Copy link
Member

Choose a reason for hiding this comment

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

Useless for integer types? How?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because nulls will have the value zero which then panic

fn test_int_array_modulus_overflow_wrapping() {
let a = Int32Array::from(vec![i32::MIN]);
let b = Int32Array::from(vec![-1]);
let result = modulus(&a, &b).unwrap();
assert_eq!(0, result.value(0))
}

#[test]
Copy link
Contributor Author

@tustvold tustvold Oct 7, 2022

Choose a reason for hiding this comment

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

This was an undocumented bug that has now been fixed 🎉

Copy link
Member

Choose a reason for hiding this comment

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

what bug it is?

Copy link
Member

Choose a reason for hiding this comment

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

For example, it caught that the SIMD kernels were using the default %

This?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Oct 7, 2022
Copy link
Member

@viirya viirya left a comment

Choose a reason for hiding this comment

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

The cleanup looks good to me. Just a few questions.

@tustvold tustvold merged commit c8321f4 into apache:master Oct 8, 2022
@ursabot
Copy link

ursabot commented Oct 8, 2022

Benchmark runs are scheduled for baseline = 97480a9 and contender = c8321f4. c8321f4 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
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

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.

None yet

3 participants