Function smartnoise_runtime::utilities::broadcast_map [−][src]
pub fn broadcast_map<T, U>(
left: ArrayD<T>,
right: ArrayD<T>,
operator: &dyn Fn(&T, &T) -> U
) -> Result<ArrayD<U>> where
T: Clone,
U: Default,
Broadcast left and right to match each other, and map an operator over the pairs.
Arguments
left
- Left vector to map over.right
- Right vector to map over.operator
- Function to apply to each pair.
Return
An array of mapped data.
Example
use smartnoise_validator::errors::*; use ndarray::prelude::*; use smartnoise_runtime::utilities::broadcast_map; let left: ArrayD<f64> = arr1(&[1., -2., 3., 5.]).into_dyn(); let right: ArrayD<f64> = arr1(&[2.]).into_dyn(); let mapped: Result<ArrayD<f64>> = broadcast_map(left, right, &|l, r| l.max(r.clone())); println!("{:?}", mapped); // [2., 2., 3., 5.]