etseidl commented on code in PR #6252:
URL: https://github.com/apache/arrow-rs/pull/6252#discussion_r1723958216
##########
arrow-array/src/array/primitive_array.rs:
##########
@@ -1016,6 +1016,32 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
PrimitiveArray::new(values, Some(nulls))
}
+ /// Applies a unary infallible function to each value in an array,
producing a
+ /// new primitive array.
+ ///
+ /// # Null Handling
+ ///
+ /// Applies the function for all values, including those on null slots.
This
+ /// will often allow the compiler to generate faster vectorized code, but
+ /// requires that the operation must be infallible (not error/panic) for
any
+ /// value of the corresponding type or this function may panic.
+ pub fn from_unary<U: ArrayAccessor, F>(left: U, mut op: F) -> Self
+ where
+ F: FnMut(U::Item) -> T::Native,
+ {
+ let nulls = left.logical_nulls();
+ let mut values: Vec<T::Native> = vec![T::Native::default();
left.len()];
+
+ for (i, val) in values.iter_mut().enumerate().take(left.len()) {
Review Comment:
Hmm...benchmarks are a tricky thing. Clippy didn't like the above, so I
rewrote it to use a ptr...and then the `INT32->Decimal128` benchmarks
regressed. I wound up taking @jhorstmann's suggestion, but used
`Buffer::from_trusted_len_iter` rather than `collect`. No more regression for
byte arrays 😄
--
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]