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

Function expand_to_same_dims

ciphercore-base/src/ops/comparisons.rs:271–278  ·  view source on GitHub ↗

As we support broadcasting in comparison arguments, we need to make sure they are still broadcastable after bits are pulled out to the outermost dimension. Say, we want to compare array of size `[2, 3, 64]` and array of size `[3, 64]`. This is a valid operation because `[3, 64]` could be broadcasted to `[2, 3, 64]`. After pulling out bits, we get shapes `[64, 2, 3]` and `[64, 3]`, which are not

(a: Node, b: Node)

Source from the content-addressed store, hash-verified

269/// To fix this, we convert `[3, 64]` into `[1, 3, 64]` first. After pulling out
270/// bits, shape is `[64, 1, 3]`, which could be broadcasted to `[64, 2, 3]`.
271fn expand_to_same_dims(a: Node, b: Node) -> Result<(Node, Node)> {
272 let len_a = a.get_type()?.get_shape().len();
273 let len_b = b.get_type()?.get_shape().len();
274 let result_len = max(len_a, len_b);
275 let a = expand_dims(a, &(0..result_len - len_a).collect::<Vec<_>>())?;
276 let b = expand_dims(b, &(0..result_len - len_b).collect::<Vec<_>>())?;
277 Ok((a, b))
278}
279
280/// - This function flips all values of the input Array's last component,
281/// which correspond to MSB bit (after `pull_out_bits`), to enable the

Callers 1

preprocess_inputsFunction · 0.85

Calls 3

expand_dimsFunction · 0.85
get_shapeMethod · 0.80
get_typeMethod · 0.45

Tested by

no test coverage detected