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

Function randslice_from_shape

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

570 return s
571
572def randslice_from_shape(ndim, shape):
573 """Create two sets of slices for an array x with shape 'shape'
574 such that shapeof(x[lslices]) == shapeof(x[rslices])."""
575 lslices = [0] * ndim
576 rslices = [0] * ndim
577 for n in range(ndim):
578 l = shape[n]
579 slicelen = randrange(1, l+1) if l > 0 else 0
580 lslices[n] = randslice_from_slicelen(slicelen, l)
581 rslices[n] = randslice_from_slicelen(slicelen, l)
582 return tuple(lslices), tuple(rslices)
583
584def rand_aligned_slices(maxdim=5, maxshape=16):
585 """Create (lshape, rshape, tuple(lslices), tuple(rslices)) such that

Callers 1

Calls 1

randslice_from_slicelenFunction · 0.85

Tested by

no test coverage detected