Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem
(memlen, itemsize, ndim, shape, strides, offset)
| 453 | # |
| 454 | |
| 455 | def verify_structure(memlen, itemsize, ndim, shape, strides, offset): |
| 456 | """Verify that the parameters represent a valid array within |
| 457 | the bounds of the allocated memory: |
| 458 | char *mem: start of the physical memory block |
| 459 | memlen: length of the physical memory block |
| 460 | offset: (char *)buf - mem |
| 461 | """ |
| 462 | if offset % itemsize: |
| 463 | return False |
| 464 | if offset < 0 or offset+itemsize > memlen: |
| 465 | return False |
| 466 | if any(v % itemsize for v in strides): |
| 467 | return False |
| 468 | |
| 469 | if ndim <= 0: |
| 470 | return ndim == 0 and not shape and not strides |
| 471 | if 0 in shape: |
| 472 | return True |
| 473 | |
| 474 | imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) |
| 475 | if strides[j] <= 0) |
| 476 | imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) |
| 477 | if strides[j] > 0) |
| 478 | |
| 479 | return 0 <= offset+imin and offset+imax+itemsize <= memlen |
| 480 | |
| 481 | def get_item(lst, indices): |
| 482 | for i in indices: |
no test coverage detected
searching dependent graphs…