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

Function randslice_from_shape

Lib/test/test_buffer.py:584–594  ·  view source on GitHub ↗

Create two sets of slices for an array x with shape 'shape' such that shapeof(x[lslices]) == shapeof(x[rslices]).

(ndim, shape)

Source from the content-addressed store, hash-verified

582 return s
583
584def randslice_from_shape(ndim, shape):
585 """Create two sets of slices for an array x with shape 'shape'
586 such that shapeof(x[lslices]) == shapeof(x[rslices])."""
587 lslices = [0] * ndim
588 rslices = [0] * ndim
589 for n in range(ndim):
590 l = shape[n]
591 slicelen = randrange(1, l+1) if l > 0 else 0
592 lslices[n] = randslice_from_slicelen(slicelen, l)
593 rslices[n] = randslice_from_slicelen(slicelen, l)
594 return tuple(lslices), tuple(rslices)
595
596def rand_aligned_slices(maxdim=5, maxshape=16):
597 """Create (lshape, rshape, tuple(lslices), tuple(rslices)) such that

Callers 1

Calls 1

randslice_from_slicelenFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…