From f32042cbb6fa1f8216b076e65ea0f516ac0c3cc7 Mon Sep 17 00:00:00 2001 From: Liang-Chi Hsieh Date: Mon, 28 Nov 2022 09:02:20 -0800 Subject: [PATCH] Remove _mut arithmetic kernels --- arrow/src/compute/kernels/arithmetic.rs | 51 +++---------------------- 1 file changed, 5 insertions(+), 46 deletions(-) diff --git a/arrow/src/compute/kernels/arithmetic.rs b/arrow/src/compute/kernels/arithmetic.rs index cde4da0df9d4..0737f2974353 100644 --- a/arrow/src/compute/kernels/arithmetic.rs +++ b/arrow/src/compute/kernels/arithmetic.rs @@ -915,47 +915,6 @@ where Ok(unary(array, |value| value.add_wrapping(scalar))) } -/// Mutate an array by adding every value in an array by a scalar. If any value in the array -/// is null then the result is also null. -/// -/// This only mutates the array if it is not shared buffers with other arrays. For shared -/// array, it returns an `Err` which wraps input array. -/// -/// This doesn't detect overflow. Once overflowing, the result will wrap around. -/// For an overflow-checking variant, use `add_scalar_checked_mut` instead. -pub fn add_scalar_mut( - array: PrimitiveArray, - scalar: T::Native, -) -> std::result::Result, PrimitiveArray> -where - T: ArrowNumericType, - T::Native: ArrowNativeTypeOp, -{ - unary_mut(array, |value| value.add_wrapping(scalar)) -} - -/// Mutate an array by adding every value in an array by a scalar. If any value in the array -/// is null then the result is also null. -/// -/// This only mutates the array if it is not shared buffers with other arrays. For shared -/// array, it returns an `Err` which wraps input array. -/// -/// This detects overflow and returns an `Err` within an `Ok` which wraps an `Error` of -/// actual error. For an non-overflow-checking variant, use `add_scalar_mut` instead. -pub fn add_scalar_checked_mut( - array: PrimitiveArray, - scalar: T::Native, -) -> std::result::Result< - std::result::Result, ArrowError>, - PrimitiveArray, -> -where - T: ArrowNumericType, - T::Native: ArrowNativeTypeOp, -{ - try_unary_mut(array, |value| value.add_checked(scalar)) -} - /// Add every value in an array by a scalar. If any value in the array is null then the /// result is also null. /// @@ -3142,24 +3101,24 @@ mod tests { } #[test] - fn test_primitive_array_add_scalar_mut() { + fn test_primitive_add_scalar_by_unary_mut() { let a = Int32Array::from(vec![15, 14, 9, 8, 1]); let b = 3; - let c = add_scalar_mut(a, b).unwrap(); + let c = unary_mut(a, |value| value.add_wrapping(b)).unwrap(); let expected = Int32Array::from(vec![18, 17, 12, 11, 4]); assert_eq!(c, expected); } #[test] - fn test_primitive_add_scalar_mut_wrapping_overflow() { + fn test_primitive_add_scalar_overflow_by_try_unary_mut() { let a = Int32Array::from(vec![i32::MAX, i32::MIN]); - let wrapped = add_scalar_mut(a, 1).unwrap(); + let wrapped = unary_mut(a, |value| value.add_wrapping(1)).unwrap(); let expected = Int32Array::from(vec![-2147483648, -2147483647]); assert_eq!(expected, wrapped); let a = Int32Array::from(vec![i32::MAX, i32::MIN]); - let overflow = add_scalar_checked_mut(a, 1); + let overflow = try_unary_mut(a, |value| value.add_checked(1)); let _ = overflow.unwrap().expect_err("overflow should be detected"); } }