Skip to content

Conversation

@ritchie46
Copy link
Contributor

@ritchie46 ritchie46 commented Jan 29, 2021

Adds a SISD and SIMD kernel to raise a Float32/64 array to a power of a scalar of the same type. We could also make a thin sqrt wrapper.

I also added a unary_op fn to ArrowNumeric type 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 ArrowFloatNumericType trait 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.

@ritchie46 ritchie46 changed the title Power kernel ARROW-11428: [Rust] Add power_scalar kernel Jan 29, 2021
@apache apache deleted a comment from github-actions bot Jan 29, 2021
@kou kou changed the title ARROW-11428: [Rust] Add power_scalar kernel ARROW-11428: [Rust] Add power_scalar kernel Jan 29, 2021
@apache apache deleted a comment from github-actions bot Jan 29, 2021
@github-actions
Copy link

Copy link
Contributor

@nevi-me nevi-me left a comment

Choose a reason for hiding this comment

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

Some comments

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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).

Copy link
Contributor

@nevi-me nevi-me Feb 8, 2021

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.

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 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).

Copy link
Contributor

@nevi-me nevi-me left a 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.

@ritchie46
Copy link
Contributor Author

Rebased! 👍

@nevi-me nevi-me closed this in 599a63e Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants