MCPcopy Index your code
hub / github.com/numpy/numpy / _get_stats

Function _get_stats

numpy/lib/_arraypad_impl.py:231–294  ·  view source on GitHub ↗

Calculate statistic for the empty-padded array in given dimension. Parameters ---------- padded : ndarray Empty-padded array. axis : int Dimension in which the statistic is calculated. width_pair : (int, int) Pair of widths that mark the pad area on

(padded, axis, width_pair, length_pair, stat_func)

Source from the content-addressed store, hash-verified

229
230
231def _get_stats(padded, axis, width_pair, length_pair, stat_func):
232 """
233 Calculate statistic for the empty-padded array in given dimension.
234
235 Parameters
236 ----------
237 padded : ndarray
238 Empty-padded array.
239 axis : int
240 Dimension in which the statistic is calculated.
241 width_pair : (int, int)
242 Pair of widths that mark the pad area on both sides in the given
243 dimension.
244 length_pair : 2-element sequence of None or int
245 Gives the number of values in valid area from each side that is
246 taken into account when calculating the statistic. If None the entire
247 valid area in `padded` is considered.
248 stat_func : function
249 Function to compute statistic. The expected signature is
250 ``stat_func(x: ndarray, axis: int, keepdims: bool) -> ndarray``.
251
252 Returns
253 -------
254 left_stat, right_stat : ndarray
255 Calculated statistic for both sides of `padded`.
256 """
257 # Calculate indices of the edges of the area with original values
258 left_index = width_pair[0]
259 right_index = padded.shape[axis] - width_pair[1]
260 # as well as its length
261 max_length = right_index - left_index
262
263 # Limit stat_lengths to max_length
264 left_length, right_length = length_pair
265 if left_length is None or max_length < left_length:
266 left_length = max_length
267 if right_length is None or max_length < right_length:
268 right_length = max_length
269
270 if (left_length == 0 or right_length == 0) \
271 and stat_func in {np.amax, np.amin}:
272 # amax and amin can't operate on an empty array,
273 # raise a more descriptive warning here instead of the default one
274 raise ValueError("stat_length of 0 yields no value for padding")
275
276 # Calculate statistic for the left side
277 left_slice = _slice_at_axis(
278 slice(left_index, left_index + left_length), axis)
279 left_chunk = padded[left_slice]
280 left_stat = stat_func(left_chunk, axis=axis, keepdims=True)
281 _round_if_needed(left_stat, padded.dtype)
282
283 if left_length == right_length == max_length:
284 # return early as right_stat must be identical to left_stat
285 return left_stat, left_stat
286
287 # Calculate statistic for the right side
288 right_slice = _slice_at_axis(

Callers 1

padFunction · 0.85

Calls 3

_slice_at_axisFunction · 0.85
sliceFunction · 0.85
_round_if_neededFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…