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

Function broadcast_arrays

ciphercore-base/src/broadcast.rs:46–65  ·  view source on GitHub ↗
(element_types: Vec<Type>)

Source from the content-addressed store, hash-verified

44}
45
46pub(super) fn broadcast_arrays(element_types: Vec<Type>) -> Result<Type> {
47 if element_types.is_empty() {
48 return Err(runtime_error!("Can't broadcast the empty sequence"));
49 }
50 for x in &element_types {
51 if !x.is_scalar() && !x.is_array() {
52 return Err(runtime_error!(
53 "Can broadcast only scalars and arrays, got {x:?}"
54 ));
55 }
56 if x.is_array() && !is_valid_shape(x.get_shape()) {
57 return Err(runtime_error!("Invalid shape: {:?}", x.get_shape()));
58 }
59 }
60 let mut result = element_types[0].clone();
61 for item in element_types.iter().skip(1) {
62 result = broadcast_pair(result, item.clone())?;
63 }
64 Ok(result)
65}
66
67pub fn index_to_number(index: &[u64], shape: &[u64]) -> u64 {
68 let mut num = 0;

Callers 2

test_malformedFunction · 0.85
process_nodeMethod · 0.85

Calls 7

is_valid_shapeFunction · 0.85
broadcast_pairFunction · 0.85
is_emptyMethod · 0.80
is_scalarMethod · 0.80
is_arrayMethod · 0.80
get_shapeMethod · 0.80
cloneMethod · 0.80

Tested by 1

test_malformedFunction · 0.68