ClifHouck commented on code in PR #40067:
URL: https://github.com/apache/arrow/pull/40067#discussion_r1492697128
##########
cpp/src/arrow/compute/kernels/scalar_cast_internal.cc:
##########
@@ -47,6 +49,36 @@ struct CastPrimitive {
}
};
+template<> struct CastPrimitive<HalfFloatType, FloatType, enable_if_t<true>> {
+ static void Exec(const ArraySpan& arr, ArraySpan* out) {
+ const float* in_values = arr.GetValues<float>(1);
+ uint16_t* out_values = out->GetValues<uint16_t>(1);
+ for (int64_t i = 0; i < arr.length; ++i) {
+ float val = *in_values;
+ uint16_t converted = Float16(val).bits();
+ std::memcpy(out_values, static_cast<void*>(&converted),
sizeof(uint16_t));
+ out_values++;
+ in_values++;
+ }
+ }
+};
+
+template<> struct CastPrimitive<FloatType, HalfFloatType, enable_if_t<true>> {
Review Comment:
I believe you and I attempted this:
```cpp
template<typename OutType>
struct CastPrimitive<OutType, HalfFloatType,
enable_if_floating_point<typename OutType::c_type>> {
static void Exec(const ArraySpan& arr, ArraySpan* out) {
using OutT = typename OutType::c_type;
const uint16_t* in_values = arr.GetValues<uint16_t>(1);
OutT* out_values = out->GetValues<OutT>(1);
for (int64_t i = 0; i < arr.length; ++i) {
*out_values++ =
static_cast<OutT>(Float16::FromBits(*in_values++));
}
}
};
```
But it doesn't seem to call
```cpp
explicit Float16::operator double();
```
or float. And I don't see how I can use
```cpp
Float16::ToDouble();
Float16::ToFloat();
```
In a templated version. Maybe you can give me a hint? My C++ template-fu is
not great.
--
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]