Pad `axis` of `arr` with wrapped values. Parameters ---------- padded : ndarray Input array of arbitrary shape. axis : int Axis along which to pad `arr`. width_pair : (int, int) Pair of widths that mark the pad area on both sides in the given
(padded, axis, width_pair, original_period)
| 392 | |
| 393 | |
| 394 | def _set_wrap_both(padded, axis, width_pair, original_period): |
| 395 | """ |
| 396 | Pad `axis` of `arr` with wrapped values. |
| 397 | |
| 398 | Parameters |
| 399 | ---------- |
| 400 | padded : ndarray |
| 401 | Input array of arbitrary shape. |
| 402 | axis : int |
| 403 | Axis along which to pad `arr`. |
| 404 | width_pair : (int, int) |
| 405 | Pair of widths that mark the pad area on both sides in the given |
| 406 | dimension. |
| 407 | original_period : int |
| 408 | Original length of data on `axis` of `arr`. |
| 409 | |
| 410 | Returns |
| 411 | ------- |
| 412 | pad_amt : tuple of ints, length 2 |
| 413 | New index positions of padding to do along the `axis`. If these are |
| 414 | both 0, padding is done in this dimension. |
| 415 | """ |
| 416 | left_pad, right_pad = width_pair |
| 417 | period = padded.shape[axis] - right_pad - left_pad |
| 418 | # Avoid wrapping with only a subset of the original area by ensuring period |
| 419 | # can only be a multiple of the original area's length. |
| 420 | period = period // original_period * original_period |
| 421 | |
| 422 | # If the current dimension of `arr` doesn't contain enough valid values |
| 423 | # (not part of the undefined pad area) we need to pad multiple times. |
| 424 | # Each time the pad area shrinks on both sides which is communicated with |
| 425 | # these variables. |
| 426 | new_left_pad = 0 |
| 427 | new_right_pad = 0 |
| 428 | |
| 429 | if left_pad > 0: |
| 430 | # Pad with wrapped values on left side |
| 431 | # First slice chunk from left side of the non-pad area. |
| 432 | # Use min(period, left_pad) to ensure that chunk is not larger than |
| 433 | # pad area. |
| 434 | slice_end = left_pad + period |
| 435 | slice_start = slice_end - min(period, left_pad) |
| 436 | right_slice = _slice_at_axis(slice(slice_start, slice_end), axis) |
| 437 | right_chunk = padded[right_slice] |
| 438 | |
| 439 | if left_pad > period: |
| 440 | # Chunk is smaller than pad area |
| 441 | pad_area = _slice_at_axis(slice(left_pad - period, left_pad), axis) |
| 442 | new_left_pad = left_pad - period |
| 443 | else: |
| 444 | # Chunk matches pad area |
| 445 | pad_area = _slice_at_axis(slice(None, left_pad), axis) |
| 446 | padded[pad_area] = right_chunk |
| 447 | |
| 448 | if right_pad > 0: |
| 449 | # Pad with wrapped values on right side |
| 450 | # First slice chunk from right side of the non-pad area. |
| 451 | # Use min(period, right_pad) to ensure that chunk is not larger than |
no test coverage detected
searching dependent graphs…