handle odd padding mode backward Args: dx, the backward tensor odd_padding, the odd_padding Returns: tensor, the output
(dx, odd_padding)
| 86 | |
| 87 | |
| 88 | def handle_odd_pad_bwd(dx, odd_padding): |
| 89 | """ |
| 90 | handle odd padding mode backward |
| 91 | Args: |
| 92 | dx, the backward tensor |
| 93 | odd_padding, the odd_padding |
| 94 | Returns: |
| 95 | tensor, the output |
| 96 | """ |
| 97 | # (axis, left padding if True else right padding) |
| 98 | flags = [(2, True), (2, False), (3, True), (3, False)] |
| 99 | for (axis, left), pad in zip(flags, odd_padding): |
| 100 | if pad == 0: |
| 101 | continue |
| 102 | axis_shape = list(dx.shape())[axis] |
| 103 | if left: |
| 104 | dx = singa.SliceOn(dx, pad, axis_shape, axis) |
| 105 | else: |
| 106 | dx = singa.SliceOn(dx, 0, axis_shape - pad, axis) |
| 107 | return dx |
| 108 | |
| 109 | |
| 110 | def same_pad_shape_check(handle, pad_mode, x): |