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)
| 441 | # |
| 442 | |
| 443 | def verify_structure(memlen, itemsize, ndim, shape, strides, offset): |
| 444 | """Verify that the parameters represent a valid array within |
| 445 | the bounds of the allocated memory: |
| 446 | char *mem: start of the physical memory block |
| 447 | memlen: length of the physical memory block |
| 448 | offset: (char *)buf - mem |
| 449 | """ |
| 450 | if offset % itemsize: |
| 451 | return False |
| 452 | if offset < 0 or offset+itemsize > memlen: |
| 453 | return False |
| 454 | if any(v % itemsize for v in strides): |
| 455 | return False |
| 456 | |
| 457 | if ndim <= 0: |
| 458 | return ndim == 0 and not shape and not strides |
| 459 | if 0 in shape: |
| 460 | return True |
| 461 | |
| 462 | imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) |
| 463 | if strides[j] <= 0) |
| 464 | imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) |
| 465 | if strides[j] > 0) |
| 466 | |
| 467 | return 0 <= offset+imin and offset+imax+itemsize <= memlen |
| 468 | |
| 469 | def get_item(lst, indices): |
| 470 | for i in indices: |
no test coverage detected