pitrou commented on code in PR #46973:
URL: https://github.com/apache/arrow/pull/46973#discussion_r2192370127
##########
cpp/src/arrow/scalar_test.cc:
##########
@@ -297,6 +299,26 @@ TYPED_TEST(TestNumericScalar, MakeScalar) {
AssertParseScalar(type, "3", ScalarType(3));
}
+template <typename ARROW_TYPE>
+auto GetFloat(double d) {
Review Comment:
Same suggestions as in the other test module.
Also, perhaps this can be factored into one of the testing headers?
##########
cpp/src/arrow/array/array_test.cc:
##########
@@ -2117,16 +2119,36 @@ void CheckSliceApproxEquals() {
ASSERT_TRUE(slice1->ApproxEquals(slice2));
}
+template <typename ARROW_TYPE>
+auto GetFloat(double d) {
+ if constexpr (std::is_same_v<ARROW_TYPE, HalfFloatType>) {
+ const auto h = Float16::FromDouble(d);
+ // Double check that nan/inf/sign are preserved
+ if (std::isnan(d)) {
+ EXPECT_TRUE(h.is_nan());
+ }
+ if (std::isinf(d)) {
+ EXPECT_TRUE(h.is_infinity());
+ }
+ if (std::signbit(d)) {
+ EXPECT_TRUE(h.signbit());
+ }
Review Comment:
```suggestion
EXPECT_EQ(h.is_nan(), std::isnan(d));
EXPECT_EQ(h.is_infinity(), std::isinf(d));
EXPECT_EQ(h.signbit(), std::signbit(d));
```
##########
cpp/src/arrow/scalar_test.cc:
##########
@@ -1181,8 +1205,6 @@ TEST(TestDayTimeIntervalScalars, Basics) {
ASSERT_TRUE(first->Equals(ts_val2));
}
-// TODO test HalfFloatScalar
Review Comment:
Doesn't the TODO also apply to `TestNumericScalar`?
##########
cpp/src/arrow/testing/random.cc:
##########
@@ -239,6 +250,20 @@ std::shared_ptr<Array>
RandomArrayGenerator::Date64(int64_t size, int64_t min,
memory_pool);
}
+std::shared_ptr<Array> RandomArrayGenerator::Float16(int64_t size, int16_t min,
+ int16_t max, double
null_probability,
+ int64_t alignment,
+ MemoryPool* memory_pool) {
+ using OptionType =
+ GenerateOptions<uint16_t, std::uniform_int_distribution<uint16_t>,
HalfFloatType>;
+ // FIXME: Not sure why the input min/max are signed when Float16's ctype is
uint16_t
Review Comment:
We can fix this here if there's no regression with it.
##########
cpp/src/arrow/scalar_test.cc:
##########
@@ -306,21 +328,21 @@ class TestRealScalar : public ::testing::Test {
void SetUp() {
type_ = TypeTraits<T>::type_singleton();
- scalar_val_ = std::make_shared<ScalarType>(static_cast<CType>(1));
+ scalar_val_ = std::make_shared<ScalarType>(GetFloat<T>(1));
Review Comment:
Can we allow constructing a `HalfFloatScalar` from a `util::Float16`
instance?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]