MCPcopy Create free account
hub / github.com/ciphermodelabs/ciphercore / custom_reduce

Function custom_reduce

ciphercore-base/src/ops/utils.rs:349–356  ·  view source on GitHub ↗

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>)

Source from the content-addressed store, hash-verified

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.
349pub 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.

Callers 4

reduce_mulFunction · 0.85
custom_reduce_helperFunction · 0.85
get_oprf_mask_graphFunction · 0.85
gen_multi_bit_sort_graphFunction · 0.85

Calls 1

custom_reduce_vecFunction · 0.85

Tested by

no test coverage detected