pub fn math_op<T, F>(
    left: &PrimitiveArray<T>,
    right: &PrimitiveArray<T>,
    op: F,
) -> Result<PrimitiveArray<T>>
where
    T: PolarsNumericType,
    F: Fn(T::Native, T::Native) -> Result<T::Native>,
{
    if left.len() != right.len() {
        return Err(ArrowError::ComputeError(
            "Cannot perform math operation on arrays of different length".to_string(),
        ));
    }

    let null_bit_buffer = apply_bin_op_to_option_bitmap(
        left.data().null_bitmap(),
        right.data().null_bitmap(),
        |a, b| a & b,
    )?;

    let mut values = AlignedVec::with_capacity_aligned(left.len());
    for i in 0..left.len() {
        values.push(op(left.value(i), right.value(i))?);
    }
    let arr = aligned_vec_to_primitive_array::<T>(values, null_bit_buffer, None);
    Ok(arr)
}
/// Helper function to perform math lambda function on values from two arrays. If either
/// left or right value is null then the output value is also null, so `1 + null` is
/// `null`.
Helper function to perform math lambda function on values from two arrays. If either
left or right value is null then the output value is also null, so `1 + null` is
`null`.
Helper function to perform math lambda function on values from two arrays . If either left or right value is null then the output value is also null so ` 1 + null ` is ` null ` .
pub fn math_op<T, F>(
    left: &PrimitiveArray<T>,
    right: &PrimitiveArray<T>,
    op: F,
) -> Result<PrimitiveArray<T>>
where
    T: PolarsNumericType,
    F: Fn(T::Native, T::Native) -> Result<T::Native>,
{
    if left.len() != right.len() {
        return Err(ArrowError::ComputeError(
            "Cannot perform math operation on arrays of different length".to_string(),
        ));
    }
    let null_bit_buffer = apply_bin_op_to_option_bitmap(
        left.data().null_bitmap(),
        right.data().null_bitmap(),
        |a, b| a & b,
    )?;
    let mut values = AlignedVec::with_capacity_aligned(left.len());
    for i in 0..left.len() {
        values.push(op(left.value(i), right.value(i))?);
    }
    let arr = aligned_vec_to_primitive_array::<T>(values, null_bit_buffer, None);
    Ok(arr)
}
pub fn math_op < T , F > ( left : & PrimitiveArray < T > , right : & PrimitiveArray < T > , op : F , ) -> Result < PrimitiveArray < T > > where T : PolarsNumericType , F : Fn ( T :: Native , T :: Native ) -> Result < T :: Native > , { if left . len ( ) != right . len ( ) { return Err ( ArrowError :: ComputeError ( " " . to_string ( ) , ) ) ; } let null_bit_buffer = apply_bin_op_to_option_bitmap ( left . data ( ) . null_bitmap ( ) , right . data ( ) . null_bitmap ( ) , | a , b | a & b , ) ? ; let mut values = AlignedVec :: with_capacity_aligned ( left . len ( ) ) ; for i in 0 .. left . len ( ) { values . push ( op ( left . value ( i ) , right . value ( i ) ) ? ) ; } let arr = aligned_vec_to_primitive_array :: < T > ( values , null_bit_buffer , None ) ; Ok ( arr ) }
Helper function to perform math lambda function on values from two arrays.
Helper function to perform math lambda function on values from two arrays .
left
&PrimitiveArray<T>
right
&PrimitiveArray<T>
op
F
left
&PrimitiveArray<T>
right
&PrimitiveArray<T>
op
F