48 constexpr int num_spatial_dims = 2;
50 assert(window_size.size() == num_spatial_dims);
51 assert(strides.size() == num_spatial_dims);
52 assert(padding_before.size() == num_spatial_dims);
53 assert(padding_after.size() == num_spatial_dims);
59 Index in_index(input_shape.rank());
64 size_t num_elements = 0;
67 in_index.
at(0) = out_index.at(0);
68 in_index.
at(3) = out_index.at(3);
73 for (
int i = 0; i < num_spatial_dims; ++i)
75 out_index.at(1 + i) * strides[i] + window_index.at(i) - padding_before[i];
80 result += input.at(in_index);
88 result /= num_elements;
89 res_accessor.
at(out_index) = result;
102 const auto &input_type = input.getType();
106 assert(input_type.isQuantized());
107 assert(output_type.isQuantized());
108 assert(input_type.getElementType() == DataType::UINT8);
118 constexpr int num_spatial_dims = 2;
119 assert(input.getShape().rank() == 4);
120 assert(window_size.size() == num_spatial_dims);
121 assert(strides.size() == num_spatial_dims);
122 assert(padding_before.size() == num_spatial_dims);
123 assert(padding_after.size() == num_spatial_dims);
129 Index in_index(input_shape.rank());
131 int32_t output_min = std::numeric_limits<uint8_t>::min();
132 int32_t output_max = std::numeric_limits<uint8_t>::max();
137 size_t num_elements = 0;
140 in_index.
at(0) = out_index.at(0);
141 in_index.
at(3) = out_index.at(3);
146 for (
int i = 0; i < num_spatial_dims; ++i)
148 out_index.at(1 + i) * strides[i] + window_index.at(i) - padding_before[i];
153 result += input_accessor.
at(in_index);
160 result = (result + num_elements / 2) / num_elements;
161 result = std::max(result, output_min);
162 result = std::min(result, output_max);
163 res_accessor.
at(out_index) =
static_cast<uint8_t
>(result);