MCPcopy Index your code
hub / github.com/python/cpython / randslice_from_slicelen

Function randslice_from_slicelen

Lib/test/test_buffer.py:571–582  ·  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

569 return memlen, itemsize, ndim, shape, strides, offset
570
571def randslice_from_slicelen(slicelen, listlen):
572 """Create a random slice of len slicelen that fits into listlen."""
573 maxstart = listlen - slicelen
574 start = randrange(maxstart+1)
575 maxstep = (listlen - start) // slicelen if slicelen else 1
576 step = randrange(1, maxstep+1)
577 stop = start + slicelen * step
578 s = slice(start, stop, step)
579 _, _, _, control = slice_indices(s, listlen)
580 if control != slicelen:
581 raise RuntimeError
582 return s
583
584def randslice_from_shape(ndim, shape):
585 """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

Used in the wild real call sites across dependent graphs

searching dependent graphs…