Pad `axis` of `arr` with reflection. 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 dim
(padded, axis, width_pair, method,
original_period, include_edge=False)
| 295 | |
| 296 | |
| 297 | def _set_reflect_both(padded, axis, width_pair, method, |
| 298 | original_period, include_edge=False): |
| 299 | """ |
| 300 | Pad `axis` of `arr` with reflection. |
| 301 | |
| 302 | Parameters |
| 303 | ---------- |
| 304 | padded : ndarray |
| 305 | Input array of arbitrary shape. |
| 306 | axis : int |
| 307 | Axis along which to pad `arr`. |
| 308 | width_pair : (int, int) |
| 309 | Pair of widths that mark the pad area on both sides in the given |
| 310 | dimension. |
| 311 | method : str |
| 312 | Controls method of reflection; options are 'even' or 'odd'. |
| 313 | original_period : int |
| 314 | Original length of data on `axis` of `arr`. |
| 315 | include_edge : bool |
| 316 | If true, edge value is included in reflection, otherwise the edge |
| 317 | value forms the symmetric axis to the reflection. |
| 318 | |
| 319 | Returns |
| 320 | ------- |
| 321 | pad_amt : tuple of ints, length 2 |
| 322 | New index positions of padding to do along the `axis`. If these are |
| 323 | both 0, padding is done in this dimension. |
| 324 | """ |
| 325 | left_pad, right_pad = width_pair |
| 326 | old_length = padded.shape[axis] - right_pad - left_pad |
| 327 | |
| 328 | if include_edge: |
| 329 | # Avoid wrapping with only a subset of the original area |
| 330 | # by ensuring period can only be a multiple of the original |
| 331 | # area's length. |
| 332 | old_length = old_length // original_period * original_period |
| 333 | # Edge is included, we need to offset the pad amount by 1 |
| 334 | edge_offset = 1 |
| 335 | else: |
| 336 | # Avoid wrapping with only a subset of the original area |
| 337 | # by ensuring period can only be a multiple of the original |
| 338 | # area's length. |
| 339 | old_length = ((old_length - 1) // (original_period - 1) |
| 340 | * (original_period - 1) + 1) |
| 341 | edge_offset = 0 # Edge is not included, no need to offset pad amount |
| 342 | old_length -= 1 # but must be omitted from the chunk |
| 343 | |
| 344 | if left_pad > 0: |
| 345 | # Pad with reflected values on left side: |
| 346 | # First limit chunk size which can't be larger than pad area |
| 347 | chunk_length = min(old_length, left_pad) |
| 348 | # Slice right to left, stop on or next to edge, start relative to stop |
| 349 | stop = left_pad - edge_offset |
| 350 | start = stop + chunk_length |
| 351 | left_slice = _slice_at_axis(slice(start, stop, -1), axis) |
| 352 | left_chunk = padded[left_slice] |
| 353 | |
| 354 | if method == "odd": |
no test coverage detected
searching dependent graphs…