From 40f0e7c6258af904dd34288069fd61e96260348f Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Mon, 31 Aug 2020 14:59:31 -0700 Subject: [PATCH] MSVC2015 does not support a mix of struct and initializer list initialization so this patch works around the issue by allowing the initialization of DerivedScale with an initializer list of float initializer lists. While this enables compilation of TFLite with MSVC2015 it also has the unfortunate side effect of moving incorrect initialization of DerivedScale (e.g `DerivedScale foo = {1, 2};`) from a compile time to a runtime error. PiperOrigin-RevId: 329385442 Change-Id: Ia609f2d06cb573c8d791b600501d97aa3efed1f3 --- .../lite/tools/optimize/operator_property.h | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tensorflow/lite/tools/optimize/operator_property.h b/tensorflow/lite/tools/optimize/operator_property.h index ef84f3aaac1..58922a60e27 100644 --- a/tensorflow/lite/tools/optimize/operator_property.h +++ b/tensorflow/lite/tools/optimize/operator_property.h @@ -26,6 +26,27 @@ namespace operator_property { // the scales. For example, for bias in conv, derived_scale = {{0, 1}, {}, {}} // and for lstm gate bias, the derived scale is {{}, {0}, {2^-10}} struct DerivedScale { + // MSVC2015 version 14.0 and below doesn't support struct initialization with + // initializer lists so emulate the behavior using a float initializer list. +#if _MSC_VER <= 1900 + DerivedScale() {} + // Construct this object with a list of initializer lists. All list elements + // are cast to float values to avoid ambiguous construction of a union-style + // object that could take either std::initializer_list or + // std::initializer_list. + DerivedScale(std::initializer_list> values) { + assert(values.size() == 3); + std::vector> items(values); + for (auto& it : items[0]) { + input_tensors.push_back(static_cast(it)); + } + for (auto& it : items[1]) { + intermediate_tensors.push_back(static_cast(it)); + } + factors.assign(items[2]); + } +#endif // _MSC_VER <= 1900 + std::vector input_tensors = {}; std::vector intermediate_tensors = {}; // This is a list of extra factors that are not associated with any other