Skip to content

Commit

Permalink
Rename MIN/MAX constants to make it explicit they use the total order…
Browse files Browse the repository at this point in the history
… relation
  • Loading branch information
jhorstmann committed Nov 21, 2023
1 parent 6a6b5f5 commit 175c799
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 32 deletions.
8 changes: 6 additions & 2 deletions arrow-arith/src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ struct MinAccumulator<T: ArrowNativeTypeOp> {

impl<T: ArrowNativeTypeOp> Default for MinAccumulator<T> {
fn default() -> Self {
Self { min: T::MAX }
Self {
min: T::MAX_TOTAL_ORDER,
}
}
}

Expand Down Expand Up @@ -120,7 +122,9 @@ struct MaxAccumulator<T: ArrowNativeTypeOp> {

impl<T: ArrowNativeTypeOp> Default for MaxAccumulator<T> {
fn default() -> Self {
Self { max: T::MIN }
Self {
max: T::MIN_TOTAL_ORDER,
}
}
}

Expand Down
60 changes: 30 additions & 30 deletions arrow-array/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ pub trait ArrowNativeTypeOp: ArrowNativeType {
/// The minimum value and identity for the `max` aggregation.
/// Note that the aggregation uses the total order predicate for floating point values,
/// which means that this value is a negative NaN.
const MIN: Self;
const MIN_TOTAL_ORDER: Self;

/// The maximum value and identity for the `min` aggregation.
/// Note that the aggregation uses the total order predicate for floating point values,
/// which means that this value is a positive NaN.
const MAX: Self;
const MAX_TOTAL_ORDER: Self;

/// Checked addition operation
fn add_checked(self, rhs: Self) -> Result<Self, ArrowError>;
Expand Down Expand Up @@ -145,8 +145,8 @@ macro_rules! native_type_op {
impl ArrowNativeTypeOp for $t {
const ZERO: Self = $zero;
const ONE: Self = $one;
const MIN: Self = $min;
const MAX: Self = $max;
const MIN_TOTAL_ORDER: Self = $min;
const MAX_TOTAL_ORDER: Self = $max;

#[inline]
fn add_checked(self, rhs: Self) -> Result<Self, ArrowError> {
Expand Down Expand Up @@ -289,8 +289,8 @@ macro_rules! native_type_float_op {
impl ArrowNativeTypeOp for $t {
const ZERO: Self = $zero;
const ONE: Self = $one;
const MIN: Self = $min;
const MAX: Self = $max;
const MIN_TOTAL_ORDER: Self = $min;
const MAX_TOTAL_ORDER: Self = $max;

#[inline]
fn add_checked(self, rhs: Self) -> Result<Self, ArrowError> {
Expand Down Expand Up @@ -818,37 +818,37 @@ mod tests {

#[test]
fn test_float_total_order_min_max() {
assert!(<f64 as ArrowNativeTypeOp>::MIN.is_lt(f64::NEG_INFINITY));
assert!(<f64 as ArrowNativeTypeOp>::MAX.is_gt(f64::INFINITY));
assert!(<f64 as ArrowNativeTypeOp>::MIN_TOTAL_ORDER.is_lt(f64::NEG_INFINITY));
assert!(<f64 as ArrowNativeTypeOp>::MAX_TOTAL_ORDER.is_gt(f64::INFINITY));

assert!(<f64 as ArrowNativeTypeOp>::MIN.is_nan());
assert!(<f64 as ArrowNativeTypeOp>::MIN.is_sign_negative());
assert!(<f64 as ArrowNativeTypeOp>::MIN.is_lt(-f64::NAN));
assert!(<f64 as ArrowNativeTypeOp>::MIN_TOTAL_ORDER.is_nan());
assert!(<f64 as ArrowNativeTypeOp>::MIN_TOTAL_ORDER.is_sign_negative());
assert!(<f64 as ArrowNativeTypeOp>::MIN_TOTAL_ORDER.is_lt(-f64::NAN));

assert!(<f64 as ArrowNativeTypeOp>::MAX.is_nan());
assert!(<f64 as ArrowNativeTypeOp>::MAX.is_sign_positive());
assert!(<f64 as ArrowNativeTypeOp>::MAX.is_gt(f64::NAN));
assert!(<f64 as ArrowNativeTypeOp>::MAX_TOTAL_ORDER.is_nan());
assert!(<f64 as ArrowNativeTypeOp>::MAX_TOTAL_ORDER.is_sign_positive());
assert!(<f64 as ArrowNativeTypeOp>::MAX_TOTAL_ORDER.is_gt(f64::NAN));

assert!(<f32 as ArrowNativeTypeOp>::MIN.is_lt(f32::NEG_INFINITY));
assert!(<f32 as ArrowNativeTypeOp>::MAX.is_gt(f32::INFINITY));
assert!(<f32 as ArrowNativeTypeOp>::MIN_TOTAL_ORDER.is_lt(f32::NEG_INFINITY));
assert!(<f32 as ArrowNativeTypeOp>::MAX_TOTAL_ORDER.is_gt(f32::INFINITY));

assert!(<f32 as ArrowNativeTypeOp>::MIN.is_nan());
assert!(<f32 as ArrowNativeTypeOp>::MIN.is_sign_negative());
assert!(<f32 as ArrowNativeTypeOp>::MIN.is_lt(-f32::NAN));
assert!(<f32 as ArrowNativeTypeOp>::MIN_TOTAL_ORDER.is_nan());
assert!(<f32 as ArrowNativeTypeOp>::MIN_TOTAL_ORDER.is_sign_negative());
assert!(<f32 as ArrowNativeTypeOp>::MIN_TOTAL_ORDER.is_lt(-f32::NAN));

assert!(<f32 as ArrowNativeTypeOp>::MAX.is_nan());
assert!(<f32 as ArrowNativeTypeOp>::MAX.is_sign_positive());
assert!(<f32 as ArrowNativeTypeOp>::MAX.is_gt(f32::NAN));
assert!(<f32 as ArrowNativeTypeOp>::MAX_TOTAL_ORDER.is_nan());
assert!(<f32 as ArrowNativeTypeOp>::MAX_TOTAL_ORDER.is_sign_positive());
assert!(<f32 as ArrowNativeTypeOp>::MAX_TOTAL_ORDER.is_gt(f32::NAN));

assert!(<f16 as ArrowNativeTypeOp>::MIN.is_lt(f16::NEG_INFINITY));
assert!(<f16 as ArrowNativeTypeOp>::MAX.is_gt(f16::INFINITY));
assert!(<f16 as ArrowNativeTypeOp>::MIN_TOTAL_ORDER.is_lt(f16::NEG_INFINITY));
assert!(<f16 as ArrowNativeTypeOp>::MAX_TOTAL_ORDER.is_gt(f16::INFINITY));

assert!(<f16 as ArrowNativeTypeOp>::MIN.is_nan());
assert!(<f16 as ArrowNativeTypeOp>::MIN.is_sign_negative());
assert!(<f16 as ArrowNativeTypeOp>::MIN.is_lt(-f16::NAN));
assert!(<f16 as ArrowNativeTypeOp>::MIN_TOTAL_ORDER.is_nan());
assert!(<f16 as ArrowNativeTypeOp>::MIN_TOTAL_ORDER.is_sign_negative());
assert!(<f16 as ArrowNativeTypeOp>::MIN_TOTAL_ORDER.is_lt(-f16::NAN));

assert!(<f16 as ArrowNativeTypeOp>::MAX.is_nan());
assert!(<f16 as ArrowNativeTypeOp>::MAX.is_sign_positive());
assert!(<f16 as ArrowNativeTypeOp>::MAX.is_gt(f16::NAN));
assert!(<f16 as ArrowNativeTypeOp>::MAX_TOTAL_ORDER.is_nan());
assert!(<f16 as ArrowNativeTypeOp>::MAX_TOTAL_ORDER.is_sign_positive());
assert!(<f16 as ArrowNativeTypeOp>::MAX_TOTAL_ORDER.is_gt(f16::NAN));
}
}

0 comments on commit 175c799

Please sign in to comment.