MCPcopy Create free account
hub / github.com/apache/arrow-rs / try_unary_mut

Method try_unary_mut

arrow-array/src/array/primitive_array.rs:1012–1035  ·  view source on GitHub ↗

Applies a unary fallible function to all valid values in a mutable primitive array. # Null Handling See [`Self::try_unary`] for more information on null handling. # Buffer Reuse See [`Self::unary_mut`] for more information on buffer reuse. This returns an `Err` when the input array is shared buffer with other array. In the case, returned `Err` wraps input array. If the function encounters an

(
        self,
        op: F,
    )

Source from the content-addressed store, hash-verified

1010 ///
1011 /// Note: LLVM is currently unable to effectively vectorize fallible operations
1012 pub fn try_unary_mut<F, E>(
1013 self,
1014 op: F,
1015 ) -> Result<Result<PrimitiveArray<T>, E>, PrimitiveArray<T>>
1016 where
1017 F: Fn(T::Native) -> Result<T::Native, E>,
1018 {
1019 let len = self.len();
1020 let null_count = self.null_count();
1021 let mut builder = self.into_builder()?;
1022
1023 let (slice, null_buffer) = builder.slices_mut();
1024
1025 let r = try_for_each_valid_idx(len, 0, null_count, null_buffer.as_deref(), |idx| {
1026 unsafe { *slice.get_unchecked_mut(idx) = op(*slice.get_unchecked(idx))? };
1027 Ok::<_, E>(())
1028 });
1029
1030 if let Err(err) = r {
1031 return Ok(Err(err));
1032 }
1033
1034 Ok(Ok(builder.finish()))
1035 }
1036
1037 /// Applies a unary and nullable function to all valid values in a primitive array
1038 ///

Callers 1

try_unary_mutFunction · 0.80

Calls 6

try_for_each_valid_idxFunction · 0.85
slices_mutMethod · 0.80
lenMethod · 0.45
null_countMethod · 0.45
into_builderMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected