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

Function m_assign

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

388 return [multislice(sublst, slices[1:]) for sublst in lst[slices[0]]]
389
390def m_assign(llst, rlst, lslices, rslices):
391 """Multi-dimensional slice assignment: llst and rlst are the operands,
392 lslices and rslices are lists of slice objects. llst and rlst must
393 have the same structure.
394
395 For a two-dimensional example, this is not implemented in Python:
396
397 llst[0:3:2, 0:3:2] = rlst[1:3:1, 1:3:1]
398
399 Instead we write:
400
401 lslices = [slice(0,3,2), slice(0,3,2)]
402 rslices = [slice(1,3,1), slice(1,3,1)]
403 multislice_assign(llst, rlst, lslices, rslices)
404 """
405 if atomp(rlst):
406 return rlst
407 rlst = [m_assign(l, r, lslices[1:], rslices[1:])
408 for l, r in zip(llst[lslices[0]], rlst[rslices[0]])]
409 llst[lslices[0]] = rlst
410 return llst
411
412def cmp_structure(llst, rlst, lslices, rslices):
413 """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

Used in the wild real call sites across dependent graphs

searching dependent graphs…