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

Method getitem_by_idx

crates/vm/src/builtins/memory.rs:142–155  ·  view source on GitHub ↗
(&self, i: isize, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

140 }
141
142 fn getitem_by_idx(&self, i: isize, vm: &VirtualMachine) -> PyResult {
143 if self.desc.ndim() != 1 {
144 return Err(
145 vm.new_not_implemented_error("multi-dimensional sub-views are not implemented")
146 );
147 }
148 let (shape, stride, suboffset) = self.desc.dim_desc[0];
149 let index = i
150 .wrapped_at(shape)
151 .ok_or_else(|| vm.new_index_error("index out of range"))?;
152 let index = index as isize * stride + suboffset;
153 let pos = (index + self.start as isize) as usize;
154 self.unpack_single(pos, vm)
155 }
156
157 fn getitem_by_slice(&self, slice: &PySlice, vm: &VirtualMachine) -> PyResult {
158 let mut other = self.new_view();

Callers 4

__getitem__Method · 0.80
countMethod · 0.80
indexMethod · 0.80
nextMethod · 0.80

Calls 5

ok_or_elseMethod · 0.80
wrapped_atMethod · 0.80
unpack_singleMethod · 0.80
ErrClass · 0.50
ndimMethod · 0.45

Tested by

no test coverage detected