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



##########
File path: rust/arrow/src/compute/kernels/arithmetic.rs
##########
@@ -256,6 +256,49 @@ where
     Ok(PrimitiveArray::<T>::from(Arc::new(data)))
 }
 
+/// Scalar-divisor version of `math_divide`.
+fn math_divide_scalar<T>(
+    array: &PrimitiveArray<T>,
+    divisor: T::Native,
+) -> Result<PrimitiveArray<T>>
+where
+    T: ArrowNumericType,
+    T::Native: Div<Output = T::Native> + Zero,
+{
+    if divisor.is_zero() {
+        return Err(ArrowError::DivideByZero);
+    }
+
+    let null_bit_buffer = array.data_ref().null_buffer().cloned();
+
+    let buffer = if let Some(b) = &null_bit_buffer {
+        let values = array.values().iter().enumerate().map(|(i, value)| {
+            let is_valid = unsafe { bit_util::get_bit_raw(b.as_ptr(), i) };
+            if is_valid {
+                *value / divisor
+            } else {
+                T::default_value()
+            }
+        });
+        unsafe { Buffer::from_trusted_len_iter(values) }
+    } else {
+        // no value is null
+        let values = array.values().iter().map(|value| *value / divisor);
+        unsafe { Buffer::from_trusted_len_iter(values) }
+    };

Review comment:
       Thanks, @abreis , looks great!
   
   Exactly. This is a general reason why arrow format (and others) have the 
mask bitmap separated from the values is that it enables stuff like this.
   
   fwiw, I have seen this in other instances as-well. I have not looked at the 
compiled code, but my hypothesis is that as-well: auto-vectorization is kicking 
in, which is great because SIMD requires nightly, and this does not :D




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to