jorgecarleitao commented on a change in pull request #9454:
URL: https://github.com/apache/arrow/pull/9454#discussion_r577309641



##########
File path: rust/arrow/src/compute/kernels/arithmetic.rs
##########
@@ -387,9 +430,42 @@ where
     Ok(())
 }
 
-/// SIMD vectorized version of `divide`, the divide kernel needs it's own 
implementation as there
-/// is a need to handle situations where a divide by `0` occurs.  This is 
complicated by `NULL`
-/// slots and padding.
+/// Scalar-divisor version of `simd_checked_divide_remainder`.
+#[cfg(simd)]
+#[inline]
+fn simd_checked_divide_scalar_remainder<T: ArrowNumericType>(
+    valid_mask: Option<u64>,
+    array_chunks: ChunksExact<T::Native>,
+    divisor: T::Native,
+    result_chunks: ChunksExactMut<T::Native>,
+) -> Result<()>
+where
+    T::Native: Zero + Div<Output = T::Native>,
+{
+    if divisor.is_zero() {
+        return Err(ArrowError::DivideByZero);
+    }
+
+    let result_remainder = result_chunks.into_remainder();
+    let array_remainder = array_chunks.remainder();
+
+    result_remainder
+        .iter_mut()
+        .zip(array_remainder.iter())
+        .enumerate()
+        .for_each(|(i, (result_scalar, array_scalar))| {
+            if valid_mask.map(|mask| mask & (1 << i) != 0).unwrap_or(true) {
+                *result_scalar = *array_scalar / divisor;
+            }
+        });

Review comment:
       same here: no need to run the mask: just operate over the whole thing 
ignoring nulls.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to