diff options
author | 2018-09-01 01:40:41 +0000 | |
---|---|---|
committer | 2018-09-04 06:50:34 +0000 | |
commit | ce9e5b035b32ef02cd7d10f6ffdd27cc2a75664d (patch) | |
tree | 9523edc9575c28d4b528a57de520455cae312d78 /tensorflow/python/framework | |
parent | c1385b0ddf823a6eabee865cc90e5d6147691add (diff) |
Fix syntax error in single_image_random_dot_stereograms caused by locale
This fix tries to address the issue raised in 21164 where
the single_image_random_dot_stereograms in different locale
(like de_DE) caused syntax error in python like:
```
File "<string>", line 28
def single_image_random_dot_stereograms(depth_values, hidden_surface_removal=True, convergence_dots_size=8, dots_per_inch=72, eye_separation=2,5, mu=0,333299994, normalize=True, normalize_max=-100, normalize_min=100, border_level=0, number_colors=256, output_image_shape=[1024, 768, 1], output_data_window=[1022, 757], name=None):
^
SyntaxError: invalid syntax
```
The issue was that the float to string conversion in
python_op_gen_internal.cc triggered snprintf (in `FloatToBuffer`) which is local
dependent and generates something like `eye_separatiion=2,5` in DE locale.
This fix replaced the float to string conversion with locale-independent
```
std::ostringstream s;
s.imbue(std::locale::classic());
```
This fix fixes 21164.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Diffstat (limited to 'tensorflow/python/framework')
-rw-r--r-- | tensorflow/python/framework/python_op_gen_internal.cc | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/tensorflow/python/framework/python_op_gen_internal.cc b/tensorflow/python/framework/python_op_gen_internal.cc index f2270342b0..8ddd1e6432 100644 --- a/tensorflow/python/framework/python_op_gen_internal.cc +++ b/tensorflow/python/framework/python_op_gen_internal.cc @@ -435,7 +435,10 @@ string AttrValueToPython(const string& type, const AttrValue& value, if (std::isnan(value.f()) || std::isinf(value.f())) { return strings::StrCat("float('", value.f(), "')"); } else { - return strings::StrCat(value.f()); + std::ostringstream s; + s.imbue(std::locale::classic()); + s << value.f(); + return s.str(); } } else if (type == "bool") { return value.b() ? "True" : "False"; |