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)
| 268 | #-------------------------------------------- |
| 269 | |
| 270 | def byte_bounds(a): |
| 271 | """ |
| 272 | Returns pointers to the end-points of an array. |
| 273 | |
| 274 | Parameters |
| 275 | ---------- |
| 276 | a : ndarray |
| 277 | Input array. It must conform to the Python-side of the array |
| 278 | interface. |
| 279 | |
| 280 | Returns |
| 281 | ------- |
| 282 | (low, high) : tuple of 2 integers |
| 283 | The first integer is the first byte of the array, the second |
| 284 | integer is just past the last byte of the array. If `a` is not |
| 285 | contiguous it will not use every byte between the (`low`, `high`) |
| 286 | values. |
| 287 | |
| 288 | Examples |
| 289 | -------- |
| 290 | >>> I = np.eye(2, dtype='f'); I.dtype |
| 291 | dtype('float32') |
| 292 | >>> low, high = np.byte_bounds(I) |
| 293 | >>> high - low == I.size*I.itemsize |
| 294 | True |
| 295 | >>> I = np.eye(2); I.dtype |
| 296 | dtype('float64') |
| 297 | >>> low, high = np.byte_bounds(I) |
| 298 | >>> high - low == I.size*I.itemsize |
| 299 | True |
| 300 | |
| 301 | """ |
| 302 | ai = a.__array_interface__ |
| 303 | a_data = ai['data'][0] |
| 304 | astrides = ai['strides'] |
| 305 | ashape = ai['shape'] |
| 306 | bytes_a = asarray(a).dtype.itemsize |
| 307 | |
| 308 | a_low = a_high = a_data |
| 309 | if astrides is None: |
| 310 | # contiguous case |
| 311 | a_high += a.size * bytes_a |
| 312 | else: |
| 313 | for shape, stride in zip(ashape, astrides): |
| 314 | if stride < 0: |
| 315 | a_low += (shape-1)*stride |
| 316 | else: |
| 317 | a_high += (shape-1)*stride |
| 318 | a_high += bytes_a |
| 319 | return a_low, a_high |
| 320 | |
| 321 | |
| 322 | #----------------------------------------------------------------------------- |