Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.9/dist-packages/numpy/lib/_array_utils_impl.py: 30%
20 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-09 06:12 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-09 06:12 +0000
1"""
2Miscellaneous utils.
3"""
4from numpy._core import asarray
5from numpy._core.numeric import normalize_axis_tuple, normalize_axis_index
6from numpy._utils import set_module
8__all__ = ["byte_bounds", "normalize_axis_tuple", "normalize_axis_index"]
11@set_module("numpy.lib.array_utils")
12def byte_bounds(a):
13 """
14 Returns pointers to the end-points of an array.
16 Parameters
17 ----------
18 a : ndarray
19 Input array. It must conform to the Python-side of the array
20 interface.
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.
30 Examples
31 --------
32 >>> I = np.eye(2, dtype='f'); I.dtype
33 dtype('float32')
34 >>> low, high = np.lib.array_utils.byte_bounds(I)
35 >>> high - low == I.size*I.itemsize
36 True
37 >>> I = np.eye(2); I.dtype
38 dtype('float64')
39 >>> low, high = np.lib.array_utils.byte_bounds(I)
40 >>> high - low == I.size*I.itemsize
41 True
43 """
44 ai = a.__array_interface__
45 a_data = ai['data'][0]
46 astrides = ai['strides']
47 ashape = ai['shape']
48 bytes_a = asarray(a).dtype.itemsize
50 a_low = a_high = a_data
51 if astrides is None:
52 # contiguous case
53 a_high += a.size * bytes_a
54 else:
55 for shape, stride in zip(ashape, astrides):
56 if stride < 0:
57 a_low += (shape-1)*stride
58 else:
59 a_high += (shape-1)*stride
60 a_high += bytes_a
61 return a_low, a_high