From adcfffcfd1c5bcee98ff44dd299460994a7a99d3 Mon Sep 17 00:00:00 2001 From: Rui Mo Date: Mon, 12 Apr 2021 08:56:44 +0800 Subject: [PATCH] add normalize function (#11) --- .../gandiva/function_registry_arithmetic.cc | 3 +++ cpp/src/gandiva/precompiled/arithmetic_ops.cc | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/cpp/src/gandiva/function_registry_arithmetic.cc b/cpp/src/gandiva/function_registry_arithmetic.cc index da0983b66b237..2d119afb8fda6 100644 --- a/cpp/src/gandiva/function_registry_arithmetic.cc +++ b/cpp/src/gandiva/function_registry_arithmetic.cc @@ -169,6 +169,9 @@ std::vector GetArithmeticFunctionRegistry() { UNARY_SAFE_NULL_IF_NULL(round, {}, int64, int64), BINARY_GENERIC_SAFE_NULL_IF_NULL(round, {}, int32, int32, int32), BINARY_GENERIC_SAFE_NULL_IF_NULL(round, {}, int64, int32, int64), + // normalize for nan and zero + UNARY_SAFE_NULL_IF_NULL(normalize, {}, float32, float32), + UNARY_SAFE_NULL_IF_NULL(normalize, {}, float64, float64), // bitwise functions BINARY_GENERIC_SAFE_NULL_IF_NULL(shift_left, {}, int32, int32, int32), BINARY_GENERIC_SAFE_NULL_IF_NULL(shift_left, {}, int64, int32, int64), diff --git a/cpp/src/gandiva/precompiled/arithmetic_ops.cc b/cpp/src/gandiva/precompiled/arithmetic_ops.cc index a41062a4f2f84..1c7e7de00a609 100644 --- a/cpp/src/gandiva/precompiled/arithmetic_ops.cc +++ b/cpp/src/gandiva/precompiled/arithmetic_ops.cc @@ -223,6 +223,24 @@ NUMERIC_DATE_TYPES(BINARY_RELATIONAL_NAN, greater_than_or_equal_to_with_nan, >=) #undef BINARY_RELATIONAL_NAN +// normalize +#define NORMALIZE(IN_TYPE, OUT_TYPE) \ + FORCE_INLINE \ + gdv_##OUT_TYPE normalize_##IN_TYPE(gdv_##IN_TYPE in) { \ + if (isnan(in)) { \ + return 0.0 / 0.0; \ + } else if (in < 0 && std::abs(in) < 0.0000001) { \ + return 0.0; \ + } else { \ + return in; \ + } \ + } + +NORMALIZE(float64, float64) +NORMALIZE(float32, float32) + +#undef NORMALIZE + // cast fns : takes one param type, returns another type. #define CAST_UNARY(NAME, IN_TYPE, OUT_TYPE) \ FORCE_INLINE \