MCPcopy Create free account
hub / github.com/numpy/numpy / get_data

Function get_data

benchmarks/benchmarks/common.py:124–221  ·  view source on GitHub ↗

Generates a cached random array that covers several scenarios that may affect the benchmark for fairness and to stabilize the benchmark. Parameters ---------- size: int Array length. dtype: dtype or dtype specifier ip_num: int Input number, to avoid me

(size, dtype, ip_num=0, zeros=False, finite=True, denormal=False)

Source from the content-addressed store, hash-verified

122
123@lru_cache(typed=True)
124def get_data(size, dtype, ip_num=0, zeros=False, finite=True, denormal=False):
125 """
126 Generates a cached random array that covers several scenarios that
127 may affect the benchmark for fairness and to stabilize the benchmark.
128
129 Parameters
130 ----------
131 size: int
132 Array length.
133
134 dtype: dtype or dtype specifier
135
136 ip_num: int
137 Input number, to avoid memory overload
138 and to provide unique data for each operand.
139
140 zeros: bool
141 Spreading zeros along with generated data.
142
143 finite: bool
144 Avoid spreading fp special cases nan/inf.
145
146 denormal:
147 Spreading subnormal numbers along with generated data.
148 """
149 dtype = np.dtype(dtype)
150 dname = dtype.name
151 cache_name = f'{dname}_{size}_{ip_num}_{int(zeros)}'
152 if dtype.kind in 'fc':
153 cache_name += f'{int(finite)}{int(denormal)}'
154 cache_name += '.bin'
155 cache_path = CACHE_ROOT / cache_name
156 if cache_path.exists():
157 return np.fromfile(cache_path, dtype)
158
159 array = np.ones(size, dtype)
160 rands = []
161 if dtype.kind == 'i':
162 dinfo = np.iinfo(dtype)
163 scale = 8
164 if zeros:
165 scale += 1
166 lsize = size // scale
167 for low, high in (
168 (-0x80, -1),
169 (1, 0x7f),
170 (-0x8000, -1),
171 (1, 0x7fff),
172 (-0x80000000, -1),
173 (1, 0x7fffffff),
174 (-0x8000000000000000, -1),
175 (1, 0x7fffffffffffffff),
176 ):
177 rands += [np.random.randint(
178 max(low, dinfo.min),
179 min(high, dinfo.max),
180 lsize, dtype
181 )]

Callers 2

setupMethod · 0.85
setupMethod · 0.85

Calls 6

astypeMethod · 0.80
tofileMethod · 0.80
maxFunction · 0.50
minFunction · 0.50
dtypeMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected