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

Use downcast_primitive_array in arithmetic kernels #2640

Merged
merged 2 commits into from Sep 5, 2022

Conversation

viirya
Copy link
Member

@viirya viirya commented Sep 3, 2022

Which issue does this PR close?

Closes #2639.

Rationale for this change

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 Sep 3, 2022
@viirya
Copy link
Member Author

viirya commented Sep 3, 2022

Did a benchmark run and no obvious difference found.

@@ -225,6 +225,255 @@ macro_rules! downcast_primitive_array {
$($p => $fallback,)*
}
};

(($values1:ident, $values2:ident) => $e:block $($p:pat => $fallback:expr $(,)*)*) => {
Copy link
Contributor

@tustvold tustvold Sep 3, 2022

Choose a reason for hiding this comment

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

This has an implicit assumption that $values1 and $values2 have the same type, not only is this potentially surprising as an API, but I think it changes the behaviour of the kernels which will now panic where previously they would return an error?

Adding $values2.data_type() to the match might work, but this still feels a bit confusing as an API? 🤔

I wonder if we could instead do something like this

downcast_primitive_array!(
      left => {
          let right = as_primitive_array(right);
          multiply(left, right).map(|a| Arc::new(a) as ArrayRef)
      }
      _ => Err(ArrowError::CastError(format!(
          "Unsupported data type {}, {}",
          left.data_type(), right.data_type()
      )))
  )

And rely on the fact the generic kernels constrain them to be the same type. I don't know, perhaps this is hack...

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, good point. But I guess the suggested one will also panic on let right = as_primitive_array(right); if right is not same type?

Let me do a test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, math_op doesn't constrain two sides of op should be same type. So

downcast_primitive_array!(
    left => {
        let right = as_primitive_array(right);
        math_op(left, right, |a, b| a + b).map(|a| Arc::new(a) as ArrayRef)
    }
    _ => Err(ArrowError::CastError(format!(
       "Unsupported data type {}, {}",
        left.data_type(), right.data_type()
   )))
)

will not constrain the right side type.

Copy link
Contributor

Choose a reason for hiding this comment

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

suggested one will

Yeah, you will still need to check the type, it is what it is

doesn't constrain the type

That's why i suggested using the generic kernel not math_op directly 😃

Copy link
Member Author

@viirya viirya Sep 3, 2022

Choose a reason for hiding this comment

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

Oh oh right. 😄

Good news is it works.

But as Float16Type doesn't implement ArrowNumericType, I need to remove Float16Type pattern from downcast_primitive_array! to make it work.

For simd feature, seems f16 related APIs are not available so it appears not easy to let Float16Type implement ArrowNumericType.

Currently I leave single argument downcast_primitive_array! untouched and stick with two argument one and make it constrain the two arguments must be same type.

@tustvold
Copy link
Contributor

tustvold commented Sep 3, 2022

Btw very cool to see these being used already ❤️

@tustvold tustvold merged commit 30ab9bb into apache:master Sep 5, 2022
@ursabot
Copy link

ursabot commented Sep 5, 2022

Benchmark runs are scheduled for baseline = b46fc92 and contender = 30ab9bb. 30ab9bb 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.

Use downcast_primitive_array in arithmetic kernels
3 participants