提交 f043aab7 编写于 作者: A A. Unique TensorFlower 提交者: TensorFlower Gardener

Fixes in CompareConstantArrays:

 - Array fields minmax and quantization_params are pointers.
      (so the current check could have false negatives as identical objects
       have different addresses)
 - also compare narrow_range.
      (so the current check could have false positives --- my bad, I added
       narrow_range later and forgot to update this code).

PiperOrigin-RevId: 216626868
上级 d45c30fa
......@@ -107,6 +107,11 @@ struct QuantizationParams {
double scale = 0.0;
};
inline bool operator==(const QuantizationParams& qp1,
const QuantizationParams& qp2) {
return qp1.zero_point == qp2.zero_point && qp1.scale == qp2.scale;
}
template <int N>
struct Dims {
int sizes[N];
......
......@@ -738,15 +738,41 @@ bool CompareArrayBuffers(const Array& lhs_array, const Array& rhs_array) {
}
return true;
}
bool HaveSameMinMax(const Array& lhs_array, const Array& rhs_array) {
if (lhs_array.minmax || rhs_array.minmax) {
if (!lhs_array.minmax || !rhs_array.minmax) {
return false;
}
if (!(*lhs_array.minmax == *rhs_array.minmax)) {
return false;
}
}
return true;
}
bool HaveSameQuantizationParams(const Array& lhs_array,
const Array& rhs_array) {
if (lhs_array.quantization_params || rhs_array.quantization_params) {
if (!lhs_array.quantization_params || !rhs_array.quantization_params) {
return false;
}
if (!(*lhs_array.quantization_params == *rhs_array.quantization_params)) {
return false;
}
}
return true;
}
} // namespace
bool CompareConstantArrays(const Array& lhs_array, const Array& rhs_array) {
bool attrs_equal =
lhs_array.shape() == rhs_array.shape() &&
lhs_array.data_type == rhs_array.data_type &&
lhs_array.final_data_type == rhs_array.final_data_type &&
lhs_array.minmax == rhs_array.minmax &&
lhs_array.quantization_params == rhs_array.quantization_params;
bool attrs_equal = lhs_array.shape() == rhs_array.shape() &&
lhs_array.data_type == rhs_array.data_type &&
lhs_array.final_data_type == rhs_array.final_data_type &&
HaveSameMinMax(lhs_array, rhs_array) &&
HaveSameQuantizationParams(lhs_array, rhs_array) &&
lhs_array.narrow_range == rhs_array.narrow_range;
if (!attrs_equal) {
return false;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册