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 2022/09/06 10:11:14 UTC
[GitHub] [arrow-rs] tustvold commented on a diff in pull request #2658: Change max/min string macro to generic helper function min_max_helper
tustvold commented on code in PR #2658:
URL: https://github.com/apache/arrow-rs/pull/2658#discussion_r963523215
##########
arrow/src/compute/kernels/aggregate.rs:
##########
@@ -142,46 +105,48 @@ pub fn max_boolean(array: &BooleanArray) -> Option<bool> {
.or(Some(false))
}
-/// Helper to compute min/max of [`GenericStringArray`] and [`GenericBinaryArray`]
-macro_rules! min_max_binary_string {
- ($array: expr, $cmp: expr) => {{
- let null_count = $array.null_count();
- if null_count == $array.len() {
- None
- } else if null_count == 0 {
- // JUSTIFICATION
- // Benefit: ~8% speedup
- // Soundness: `i` is always within the array bounds
- (0..$array.len())
- .map(|i| unsafe { $array.value_unchecked(i) })
- .reduce(|acc, item| if $cmp(acc, item) { item } else { acc })
- } else {
- $array
- .iter()
- .flatten()
- .reduce(|acc, item| if $cmp(acc, item) { item } else { acc })
- }
- }};
+/// Helper to compute min/max of [`ArrayAccessor`].
+#[multiversion]
+#[clone(target = "x86_64+avx")]
+fn min_max_helper<T, A: ArrayAccessor<Item = T>, F>(array: A, cmp: F) -> Option<T>
+where
+ F: Fn(&T, &T) -> bool,
+{
+ let null_count = array.null_count();
+ if null_count == array.len() {
+ None
+ } else if null_count == 0 {
+ // JUSTIFICATION
+ // Benefit: ~8% speedup
+ // Soundness: `i` is always within the array bounds
+ (0..array.len())
+ .map(|i| unsafe { array.value_unchecked(i) })
+ .reduce(|acc, item| if cmp(&acc, &item) { item } else { acc })
+ } else {
+ let iter = ArrayIter::new(array);
Review Comment:
It might be faster to use `BitIndexIterator` here, something potentially for a future PR
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org