MCPcopy Index your code
hub / github.com/RustPython/RustPython / pos_from_multi_index

Method pos_from_multi_index

crates/vm/src/builtins/memory.rs:221–239  ·  view source on GitHub ↗
(&self, indexes: &[isize], vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

219 }
220
221 fn pos_from_multi_index(&self, indexes: &[isize], vm: &VirtualMachine) -> PyResult<usize> {
222 match indexes.len().cmp(&self.desc.ndim()) {
223 Ordering::Less => {
224 return Err(vm.new_not_implemented_error("sub-views are not implemented"));
225 }
226 Ordering::Greater => {
227 return Err(vm.new_type_error(format!(
228 "cannot index {}-dimension view with {}-element tuple",
229 self.desc.ndim(),
230 indexes.len()
231 )));
232 }
233 Ordering::Equal => (),
234 }
235
236 let pos = self.desc.position(indexes, vm)?;
237 let pos = (pos + self.start as isize) as usize;
238 Ok(pos)
239 }
240
241 fn init_len(&mut self) {
242 let product: usize = self.desc.dim_desc.iter().map(|x| x.0).product();

Callers 2

getitem_by_multi_idxMethod · 0.80
setitem_by_multi_idxMethod · 0.80

Calls 5

ErrClass · 0.50
cmpMethod · 0.45
lenMethod · 0.45
ndimMethod · 0.45
positionMethod · 0.45

Tested by

no test coverage detected