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

Function normalize_subarray

ciphercore-base/src/slices.rs:108–125  ·  view source on GitHub ↗
(dimension: u64, slice_element: SliceElement)

Source from the content-addressed store, hash-verified

106}
107
108fn normalize_subarray(dimension: u64, slice_element: SliceElement) -> Result<(i64, i64, i64)> {
109 if let SliceElement::SubArray(begin, end, step) = slice_element {
110 let step = step.unwrap_or(1);
111 if step == 0 {
112 return Err(runtime_error!("Slice step can't be zero"));
113 }
114 let mut begin = begin.unwrap_or(if step > 0 { 0 } else { dimension as i64 - 1 });
115 if begin < 0 {
116 begin += dimension as i64;
117 }
118 let end = end
119 .map(|x| if x >= 0 { x } else { x + dimension as i64 })
120 .unwrap_or(if step > 0 { dimension as i64 } else { -1 });
121 Ok((begin, end, step))
122 } else {
123 panic!("Should not be here!");
124 }
125}
126
127fn get_slice_shape_1d(dimension: u64, slice_element: SliceElement) -> Result<Option<u64>> {
128 match slice_element {

Callers 2

slice_1d_indexFunction · 0.85
get_slice_shape_1dFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected