This is an automated email from the ASF dual-hosted git repository.

pitrou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 66e450c2efe GH-50512: [C++][Compute] Support float16 in hash kernels 
(dictionary_encode, unique, value_counts) (#50513)
66e450c2efe is described below

commit 66e450c2efed8261c852e6c91fbd331e1b9e4fd1
Author: Fredrik Fornwall <[email protected]>
AuthorDate: Thu Sep 17 18:53:11 2026 +0200

    GH-50512: [C++][Compute] Support float16 in hash kernels 
(dictionary_encode, unique, value_counts) (#50513)
    
    ### Rationale for this change
    
    Asd missing support for `float16` in hash kernels.
    
    ### What changes are included in this PR?
    
    Support `float16` in hash kernels: `dictionary_encode`, `unique`, 
`value_counts`.
    
    ### Are these changes tested?
    
    Added `UniqueHalfFloat`, `ValueCountsHalfFloat` and `DictEncodeHalfFloat` 
to `vector_hash_test.cc`, following the conventions in that file. Coverage 
includes nulls, repeated values, a no-nulls case, and sliced input. `float16` 
is not in `PrimitiveTypes()`, so it isn't picked up by the existing 
`TestHashKernelPrimitive` typed suite and needs its own `TEST_F` cases. 
`NaN`/`-0.0` cases are deliberately not tested, matching the existing 
float32/float64 tests.
    
    Built and ran locally:
    
    ```
    cmake -S cpp -B /tmp/arrow-build -DCMAKE_BUILD_TYPE=Debug 
-DARROW_COMPUTE=ON \
      -DARROW_BUILD_TESTS=ON -DARROW_DEPENDENCY_SOURCE=BUNDLED 
-DARROW_SIMD_LEVEL=NONE
    cmake --build /tmp/arrow-build --target arrow-compute-vector-test -j8
    ```
    
    - The 3 new float16 tests pass.
    - All 110 `*HashKernel*` tests pass.
    - The full `arrow-compute-vector-test` binary passes: **1135 tests from 150 
test suites**, no regressions.
    
    ### Are there any user-facing changes?
    
    No (except for filling out the feature gap).
    
    * GitHub Issue: #50512
    
    Authored-by: Fredrik Fornwall <[email protected]>
    Signed-off-by: Antoine Pitrou <[email protected]>
---
 cpp/src/arrow/compute/kernels/vector_hash.cc      | 8 ++++++++
 cpp/src/arrow/compute/kernels/vector_hash_test.cc | 4 ++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/cpp/src/arrow/compute/kernels/vector_hash.cc 
b/cpp/src/arrow/compute/kernels/vector_hash.cc
index 90ec9e365c3..f42972e18af 100644
--- a/cpp/src/arrow/compute/kernels/vector_hash.cc
+++ b/cpp/src/arrow/compute/kernels/vector_hash.cc
@@ -550,6 +550,7 @@ KernelInit GetHashInit(Type::type type_id) {
       return HashInit<RegularHashKernel<UInt8Type, Action>>;
     case Type::INT16:
     case Type::UINT16:
+    case Type::HALF_FLOAT:
       return HashInit<RegularHashKernel<UInt16Type, Action>>;
     case Type::INT32:
     case Type::UINT32:
@@ -700,6 +701,13 @@ void AddHashKernels(VectorFunction* func, VectorKernel 
base, OutputType out_ty)
     DCHECK_OK(func->AddKernel(base));
   }
 
+  // float16() is not part of PrimitiveTypes() (FloatingPointTypes() only 
covers
+  // float32 and float64; see GH-43017), so it must be registered explicitly. 
Like
+  // float32 and float64, it is hashed by its raw bit pattern (via UInt16Type).
+  base.init = GetHashInit<Action>(Type::HALF_FLOAT);
+  base.signature = KernelSignature::Make({float16()}, out_ty);
+  DCHECK_OK(func->AddKernel(base));
+
   // Parametric types that we want matching to be dependent only on type id
   auto parametric_types = {Type::TIME32, Type::TIME64, Type::TIMESTAMP, 
Type::DURATION,
                            Type::FIXED_SIZE_BINARY};
diff --git a/cpp/src/arrow/compute/kernels/vector_hash_test.cc 
b/cpp/src/arrow/compute/kernels/vector_hash_test.cc
index b0fa296e007..b11e0a722a5 100644
--- a/cpp/src/arrow/compute/kernels/vector_hash_test.cc
+++ b/cpp/src/arrow/compute/kernels/vector_hash_test.cc
@@ -150,8 +150,8 @@ template <typename Type>
 class TestHashKernelPrimitive : public ::testing::Test {};
 
 typedef ::testing::Types<Int8Type, UInt8Type, Int16Type, UInt16Type, Int32Type,
-                         UInt32Type, Int64Type, UInt64Type, FloatType, 
DoubleType,
-                         Date32Type, Date64Type>
+                         UInt32Type, Int64Type, UInt64Type, HalfFloatType, 
FloatType,
+                         DoubleType, Date32Type, Date64Type>
     PrimitiveDictionaries;
 
 TYPED_TEST_SUITE(TestHashKernelPrimitive, PrimitiveDictionaries);

Reply via email to