Skip to content

Commit a03d4ee

Browse files
MazterQyoumcheshkov
authored andcommitted
feat: Support powf for arrays
1 parent aac0907 commit a03d4ee

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

arrow/src/compute/kernels/arithmetic.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,19 @@ where
488488
Ok(unary(array, |x| -x))
489489
}
490490

491+
/// Perform `left ^ right` (pow) operation on two arrays. If either left or right value is null
492+
/// then the result is also null.
493+
pub fn powf<T>(
494+
left: &PrimitiveArray<T>,
495+
right: &PrimitiveArray<T>,
496+
) -> Result<PrimitiveArray<T>>
497+
where
498+
T: datatypes::ArrowFloatNumericType,
499+
T::Native: Pow<T::Native, Output = T::Native>,
500+
{
501+
math_op(left, right, |a, b| a.pow(b))
502+
}
503+
491504
/// Raise array with floating point values to the power of a scalar.
492505
pub fn powf_scalar<T>(
493506
array: &PrimitiveArray<T>,
@@ -1043,6 +1056,16 @@ mod tests {
10431056
assert_eq!(expected, actual);
10441057
}
10451058

1059+
#[test]
1060+
fn test_primitive_array_powf() {
1061+
let a = Float64Array::from(vec![3.0, 25.0, -2.5]);
1062+
let b = Float64Array::from(vec![5.0, -1.5, 2.0]);
1063+
let c = powf(&a, &b).unwrap();
1064+
assert_eq!(243.0, c.value(0));
1065+
assert_eq!(0.008, c.value(1));
1066+
assert_eq!(6.25, c.value(2));
1067+
}
1068+
10461069
#[test]
10471070
fn test_arithmetic_kernel_should_not_rely_on_padding() {
10481071
let a: UInt8Array = (0..128_u8).into_iter().map(Some).collect();

0 commit comments

Comments
 (0)