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
This commit is contained in:
parent
384ffdab5d
commit
40f0e7c625
@ -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<float> or
|
||||
// std::initializer_list<int>.
|
||||
DerivedScale(std::initializer_list<std::initializer_list<float>> values) {
|
||||
assert(values.size() == 3);
|
||||
std::vector<std::initializer_list<float>> items(values);
|
||||
for (auto& it : items[0]) {
|
||||
input_tensors.push_back(static_cast<int>(it));
|
||||
}
|
||||
for (auto& it : items[1]) {
|
||||
intermediate_tensors.push_back(static_cast<int>(it));
|
||||
}
|
||||
factors.assign(items[2]);
|
||||
}
|
||||
#endif // _MSC_VER <= 1900
|
||||
|
||||
std::vector<int> input_tensors = {};
|
||||
std::vector<int> intermediate_tensors = {};
|
||||
// This is a list of extra factors that are not associated with any other
|
||||
|
Loading…
Reference in New Issue
Block a user