Skip to content

Commit 4031e12

Browse files
committed
Fix the precision loss in Tensor output stream operator <<
1 parent 76d023b commit 4031e12

File tree

1 file changed

+2
-0
lines changed
  • source/module_base/module_container/ATen/core

1 file changed

+2
-0
lines changed

source/module_base/module_container/ATen/core/tensor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ Tensor Tensor::operator[](const int& index) const {
324324
// Overloaded operator<< for the Tensor class.
325325
std::ostream& operator<<(std::ostream& os, const Tensor& tensor) {
326326
std::ios::fmtflags flag(os.flags());
327+
std::streamsize precision = os.precision(); // save the current precision
327328
const int64_t num_elements = tensor.NumElements();
328329
const DataType data_type = tensor.data_type();
329330
const DeviceType device_type = tensor.device_type();
@@ -398,6 +399,7 @@ std::ostream& operator<<(std::ostream& os, const Tensor& tensor) {
398399
#endif
399400
// restore the os settings
400401
os.flags(flag);
402+
os.precision(precision); // restore the precision
401403
return os;
402404
}
403405

0 commit comments

Comments
 (0)