50inline void Depad(
const int32_t *padding_data, int32_t pad_rank,
const Shape &input_shape,
53 using PaddingInfo = std::pair<int32_t, int32_t>;
54 using PaddingList = std::vector<PaddingInfo>;
59 PaddingList padding_list(pad_rank);
60 for (int32_t n = 0; n < pad_rank; ++n)
62 const int32_t *from = padding_data + (n * 2);
63 assert(from[0] >= 0 && from[1] >= 0);
64 padding_list[n] = {from[0], from[1]};
66 for (int32_t i = 0; i < pad_rank; ++i)
69 input_shape.
Dims(i) - padding_list[i].first - padding_list[i].second);
79 const int32_t padding_left = padding_list[0].first;
80 std::memcpy(output_data, input_data + padding_left, out_row_len *
sizeof(T));
87 const int32_t in_row_len = input_shape.
Dims(1);
88 const int32_t padding_top = padding_list[0].first;
89 const int32_t padding_left = padding_list[1].first;
90 for (
auto i = 0; i < out_col_len; ++i)
92 const auto in_offset = (i + padding_top) * in_row_len + padding_left;
93 const auto out_offset = i * out_row_len;
95 std::memcpy(output_data + out_offset, input_data + in_offset, out_row_len *
sizeof(T));
104 const int32_t out_plain_size = out_col_len * out_row_len;
105 const int32_t in_col_len = input_shape.
Dims(1);
106 const int32_t in_row_len = input_shape.
Dims(2);
107 const int32_t in_plain_size = in_col_len * in_row_len;
108 const int32_t padding_depth = padding_list[0].first;
109 const int32_t padding_top = padding_list[1].first;
110 const int32_t padding_left = padding_list[2].first;
111 for (
auto d = 0; d < out_plain_len; ++d)
113 for (
auto h = 0; h < out_col_len; ++h)
115 const auto in_offset =
116 (d + padding_depth) * in_plain_size + (h + padding_top) * in_row_len + (padding_left);
117 const auto out_offset = (d * out_plain_size) + (h * out_row_len);
119 std::memcpy(output_data + out_offset, input_data + in_offset, out_row_len *
sizeof(T));
130 const int32_t out_plain_size = out_col_len * out_row_len;
131 const int32_t out_cube_size = out_plain_len * out_plain_size;
132 const int32_t in_plain_len = input_shape.
Dims(1);
133 const int32_t in_col_len = input_shape.
Dims(2);
134 const int32_t in_row_len = input_shape.
Dims(3);
135 const int32_t in_plain_size = in_col_len * in_row_len;
136 const int32_t in_cube_size = in_plain_len * in_plain_size;
137 const int32_t padding_cube = padding_list[0].first;
138 const int32_t padding_depth = padding_list[1].first;
139 const int32_t padding_top = padding_list[2].first;
140 const int32_t padding_left = padding_list[3].first;
141 for (
auto c = 0; c < out_cube_len; ++c)
143 for (
auto d = 0; d < out_plain_len; ++d)
145 for (
auto h = 0; h < out_col_len; ++h)
147 const auto in_offset = (c + padding_cube) * in_cube_size +
148 (d + padding_depth) * in_plain_size +
149 (h + padding_top) * in_row_len + (padding_left);
150 const auto out_offset = (c * out_cube_size) + (d * out_plain_size) + (h * out_row_len);
152 std::memcpy(output_data + out_offset, input_data + in_offset, out_row_len *
sizeof(T));
159 throw std::runtime_error(
"Padding for rank > 4 NYI");