Reduces an array over the first dimension, using log number of `combine` calls. `combine` receives two arrays (first, second) of same shape, and needs to return one array of same shape. `combine` is assumed to be associative and commutative.
(node: Node, combine: impl Fn(Node, Node) -> Result<Node>)
| 347 | /// `combine` receives two arrays (first, second) of same shape, and needs to return one array of |
| 348 | /// same shape. `combine` is assumed to be associative and commutative. |
| 349 | pub fn custom_reduce(node: Node, combine: impl Fn(Node, Node) -> Result<Node>) -> Result<Node> { |
| 350 | custom_reduce_vec(vec![node], |first, second| { |
| 351 | Ok(vec![combine(first[0].clone(), second[0].clone())?]) |
| 352 | })? |
| 353 | .into_iter() |
| 354 | .next() |
| 355 | .ok_or_else(|| runtime_error!("Internal error: custom_reduce_vec returned empty vec")) |
| 356 | } |
| 357 | |
| 358 | /// Reduces a vector of arrays sharing the same first dimension, over the first dimension, using |
| 359 | /// log number of `combine` calls. |
no test coverage detected