Returns pointers to the end-points of an array. Parameters ---------- a : ndarray Input array. It must conform to the Python-side of the array interface. Returns ------- (low, high) : tuple of 2 integers The first integer is the first byte of th
(a)
| 10 | |
| 11 | @set_module("numpy.lib.array_utils") |
| 12 | def byte_bounds(a): |
| 13 | """ |
| 14 | Returns pointers to the end-points of an array. |
| 15 | |
| 16 | Parameters |
| 17 | ---------- |
| 18 | a : ndarray |
| 19 | Input array. It must conform to the Python-side of the array |
| 20 | interface. |
| 21 | |
| 22 | Returns |
| 23 | ------- |
| 24 | (low, high) : tuple of 2 integers |
| 25 | The first integer is the first byte of the array, the second |
| 26 | integer is just past the last byte of the array. If `a` is not |
| 27 | contiguous it will not use every byte between the (`low`, `high`) |
| 28 | values. |
| 29 | |
| 30 | Examples |
| 31 | -------- |
| 32 | >>> import numpy as np |
| 33 | >>> I = np.eye(2, dtype=np.float32); I.dtype |
| 34 | dtype('float32') |
| 35 | >>> low, high = np.lib.array_utils.byte_bounds(I) |
| 36 | >>> high - low == I.size*I.itemsize |
| 37 | True |
| 38 | >>> I = np.eye(2); I.dtype |
| 39 | dtype('float64') |
| 40 | >>> low, high = np.lib.array_utils.byte_bounds(I) |
| 41 | >>> high - low == I.size*I.itemsize |
| 42 | True |
| 43 | |
| 44 | """ |
| 45 | ai = a.__array_interface__ |
| 46 | a_data = ai['data'][0] |
| 47 | astrides = ai['strides'] |
| 48 | ashape = ai['shape'] |
| 49 | bytes_a = asarray(a).dtype.itemsize |
| 50 | |
| 51 | a_low = a_high = a_data |
| 52 | if astrides is None: |
| 53 | # contiguous case |
| 54 | a_high += a.size * bytes_a |
| 55 | else: |
| 56 | for shape, stride in zip(ashape, astrides): |
| 57 | if stride < 0: |
| 58 | a_low += (shape - 1) * stride |
| 59 | else: |
| 60 | a_high += (shape - 1) * stride |
| 61 | a_high += bytes_a |
| 62 | return a_low, a_high |
no test coverage detected
searching dependent graphs…