Skip to content

GH-50512: [C++][Compute] Support float16 in hash kernels (dictionary_encode, unique, value_counts) - #50513

Open
fornwall wants to merge 2 commits into
apache:mainfrom
fornwall:fix-float16-hash-kernels
Open

GH-50512: [C++][Compute] Support float16 in hash kernels (dictionary_encode, unique, value_counts)#50513
fornwall wants to merge 2 commits into
apache:mainfrom
fornwall:fix-float16-hash-kernels

Conversation

@fornwall

@fornwall fornwall commented Jul 15, 2026

Copy link
Copy Markdown

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).

@fornwall
fornwall requested a review from pitrou as a code owner July 15, 2026 10:28
@fornwall
fornwall force-pushed the fix-float16-hash-kernels branch from cfc957b to b61813c Compare July 15, 2026 10:29
@fornwall fornwall changed the title Support float16 in hash kernels (dictionary_encode, unique, value_counts) GH-50512: [C++][Compute] Support float16 in hash kernels (dictionary_encode, unique, value_counts) Jul 15, 2026
@github-actions github-actions Bot added the awaiting review Awaiting review label Jul 15, 2026
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #50512 has been automatically assigned in GitHub to PR creator.

@pitrou pitrou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @fornwall ! Here are a couple comments, but LGTM on the principle.

Comment thread cpp/src/arrow/compute/kernels/vector_hash.cc
Comment thread cpp/src/arrow/compute/kernels/vector_hash_test.cc Outdated
…nts)

dictionary_encode(), unique() and value_counts() failed on half_float
input with:

  ArrowNotImplementedError: Function 'dictionary_encode' has no kernel
  matching input types (halffloat)

AddHashKernels() registers kernels by iterating PrimitiveTypes(), which
is derived from FloatingPointTypes() and only contains float32 and
float64 -- float16 is absent, so no half_float kernel was ever
registered. GetHashInit() also had no HALF_FLOAT case.

Rather than widening the public FloatingPointTypes()/NumericTypes()/
PrimitiveTypes() lists (which many other kernel registrations consume,
e.g. aggregate_basic.cc, and which would change behaviour well beyond
this bug), register the float16 kernel explicitly in AddHashKernels()
and dispatch HALF_FLOAT in GetHashInit().

HALF_FLOAT is hashed via RegularHashKernel<UInt16Type>, i.e. by its raw
bit pattern. This mirrors the existing treatment of float32 (hashed via
UInt32Type) and float64 (via UInt64Type), so NaN/-0.0 semantics are
consistent with what those types already do. HalfFloatType::c_type is
already uint16_t, and the hash kernel keeps the original type for its
output, so the resulting dictionary is correctly typed float16.

Signed-off-by: Fredrik Fornwall <fredrik@fornwall.net>
TestHashKernelPrimitive takes a hand-written ::testing::Types list, not
PrimitiveTypes(), so there was no reason for float16 to need its own
tests (the earlier comment claiming otherwise was wrong).

Adding HalfFloatType to the list drops 39 lines and gains coverage: the
standalone tests only exercised Unique/ValueCounts/DictEncode, while the
typed suite also runs ZeroChunks and PrimitiveResizeTable.

Signed-off-by: Fredrik Fornwall <fredrik@fornwall.net>
@fornwall
fornwall force-pushed the fix-float16-hash-kernels branch from 8e27efe to 723f3f9 Compare September 11, 2026 23:10
@fornwall
fornwall requested a review from pitrou September 11, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants