Make few implicit casts explicit to resolve clang warnings
PiperOrigin-RevId: 308693807 Change-Id: I9bfff0da006c029370561111d1cae37675e4eda0
This commit is contained in:
parent
f5e6c392b7
commit
6177daf885
@ -105,10 +105,10 @@ int8_t FloatToSymmetricQuantizedInt8(const float value, const float scale) {
|
|||||||
|
|
||||||
int32_t FloatToSymmetricQuantizedInt32(const float value, const float scale) {
|
int32_t FloatToSymmetricQuantizedInt32(const float value, const float scale) {
|
||||||
float quantized = round(value / scale);
|
float quantized = round(value / scale);
|
||||||
if (quantized > INT_MAX) {
|
if (static_cast<int>(quantized) > INT_MAX) {
|
||||||
quantized = INT_MAX;
|
quantized = static_cast<float>(INT_MAX);
|
||||||
} else if (quantized < INT_MIN) {
|
} else if (quantized < INT_MIN) {
|
||||||
quantized = INT_MIN;
|
quantized = static_cast<float> INT_MIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
return static_cast<int>(quantized);
|
return static_cast<int>(quantized);
|
||||||
@ -249,13 +249,15 @@ void SignedSymmetricQuantize(const float* values, TfLiteIntArray* dims,
|
|||||||
max = fmaxf(max, values[i]);
|
max = fmaxf(max, values[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
*scaling_factor = fmaxf(fabs(min), fabs(max)) / kSymmetricInt32Scale;
|
*scaling_factor =
|
||||||
|
fmaxf(fabs(min), fabs(max)) / static_cast<float>(kSymmetricInt32Scale);
|
||||||
for (int i = 0; i < input_size; i++) {
|
for (int i = 0; i < input_size; i++) {
|
||||||
const int32_t quantized_value =
|
const int32_t quantized_value =
|
||||||
static_cast<int32_t>(roundf(values[i] / *scaling_factor));
|
static_cast<int32_t>(roundf(values[i] / *scaling_factor));
|
||||||
// Clamp: just in case some odd numeric offset.
|
// Clamp: just in case some odd numeric offset.
|
||||||
quantized_values[i] = fminf(kSymmetricInt32Scale,
|
quantized_values[i] = fminf(
|
||||||
fmaxf(-kSymmetricInt32Scale, quantized_value));
|
static_cast<float>(kSymmetricInt32Scale),
|
||||||
|
fmaxf(static_cast<float>(-kSymmetricInt32Scale), quantized_value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user