ClifHouck commented on code in PR #40067:
URL: https://github.com/apache/arrow/pull/40067#discussion_r1496355677


##########
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 tried this, but it doesn't seem to end up calling the explicit operators. 
I've confirmed this experimentally. Until I can figure something out I'll leave 
this in a more specialized state.



-- 
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]

Reply via email to