message: Change quantized reduce mean 4d to be integer-only.
diff: @@ -2605,31 +2605,29 @@ inline void Mean(const tflite::MeanParams& op_params,
  TFLITE_CHECK_EQ(output_height, 1);
  TFLITE_CHECK_EQ(output_width, 1);
  - const bool ordinary_mean =
  - (input_zero_point == output_zero_point && input_scale == output_scale);
  - float scale, bias;
  - if (!ordinary_mean) {
  - scale = input_scale / output_scale;
  - bias = -input_zero_point * scale + 0.5;
  - }
  + constexpr int32_t kMinValue = std::numeric_limits<uint8_t>::min();
  + constexpr int32_t kMaxValue = std::numeric_limits<uint8_t>::max();
  +
  + int32 bias =
  + output_zero_point -
  + static_cast<int32>(input_zero_point * input_scale / output_scale);
  + float real_scale = input_scale / (num_elements_in_axis * output_scale);
  +
  + int32 multiplier, shift;
  + QuantizeMultiplier(real_scale, &multiplier, &shift);
  for (int out_b = 0; out_b < output_batch; ++out_b) {
  for (int out_d = 0; out_d < output_depth; ++out_d) {
  - float temp_value = 0;
  + int acc = 0;
  for (int in_h = 0; in_h < input_height; ++in_h) {
  for (int in_w = 0; in_w < input_width; ++in_w) {
  - temp_value +=
  - input_data[Offset(input_shape, out_b, in_h, in_w, out_d)];
  + acc += input_data[Offset(input_shape, out_b, in_h, in_w, out_d)];
  }
  }
  - temp_value = temp_value / num_elements_in_axis;
  - if (ordinary_mean) {
  + MultiplyByQuantizedMultiplier(acc, multiplier, shift);
  + acc += bias;
  + acc = std::min(std::max(acc, kMinValue), kMaxValue);
  output_data[Offset(output_shape, out_b, 0, 0, out_d)] =
  - static_cast<uint8_t>(std::round(temp_value));
  - } else {
  - output_data[Offset(output_shape, out_b, 0, 0, out_d)] =
  - static_cast<uint8_t>(std::round(temp_value * scale + bias)) +
  - output_zero_point;
  - }
  + static_cast<uint8_t>(acc);
  }
  }
  }
  