Applies a unary fallible function to all valid values in a primitive array, producing a new array of potentially different type. Applies `op` to only rows that are valid, which is often significantly slower than [`Self::unary`], which should be preferred if `op` is fallible. Note: LLVM is currently unable to effectively vectorize fallible operations
(&self, op: F)
| 967 | /// |
| 968 | /// Note: LLVM is currently unable to effectively vectorize fallible operations |
| 969 | pub fn try_unary<F, O, E>(&self, op: F) -> Result<PrimitiveArray<O>, E> |
| 970 | where |
| 971 | O: ArrowPrimitiveType, |
| 972 | F: Fn(T::Native) -> Result<O::Native, E>, |
| 973 | { |
| 974 | let len = self.len(); |
| 975 | |
| 976 | let nulls = self.nulls().cloned(); |
| 977 | let mut buffer = BufferBuilder::<O::Native>::new(len); |
| 978 | buffer.append_n_zeroed(len); |
| 979 | let slice = buffer.as_slice_mut(); |
| 980 | |
| 981 | let f = |idx| { |
| 982 | unsafe { *slice.get_unchecked_mut(idx) = op(self.value_unchecked(idx))? }; |
| 983 | Ok::<_, E>(()) |
| 984 | }; |
| 985 | |
| 986 | match &nulls { |
| 987 | Some(nulls) => nulls.try_for_each_valid_idx(f)?, |
| 988 | None => (0..len).try_for_each(f)?, |
| 989 | } |
| 990 | |
| 991 | let values = buffer.finish().into(); |
| 992 | Ok(PrimitiveArray::new(values, nulls)) |
| 993 | } |
| 994 | |
| 995 | /// Applies a unary fallible function to all valid values in a mutable |
| 996 | /// primitive array. |
no test coverage detected