Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Fixed element-wise
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Jan 10, 2022
1 parent 099d5ed commit 81aacde
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
20 changes: 10 additions & 10 deletions src/compute/aggregate/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ pub trait SimdOrd<T> {
/// reduce itself to the maximum
fn min_element(self) -> T;
/// lane-wise maximum between two instances
fn max(self, x: Self) -> Self;
fn max_lane(self, x: Self) -> Self;
/// lane-wise minimum between two instances
fn min(self, x: Self) -> Self;
fn min_lane(self, x: Self) -> Self;
/// returns a new instance with all lanes equal to `MIN`
fn new_min() -> Self;
/// returns a new instance with all lanes equal to `MAX`
Expand Down Expand Up @@ -112,11 +112,11 @@ where

let chunk_reduced = chunks.fold(T::Simd::new_min(), |acc, chunk| {
let chunk = T::Simd::from_chunk(chunk);
acc.min(chunk)
acc.min_lane(chunk)
});

let remainder = T::Simd::from_incomplete_chunk(remainder, T::Simd::MAX);
let reduced = chunk_reduced.min(remainder);
let reduced = chunk_reduced.min_lane(remainder);

reduced.min_element()
}
Expand All @@ -135,14 +135,14 @@ where
let chunk = T::Simd::from_chunk(chunk);
let mask = <T::Simd as NativeSimd>::Mask::from_chunk(validity_chunk);
let chunk = chunk.select(mask, T::Simd::new_min());
acc.min(chunk)
acc.min_lane(chunk)
},
);

let remainder = T::Simd::from_incomplete_chunk(chunks.remainder(), T::Simd::MAX);
let mask = <T::Simd as NativeSimd>::Mask::from_chunk(validity_masks.remainder());
let remainder = remainder.select(mask, T::Simd::new_min());
let reduced = chunk_reduced.min(remainder);
let reduced = chunk_reduced.min_lane(remainder);

reduced.min_element()
}
Expand Down Expand Up @@ -191,11 +191,11 @@ where

let chunk_reduced = chunks.fold(T::Simd::new_max(), |acc, chunk| {
let chunk = T::Simd::from_chunk(chunk);
acc.max(chunk)
acc.max_lane(chunk)
});

let remainder = T::Simd::from_incomplete_chunk(remainder, T::Simd::MIN);
let reduced = chunk_reduced.max(remainder);
let reduced = chunk_reduced.max_lane(remainder);

reduced.max_element()
}
Expand All @@ -214,14 +214,14 @@ where
let chunk = T::Simd::from_chunk(chunk);
let mask = <T::Simd as NativeSimd>::Mask::from_chunk(validity_chunk);
let chunk = chunk.select(mask, T::Simd::new_max());
acc.max(chunk)
acc.max_lane(chunk)
},
);

let remainder = T::Simd::from_incomplete_chunk(chunks.remainder(), T::Simd::MIN);
let mask = <T::Simd as NativeSimd>::Mask::from_chunk(validity_masks.remainder());
let remainder = remainder.select(mask, T::Simd::new_max());
let reduced = chunk_reduced.max(remainder);
let reduced = chunk_reduced.max_lane(remainder);

reduced.max_element()
}
Expand Down
8 changes: 4 additions & 4 deletions src/compute/aggregate/simd/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ macro_rules! simd_ord_int {
}

#[inline]
fn max(self, x: Self) -> Self {
fn max_lane(self, x: Self) -> Self {
let mut result = <$simd>::default();
result
.0
Expand All @@ -82,7 +82,7 @@ macro_rules! simd_ord_int {
}

#[inline]
fn min(self, x: Self) -> Self {
fn min_lane(self, x: Self) -> Self {
let mut result = <$simd>::default();
result
.0
Expand Down Expand Up @@ -123,7 +123,7 @@ macro_rules! simd_ord_float {
}

#[inline]
fn max(self, x: Self) -> Self {
fn max_lane(self, x: Self) -> Self {
let mut result = <$simd>::default();
result
.0
Expand All @@ -135,7 +135,7 @@ macro_rules! simd_ord_float {
}

#[inline]
fn min(self, x: Self) -> Self {
fn min_lane(self, x: Self) -> Self {
let mut result = <$simd>::default();
result
.0
Expand Down
12 changes: 6 additions & 6 deletions src/compute/aggregate/simd/packed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ macro_rules! simd_ord_int {
}

#[inline]
fn max(self, x: Self) -> Self {
std::cmp::Ord::max(self, x)
fn max_lane(self, x: Self) -> Self {
self.max(x)
}

#[inline]
fn min(self, x: Self) -> Self {
std::cmp::Ord::min(self, x)
fn min_lane(self, x: Self) -> Self {
self.min(x)
}

#[inline]
Expand Down Expand Up @@ -81,12 +81,12 @@ macro_rules! simd_ord_float {
}

#[inline]
fn max(self, x: Self) -> Self {
fn max_lane(self, x: Self) -> Self {
self.max(x)
}

#[inline]
fn min(self, x: Self) -> Self {
fn min_lane(self, x: Self) -> Self {
self.min(x)
}

Expand Down
16 changes: 16 additions & 0 deletions tests/it/compute/aggregate/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ fn min_max_f64_large() {
None,
Some(5.0),
Some(2.0),
None,
None,
Some(8.0),
Some(2.0),
None,
None,
Some(5.0),
Some(2.0),
None,
None,
Some(8.0),
Some(2.0),
None,
None,
Some(5.0),
Some(2.0),
]);
assert_eq!(Some(2.0), min_primitive(&a));
assert_eq!(Some(8.0), max_primitive(&a));
Expand Down

0 comments on commit 81aacde

Please sign in to comment.