Skip to content

Commit 66e450c

Browse files
authored
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]>
1 parent 68610e4 commit 66e450c

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎cpp/src/arrow/compute/kernels/vector_hash.cc‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ KernelInit GetHashInit(Type::type type_id) {
550550
return HashInit<RegularHashKernel<UInt8Type, Action>>;
551551
case Type::INT16:
552552
case Type::UINT16:
553+
case Type::HALF_FLOAT:
553554
return HashInit<RegularHashKernel<UInt16Type, Action>>;
554555
case Type::INT32:
555556
case Type::UINT32:
@@ -700,6 +701,13 @@ void AddHashKernels(VectorFunction* func, VectorKernel base, OutputType out_ty)
700701
DCHECK_OK(func->AddKernel(base));
701702
}
702703

704+
// float16() is not part of PrimitiveTypes() (FloatingPointTypes() only covers
705+
// float32 and float64; see GH-43017), so it must be registered explicitly. Like
706+
// float32 and float64, it is hashed by its raw bit pattern (via UInt16Type).
707+
base.init = GetHashInit<Action>(Type::HALF_FLOAT);
708+
base.signature = KernelSignature::Make({float16()}, out_ty);
709+
DCHECK_OK(func->AddKernel(base));
710+
703711
// Parametric types that we want matching to be dependent only on type id
704712
auto parametric_types = {Type::TIME32, Type::TIME64, Type::TIMESTAMP, Type::DURATION,
705713
Type::FIXED_SIZE_BINARY};

‎cpp/src/arrow/compute/kernels/vector_hash_test.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ template <typename Type>
150150
class TestHashKernelPrimitive : public ::testing::Test {};
151151

152152
typedef ::testing::Types<Int8Type, UInt8Type, Int16Type, UInt16Type, Int32Type,
153-
UInt32Type, Int64Type, UInt64Type, FloatType, DoubleType,
154-
Date32Type, Date64Type>
153+
UInt32Type, Int64Type, UInt64Type, HalfFloatType, FloatType,
154+
DoubleType, Date32Type, Date64Type>
155155
PrimitiveDictionaries;
156156

157157
TYPED_TEST_SUITE(TestHashKernelPrimitive, PrimitiveDictionaries);

0 commit comments

Comments
 (0)