Function arrow_arith::arity::binary
source · pub fn binary<A, B, F, O>(
a: &PrimitiveArray<A>,
b: &PrimitiveArray<B>,
op: F,
) -> Result<PrimitiveArray<O>, ArrowError>where
A: ArrowPrimitiveType,
B: ArrowPrimitiveType,
O: ArrowPrimitiveType,
F: Fn(A::Native, B::Native) -> O::Native,
Expand description
Allies a binary infallable function to two PrimitiveArray
s,
producing a new PrimitiveArray
§Details
Given two arrays of length len
, calls op(a[i], b[i])
for i
in 0..len
, collecting
the results in a PrimitiveArray
.
If any index is null in either a
or b
, the
corresponding index in the result will also be null
Like unary
, the op
is evaluated for every element in the two arrays,
including those elements which are NULL. This is beneficial as the cost of
the operation is low compared to the cost of branching, and especially when
the operation can be vectorised, however, requires op
to be infallible for
all possible values of its inputs
§Errors
- if the arrays have different lengths.
§Example
let a = Float32Array::from(vec![Some(5.1f32), None, Some(6.8), Some(7.2)]);
let b = Int32Array::from(vec![1, 2, 4, 9]);
// compute int(a) + b for each element
let c = binary(&a, &b, |a, b| a as i32 + b).unwrap();
assert_eq!(c, Int32Array::from(vec![Some(6), None, Some(10), Some(16)]));