You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/10/07 11:00:14 UTC

[GitHub] [arrow] alamb commented on a change in pull request #8370: ARROW-10015: [Rust] Simd aggregate kernels

alamb commented on a change in pull request #8370:
URL: https://github.com/apache/arrow/pull/8370#discussion_r500915629



##########
File path: rust/arrow/src/array/array.rs
##########
@@ -1907,15 +1907,16 @@ impl TryFrom<Vec<(&str, ArrayRef)>> for StructArray {
         let mut null: Option<Buffer> = None;
         for (field_name, array) in values {
             let child_datum = array.data();
+            let child_datum_len = child_datum.len();

Review comment:
       I am curious (for my own future edification) if this change actually improves performance or if it was just a code cleanup

##########
File path: rust/arrow/src/buffer.rs
##########
@@ -371,118 +388,165 @@ where
 
 fn bitwise_bin_op_helper<F>(
     left: &Buffer,
-    left_offset: usize,
+    left_offset_in_bits: usize,

Review comment:
       💯  for improved naming

##########
File path: rust/arrow/src/buffer.rs
##########
@@ -371,118 +388,165 @@ where
 
 fn bitwise_bin_op_helper<F>(
     left: &Buffer,
-    left_offset: usize,
+    left_offset_in_bits: usize,

Review comment:
       I wonder too now that you know lots about what `bitwise_bin_op_helper` does, if you might be able to add a summary in the comments
   
   Like
   ```rust
   /// This function creates a new Buffer view aligned on ....
   fn bitwise_bin_op_helper<F>(
   ```

##########
File path: rust/arrow/src/compute/kernels/aggregate.rs
##########
@@ -125,6 +125,7 @@ where
 /// Returns the sum of values in the array.

Review comment:
       ```suggestion
   /// Returns the sum of values in the array (general version)
   ```

##########
File path: rust/arrow/src/compute/kernels/aggregate.rs
##########
@@ -136,23 +137,126 @@ where
         return None;
     }
 
-    let mut n: T::Native = T::default_value();
-    let data = array.data();
-    let m = array.value_slice(0, data.len());
+    let data: &[T::Native] = array.value_slice(0, array.len());
 
-    if null_count == 0 {
-        // optimized path for arrays without null values
-        for item in m.iter().take(data.len()) {
-            n = n + *item;
+    match array.data().null_buffer() {
+        None => {
+            let sum = data.iter().fold(T::default_value(), |accumulator, value| {
+                accumulator + *value
+            });
+
+            Some(sum)
         }
-    } else {
-        for (i, item) in m.iter().enumerate() {
-            if data.is_valid(i) {
-                n = n + *item;
-            }
+        Some(buffer) => {
+            let mut sum = T::default_value();
+            let data_chunks = data.chunks_exact(64);
+            let remainder = data_chunks.remainder();
+
+            let bit_chunks = buffer.bit_chunks(array.offset(), array.len());
+            &data_chunks
+                .zip(bit_chunks.iter())
+                .for_each(|(chunk, mask)| {
+                    chunk.iter().enumerate().for_each(|(i, value)| {
+                        if (mask & (1 << i)) != 0 {
+                            sum = sum + *value;
+                        }
+                    });
+                });
+
+            let remainder_bits = bit_chunks.remainder_bits();
+
+            remainder.iter().enumerate().for_each(|(i, value)| {
+                if remainder_bits & (1 << i) != 0 {
+                    sum = sum + *value;
+                }
+            });
+
+            Some(sum)
         }
     }
-    Some(n)
+}
+
+/// Returns the sum of values in the array.

Review comment:
       ```suggestion
   /// Returns the sum of values in the array (Specialized SIMD version)
   ```




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