| 53 | } |
| 54 | |
| 55 | void calculate_padding(int64_t idx, |
| 56 | std::vector<int64_t>& pads, |
| 57 | int64_t input_dim, |
| 58 | int64_t stride, |
| 59 | int64_t dilation, |
| 60 | int64_t weight_dim, |
| 61 | bool is_same_upper) |
| 62 | { |
| 63 | int64_t output_dim = (input_dim + stride - 1) / stride; // round up result |
| 64 | int64_t new_weight_dim = weight_dim + (weight_dim - 1) * (dilation - 1); |
| 65 | int64_t pad = |
| 66 | std::max(static_cast<int64_t>(0), (output_dim - 1) * stride + new_weight_dim - input_dim); |
| 67 | auto pad_ndims = pads.size() / 2; |
| 68 | |
| 69 | if(is_same_upper) |
| 70 | { |
| 71 | pads[idx] = pad / 2; |
| 72 | pads[idx + pad_ndims] = pad - pad / 2; |
| 73 | } |
| 74 | else |
| 75 | { |
| 76 | pads[idx + pad_ndims] = pad / 2; |
| 77 | pads[idx] = pad - pad / 2; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Given the input array dimensions; kernel (wei_lens); strides; and dilations, |