Skip to content

Commit 9d0c674

Browse files
committed
always use a custom default float
1 parent bff762c commit 9d0c674

File tree

2 files changed

+7
-29
lines changed

2 files changed

+7
-29
lines changed

CMakeLists.txt

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,25 +84,6 @@ ELSE()
8484
ENDIF()
8585
ENDIF()
8686

87-
include(CheckCXXSourceCompiles)
88-
check_cxx_source_compiles(
89-
"
90-
#include <iostream>
91-
#include <iomanip>
92-
93-
int main()
94-
{
95-
std::cout << std::defaultfloat;
96-
return 0;
97-
}
98-
"
99-
HAS_DEFAULTFLOAT
100-
)
101-
102-
IF(HAS_DEFAULTFLOAT)
103-
ADD_DEFINITIONS(-DHAS_DEFAULTFLOAT)
104-
ENDIF()
105-
10687
# Can be compiled standalone
10788
IF(NOT TENSOR_LIB_INSTALL_BIN_DIR OR NOT TENSOR_LIB_INSTALL_LIB_DIR OR NOT TENSOR_LIB_INSTALL_INCLUDE_DIR)
10889
SET(TENSOR_LIB_INSTALL_BIN_DIR "bin" CACHE PATH "TENSOR_LIB install binary subdirectory")

Formatting.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@
77
#include <iostream>
88
#include <iomanip>
99

10-
#ifndef HAS_DEFAULTFLOAT
11-
namespace std {
12-
inline std::ios_base& defaultfloat(std::ios_base& __base)
13-
{
10+
11+
namespace at {
12+
13+
//not all C++ compilers have default float so we define our own here
14+
inline std::ios_base& defaultfloat(std::ios_base& __base) {
1415
__base.unsetf(std::ios_base::floatfield);
1516
return __base;
1617
}
17-
}
18-
#endif
19-
20-
namespace at {
2118

2219
std::ostream& operator<<(std::ostream & out, IntList list) {
2320
int i = 0;
@@ -100,7 +97,7 @@ static std::tuple<double, int64_t> __printFormat(std::ostream& stream, const Ten
10097
stream << std::scientific << std::setprecision(4);
10198
} else {
10299
sz = expMax + 1;
103-
stream << std::defaultfloat;
100+
stream << defaultfloat;
104101
}
105102
} else {
106103
if(expMax-expMin > 4) {
@@ -231,7 +228,7 @@ std::ostream& print(std::ostream& stream, const Tensor & tensor_, int64_t linesi
231228
} else {
232229
Tensor tensor = tensor_.toType(getType(kCPU,kDouble)).contiguous();
233230
if(tensor.ndimension() == 0) {
234-
stream << std::defaultfloat << tensor.data<double>()[0] << std::endl;
231+
stream << defaultfloat << tensor.data<double>()[0] << std::endl;
235232
stream << "[ " << tensor_.pImpl->toString() << "{} ]";
236233
} else if(tensor.ndimension() == 1) {
237234
double scale;

0 commit comments

Comments
 (0)