Skip to content

GH-43017: [C++] Make the set of casts and hash kernels involving float16 consistent with other floating types - #43018

Closed
felipecrv wants to merge 13 commits into
apache:mainfrom
felipecrv:half_float_casts
Closed

felipecrv wants to merge 13 commits into
apache:mainfrom
felipecrv:half_float_casts

Conversation

@felipecrv

@felipecrv felipecrv commented Jun 24, 2024 •

Copy link
Copy Markdown
Contributor

Rationale for this change

To simplify loops and unit tests involving numeric types. Special-casing float16 adds complexity.

What changes are included in this PR?

  • Complete the set of casts involving half-float casts (with the exception of half-float -> decimal128/256 casts)
  • Make half-floats supported in hash kernels (kernels defined in terms of the equality of physical representation of values)

Are these changes tested?

By existing tests that are now extended to run with float16 as input.

@felipecrv
felipecrv requested a review from westonpace as a code owner June 24, 2024 03:19
@github-actions

Copy link
Copy Markdown

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

@felipecrv

Copy link
Copy Markdown
Contributor Author

@ianmcook @ClifHouck

@felipecrv

Copy link
Copy Markdown
Contributor Author

@pitrou

}

// XXX: float16 is not part of NumericTypes() yet
auto& AllNumericTypes() {

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.

Can we make this const auto&, to avoid potentially mutating it from a callee?

return Generator<Type0, DoubleType, Args...>::Exec;
case Type::HALF_FLOAT:
// NOTE: Type::HALF_FLOAT used to not be part of the list of numeric types,
// so users of this template might start failing to compiler after Arrow 17.x.

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.

These are internal helpers, so if Arrow still compiles, I don't think the comment is warranted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Cool. It took me a while to realize these were internal. I will remove the comments.

}
{
// XXX: float16() is not in NumericTypes() yet
auto physical_type = GetPhysicalType(float16());

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.

What is the underlying physical type btw? We should be careful that float16 NaNs sort as described as https://arrow.apache.org/docs/cpp/compute.html#sorts-and-partitions, and we should test for that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's float16 itself. I'm changing the code to make that more obvious.

DCHECK_OK(func->AddKernel(base));
}
{
// XXX: float16() is not in PrimitiveTypes()

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.

That's a bummer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We should eventually deal with this somehow. I think we could add a less stable AllPrimitiveTypes() that includes FLOAT16 and eventually mark PrimitiveTypes() as deprecated.

@pitrou

pitrou commented Jun 27, 2024

Copy link
Copy Markdown
Member

@felipecrv Do we have tests for sorting float16 values and NaNs already? Otherwise, we should add some.

Also, is only array_sort handled, or does the more general sort also accept float16?

@pitrou

pitrou commented Jul 22, 2024

Copy link
Copy Markdown
Member

@felipecrv Is this ready for review again?

@felipecrv

Copy link
Copy Markdown
Contributor Author

@felipecrv Is this ready for review again?

No. Adding these tests you requested creates a cascade of requirements regarding half-float support that I haven't been able to fix even after putting a lot of effort into it.

@github-actions

Copy link
Copy Markdown

Thank you for your contribution. Unfortunately, this pull request has been marked as stale because it has had no activity in the past 365 days. Please remove the stale label or comment below, or this PR will be closed in 14 days. Feel free to re-open this if it has been closed in error. If you do not have repository permissions to reopen the PR, please tag a maintainer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: C++ Status: stale-warning Issues and PRs flagged as stale which are due to be closed if no indication otherwise

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants