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

Function randslice_from_slicelen

Lib/test/test_buffer.py:559–570  ·  view source on GitHub ↗

Create a random slice of len slicelen that fits into listlen.

(slicelen, listlen)

Source from the content-addressed store, hash-verified

557 return memlen, itemsize, ndim, shape, strides, offset
558
559def randslice_from_slicelen(slicelen, listlen):
560 """Create a random slice of len slicelen that fits into listlen."""
561 maxstart = listlen - slicelen
562 start = randrange(maxstart+1)
563 maxstep = (listlen - start) // slicelen if slicelen else 1
564 step = randrange(1, maxstep+1)
565 stop = start + slicelen * step
566 s = slice(start, stop, step)
567 _, _, _, control = slice_indices(s, listlen)
568 if control != slicelen:
569 raise RuntimeError
570 return s
571
572def randslice_from_shape(ndim, shape):
573 """Create two sets of slices for an array x with shape 'shape'

Callers 3

randslice_from_shapeFunction · 0.85
rand_aligned_slicesFunction · 0.85
rsliceFunction · 0.85

Calls 2

sliceClass · 0.85
slice_indicesFunction · 0.85

Tested by

no test coverage detected