aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/framework
diff options
context:
space:
mode:
authorGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-09-10 12:42:27 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-09-10 12:42:41 -0700
commit44f1fa1841f616b1b47a01f9aefbf52edcde481c (patch)
tree9cf4110ad78da98d5670edc64e86e59d21f17334 /tensorflow/python/framework
parentdd6d7c5c586b541b9d4793b7578feadd0c2da8f6 (diff)
parentf00855ee9c8ae8878a2feca7c2c8a23e4b9c6c11 (diff)
Merge pull request #22044 from yongtang:21164-default-float
PiperOrigin-RevId: 212314097
Diffstat (limited to 'tensorflow/python/framework')
-rw-r--r--tensorflow/python/framework/python_op_gen_internal.cc13
1 files changed, 10 insertions, 3 deletions
diff --git a/tensorflow/python/framework/python_op_gen_internal.cc b/tensorflow/python/framework/python_op_gen_internal.cc
index f2270342b0..f6aef5bc50 100644
--- a/tensorflow/python/framework/python_op_gen_internal.cc
+++ b/tensorflow/python/framework/python_op_gen_internal.cc
@@ -15,18 +15,20 @@ limitations under the License.
#include "tensorflow/python/framework/python_op_gen_internal.h"
+#include <float.h>
#include <stdio.h>
+#include <iomanip>
#include <sstream>
#include <unordered_map>
#include "tensorflow/core/framework/api_def.pb.h"
#include "tensorflow/core/framework/attr_value.pb.h"
#include "tensorflow/core/framework/op.h"
-#include "tensorflow/core/framework/op_def.pb_text.h"
#include "tensorflow/core/framework/op_def.pb.h"
+#include "tensorflow/core/framework/op_def.pb_text.h"
#include "tensorflow/core/framework/op_def_util.h"
#include "tensorflow/core/framework/op_gen_lib.h"
-#include "tensorflow/core/framework/tensor.pb_text.h"
#include "tensorflow/core/framework/tensor.pb.h"
+#include "tensorflow/core/framework/tensor.pb_text.h"
#include "tensorflow/core/framework/tensor_shape.pb.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/framework/types.pb.h"
@@ -435,7 +437,12 @@ 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());
+ // Use locale-independent conversion.
+ static_assert(FLT_DIG < 10, "FLT_DIG is too big");
+ std::ostringstream s;
+ s.imbue(std::locale::classic());
+ s << std::setprecision(FLT_DIG) << value.f();
+ return s.str();
}
} else if (type == "bool") {
return value.b() ? "True" : "False";