GH-46739: [C++] Fix Float16 signed zero/NaN equality comparisons#46973
GH-46739: [C++] Fix Float16 signed zero/NaN equality comparisons#46973pitrou merged 15 commits intoapache:mainfrom
Conversation
|
|
|
|
1 similar comment
|
|
9cb6072 to
f6b74b2
Compare
|
@benibus Is this ready for review again? |
|
@pitrou Yes, sorry. Feel free to take another look. |
pitrou
left a comment
There was a problem hiding this comment.
LGTM in general, some additional comments below
cpp/src/arrow/testing/random.cc
Outdated
There was a problem hiding this comment.
This doesn't fix GenerateTypedData when nan_probability_ is non-zero (it will use std::numeric_limits<uint16_t>::quiet_NaN() which is 0 and translates to Float16(0.0)).
cpp/src/arrow/testing/random.cc
Outdated
There was a problem hiding this comment.
DistributionType will be std::uniform_int_distribution<uint16_t> which will certainly not respect the min and max values once translated to Float16?
There was a problem hiding this comment.
Perhaps ValueType needs to be Float16 here to make sure we don't misuse uint16_t like this, and DistributionType could be ::arrow::random::uniform_real_distribution<float>.
cpp/src/arrow/testing/gtest_util.h
Outdated
There was a problem hiding this comment.
I wouldn't expect these checks in a helper function, especially as we supposedly have unit tests for this already (otherwise we should add them).
cpp/src/arrow/scalar.h
Outdated
There was a problem hiding this comment.
Perhaps use std::decay_t instead of std::remove_reference_t?
cpp/src/arrow/scalar_test.cc
Outdated
There was a problem hiding this comment.
We should probably keep the check here by using if constexpr as below?
cpp/src/arrow/scalar_test.cc
Outdated
There was a problem hiding this comment.
Since we are changing this, perhaps ASSERT_TRUE(set.emplace(...).second) would be better?
f6b74b2 to
866f533
Compare
Temporary for now
Since github.com/apache/pull/46981, HalfFloatBuilder now accepts Float16 values, making RealToCType's usage unnecessary in several places.
866f533 to
fb60726
Compare
cpp/src/arrow/testing/random.cc
Outdated
| ARROW_LOG(INFO) << "min = " << min_value.ToFloat(); | ||
| ARROW_LOG(INFO) << "max = " << max_value.ToFloat(); |
There was a problem hiding this comment.
You probably mean to remove these :)
There was a problem hiding this comment.
Ah, thanks! Just removed them.
|
@github-actions crossbow submit -g cpp |
|
Revision: 116b975 Submitted crossbow builds: ursacomputing/crossbow @ actions-868dcfc65b |
|
The Valgrind failure is unrelated, see #47496 |
|
Thanks a lot @benibus ! |
|
After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit caf4f70. There weren't enough matching historic benchmark results to make a call on whether there were regressions. The full Conbench report has more details. |
apache#46973) ### Rationale for this change Equality comparisons between half-floats (used in their scalar/array `Equals` methods) do not properly handle `EqualOptions::nans_equal` and `EqualOptions::signed_zeros_equal`. ### What changes are included in this PR? - Internal fixes to the current comparison behavior and additional tests as needed - Prevents Float16 NaNs from being randomly generated by test utilities by default (matching behavior for float/double) ### Are these changes tested? Yes ### Are there any user-facing changes? No * GitHub Issue: apache#46739 Authored-by: Benjamin Harkins <benpharkins@gmail.com> Signed-off-by: Antoine Pitrou <antoine@python.org>
Rationale for this change
Equality comparisons between half-floats (used in their scalar/array
Equalsmethods) do not properly handleEqualOptions::nans_equalandEqualOptions::signed_zeros_equal.What changes are included in this PR?
Are these changes tested?
Yes
Are there any user-facing changes?
No