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


##########
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:
   Similarly I think this could be made generic on the output type.



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