comphead commented on code in PR #13637:
URL: https://github.com/apache/datafusion/pull/13637#discussion_r1870122310
##########
datafusion-examples/examples/advanced_udf.rs:
##########
@@ -191,6 +199,48 @@ impl ScalarUDFImpl for PowUdf {
}
}
+/// Evaluate `base ^ exp` *without* allocating a new array, if possible
+fn pow_in_place(base: f64, exp_array: ArrayRef) -> Result<ArrayRef> {
+ // Calling `unary` creates a new array for the results. Avoiding
+ // allocations is a common optimization in performance critical code.
+ // arrow-rs allows this optimization via the `unary_mut`
+ // and `binary_mut` kernels in certain cases
+ //
+ // These kernels can only be used if there are no other references to
+ // the arrays (exp_array has to be the last remaining reference).
+ let owned_array = exp_array
+ // as before we downcast to Float64Array
+ .as_primitive::<Float64Type>()
+ // non-obviously, clone (which increments ref counts, it
+ // doesn't clone the data) to get an typed own array
+ // so we drop the original exp_array (untyped) reference
Review Comment:
does it clone the reference?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]