-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-11428: [Rust] Add power_scalar kernel #9361
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
Conversation
nevi-me
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This simplification makes this identical to crate::array::compute::kernels::arity::unary, which was recently added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right.. Then there is some duplication. What do you propose? Use the crate::array::compute::kernels::arity::unary for the logic in this model as wel? To me that seems more DRY.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nevi-me I removed the helper function and used the arity::unary::kernel
rust/arrow/src/datatypes.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could avoid creating this trait by using num::Float as a constraint for floaing types. See #9313, though I wasn't doing it for a SIMD implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For non-SIMD this would work indeed. However I could not proof my SIMD type had the powf method without this trait/ implementation. Or am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, if it's not possible to only add the trait for SIMD types, then it's a reasonable change to make.
The downside's that the trait's going to grow when we add more compute kernels (with SIMD support).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this function is powf, WDYT about renaming it as such? We're going to also have pow for the integer types, powi to raise floats to an integer power. So we could preempt the possible rename.
I'll remove the powf in #9313 because this one has a SIMD implementation.
An additional benefit of splitting powf and powi is that powi is faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed to powf_scalar. I still have a scalar suffix distinct with a (future) kernel that is a binary function (i.e. array to the power of array).
27421f4 to
82c7535
Compare
nevi-me
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, we have a persistent failure in the integration tests, which doesn't make sense.
Can you please rebase, in case there's something else that's causing the error.
In the absence of other reviewers, I'm happy that we can merge this.
82c7535 to
511eb65
Compare
|
Rebased! 👍 |
Adds a SISD and SIMD kernel to raise a
Float32/64array to a power of ascalarof the same type. We could also make a thinsqrtwrapper.I also added a
unary_opfn toArrowNumerictype as this seemed the most generic way to implement this. Next PR I could add support for a binary version of this (e.g. array to the power of array).edit:
The
ArrowFloatNumericTypetrait was added because the Simd::powf is only available for float arrays (e.g.[f32, N],[f64, N]). However, the packed_simd crate doesn't expose this functionality via a trait, but directly on the type, hence the extra trait.