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

Function m_assign

Lib/test/test_buffer.py:378–398  ·  view source on GitHub ↗

Multi-dimensional slice assignment: llst and rlst are the operands, lslices and rslices are lists of slice objects. llst and rlst must have the same structure. For a two-dimensional example, this is not implemented in Python: llst[0:3:2, 0:3:2] = rlst[1:3:1, 1:3:1]

(llst, rlst, lslices, rslices)

Source from the content-addressed store, hash-verified

376 return [multislice(sublst, slices[1:]) for sublst in lst[slices[0]]]
377
378def m_assign(llst, rlst, lslices, rslices):
379 """Multi-dimensional slice assignment: llst and rlst are the operands,
380 lslices and rslices are lists of slice objects. llst and rlst must
381 have the same structure.
382
383 For a two-dimensional example, this is not implemented in Python:
384
385 llst[0:3:2, 0:3:2] = rlst[1:3:1, 1:3:1]
386
387 Instead we write:
388
389 lslices = [slice(0,3,2), slice(0,3,2)]
390 rslices = [slice(1,3,1), slice(1,3,1)]
391 multislice_assign(llst, rlst, lslices, rslices)
392 """
393 if atomp(rlst):
394 return rlst
395 rlst = [m_assign(l, r, lslices[1:], rslices[1:])
396 for l, r in zip(llst[lslices[0]], rlst[rslices[0]])]
397 llst[lslices[0]] = rlst
398 return llst
399
400def cmp_structure(llst, rlst, lslices, rslices):
401 """Compare the structure of llst[lslices] and rlst[rslices]."""

Callers 1

multislice_assignFunction · 0.85

Calls 1

atompFunction · 0.85

Tested by

no test coverage detected