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

Function interleave

ciphercore-base/src/ops/adder.rs:218–231  ·  view source on GitHub ↗

Takes arrays `[a1, a2, ..., a_n]` and `[b1, b2, ..., b_n]` Returns `[a1, b1, a2, b2, ..., a_n, b_n]`

(first: Node, second: Node)

Source from the content-addressed store, hash-verified

216///
217/// Returns `[a1, b1, a2, b2, ..., a_n, b_n]`
218fn interleave(first: Node, second: Node) -> Result<Node> {
219 let first = expand_dims(first, &[0])?;
220 let second = expand_dims(second, &[0])?;
221 let graph = first.get_graph();
222 let joined = graph.concatenate(vec![first, second], 0)?;
223 let mut axes: Vec<_> = (0..joined.get_type()?.get_shape().len() as u64).collect();
224 axes.swap(0, 1);
225 let joined = joined.permute_axes(axes)?;
226 let mut shape = joined.get_type()?.get_shape();
227 shape[0] *= 2;
228 shape.remove(1);
229 let scalar = joined.get_type()?.get_scalar_type();
230 joined.reshape(array_type(shape, scalar))
231}
232
233/// This function generates a graph for the "segment tree" to calculate
234/// carry bits.

Callers 1

calculate_carry_bitsFunction · 0.85

Calls 10

expand_dimsFunction · 0.85
concatenateMethod · 0.80
get_shapeMethod · 0.80
array_typeFunction · 0.50
get_graphMethod · 0.45
get_typeMethod · 0.45
permute_axesMethod · 0.45
removeMethod · 0.45
get_scalar_typeMethod · 0.45
reshapeMethod · 0.45

Tested by

no test coverage detected