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

Method init_slice

crates/vm/src/builtins/memory.rs:266–292  ·  view source on GitHub ↗
(&mut self, slice: &PySlice, dim: usize, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

264 }
265
266 fn init_slice(&mut self, slice: &PySlice, dim: usize, vm: &VirtualMachine) -> PyResult<()> {
267 let (shape, stride, _) = self.desc.dim_desc[dim];
268 let slice = slice.to_saturated(vm)?;
269 let (range, step, slice_len) = slice.adjust_indices(shape);
270
271 let mut is_adjusted_suboffset = false;
272 for (_, _, suboffset) in self.desc.dim_desc.iter_mut().rev() {
273 if *suboffset != 0 {
274 *suboffset += stride * range.start as isize;
275 is_adjusted_suboffset = true;
276 break;
277 }
278 }
279 if !is_adjusted_suboffset {
280 // no suboffset set, stride must be positive
281 self.start += stride as usize
282 * if step.is_negative() {
283 range.end - 1
284 } else {
285 range.start
286 };
287 }
288 self.desc.dim_desc[dim].0 = slice_len;
289 self.desc.dim_desc[dim].1 *= step;
290
291 Ok(())
292 }
293
294 fn _to_list(
295 &self,

Callers 2

getitem_by_sliceMethod · 0.80
setitem_by_sliceMethod · 0.80

Calls 4

to_saturatedMethod · 0.80
adjust_indicesMethod · 0.80
revMethod · 0.45
iter_mutMethod · 0.45

Tested by

no test coverage detected