2424#include " arrow/type.h"
2525#include " arrow/type_traits.h"
2626#include " arrow/util/decimal.h"
27+ #include " arrow/util/float16.h"
2728#include " arrow/util/int_util_overflow.h"
29+ #include " arrow/util/logging.h"
2830#include " arrow/util/macros.h"
2931
3032namespace arrow {
@@ -34,6 +36,7 @@ using internal::DivideWithOverflow;
3436using internal::MultiplyWithOverflow;
3537using internal::NegateWithOverflow;
3638using internal::SubtractWithOverflow;
39+ using util::Float16;
3740
3841namespace compute {
3942namespace internal {
@@ -470,6 +473,11 @@ struct Negate {
470473 return -arg;
471474 }
472475
476+ template <typename T, typename Arg>
477+ static constexpr enable_if_half_float_value<T> Call (KernelContext*, Arg arg, Status*) {
478+ return -arg;
479+ }
480+
473481 template <typename T, typename Arg>
474482 static constexpr enable_if_unsigned_integer_value<T> Call (KernelContext*, Arg arg,
475483 Status*) {
@@ -517,6 +525,12 @@ struct NegateChecked {
517525 return -arg;
518526 }
519527
528+ template <typename T, typename Arg>
529+ static constexpr enable_if_half_float_value<T> Call (KernelContext*, Arg arg, Status*) {
530+ static_assert (std::is_same<T, Arg>::value, " " );
531+ return -arg;
532+ }
533+
520534 template <typename T, typename Arg>
521535 static constexpr enable_if_decimal_value<Arg, T> Call (KernelContext*, Arg arg,
522536 Status*) {
@@ -633,6 +647,15 @@ struct Sign {
633647 return std::isnan (arg) ? arg : ((arg == 0 ) ? 0 : (std::signbit (arg) ? -1 : 1 ));
634648 }
635649
650+ template <typename T, typename Arg>
651+ static constexpr enable_if_half_float_value<Arg, T> Call (KernelContext*, Arg arg,
652+ Status*) {
653+ return arg.is_nan ()
654+ ? arg
655+ : (arg.is_zero () ? Float16::zero ()
656+ : (arg.signbit () ? -Float16::one () : Float16::one ()));
657+ }
658+
636659 template <typename T, typename Arg>
637660 static constexpr enable_if_unsigned_integer_value<Arg, T> Call (KernelContext*, Arg arg,
638661 Status*) {
@@ -705,7 +728,13 @@ struct Identity;
705728template <>
706729struct Identity <Add> {
707730 template <typename Value>
708- static constexpr Value value{0 };
731+ static constexpr Value value () {
732+ if constexpr (std::is_same_v<Float16, Value>) {
733+ return Float16::zero ();
734+ } else {
735+ return 0 ;
736+ }
737+ }
709738};
710739
711740template <>
@@ -714,7 +743,13 @@ struct Identity<AddChecked> : Identity<Add> {};
714743template <>
715744struct Identity <Multiply> {
716745 template <typename Value>
717- static constexpr Value value{1 };
746+ static constexpr Value value () {
747+ if constexpr (std::is_same_v<Float16, Value>) {
748+ return Float16::one ();
749+ } else {
750+ return 1 ;
751+ }
752+ }
718753};
719754
720755template <>
@@ -723,13 +758,17 @@ struct Identity<MultiplyChecked> : Identity<Multiply> {};
723758template <>
724759struct Identity <Max> {
725760 template <typename Value>
726- static constexpr Value value{std::numeric_limits<Value>::min ()};
761+ static constexpr Value value () {
762+ return std::numeric_limits<Value>::min ();
763+ }
727764};
728765
729766template <>
730767struct Identity <Min> {
731768 template <typename Value>
732- static constexpr Value value{std::numeric_limits<Value>::max ()};
769+ static constexpr Value value () {
770+ return std::numeric_limits<Value>::max ();
771+ }
733772};
734773
735774} // namespace internal
0 commit comments