Skip to content

Commit

Permalink
always use a custom default float
Browse files Browse the repository at this point in the history
  • Loading branch information
zdevito committed Jul 10, 2017
1 parent bff762c commit 9d0c674
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
19 changes: 0 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,6 @@ ELSE()
ENDIF()
ENDIF()

include(CheckCXXSourceCompiles)
check_cxx_source_compiles(
"
#include <iostream>
#include <iomanip>
int main()
{
std::cout << std::defaultfloat;
return 0;
}
"
HAS_DEFAULTFLOAT
)

IF(HAS_DEFAULTFLOAT)
ADD_DEFINITIONS(-DHAS_DEFAULTFLOAT)
ENDIF()

# Can be compiled standalone
IF(NOT TENSOR_LIB_INSTALL_BIN_DIR OR NOT TENSOR_LIB_INSTALL_LIB_DIR OR NOT TENSOR_LIB_INSTALL_INCLUDE_DIR)
SET(TENSOR_LIB_INSTALL_BIN_DIR "bin" CACHE PATH "TENSOR_LIB install binary subdirectory")
Expand Down
17 changes: 7 additions & 10 deletions Formatting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@
#include <iostream>
#include <iomanip>

#ifndef HAS_DEFAULTFLOAT
namespace std {
inline std::ios_base& defaultfloat(std::ios_base& __base)
{

namespace at {

//not all C++ compilers have default float so we define our own here
inline std::ios_base& defaultfloat(std::ios_base& __base) {
__base.unsetf(std::ios_base::floatfield);
return __base;
}
}
#endif

namespace at {

std::ostream& operator<<(std::ostream & out, IntList list) {
int i = 0;
Expand Down Expand Up @@ -100,7 +97,7 @@ static std::tuple<double, int64_t> __printFormat(std::ostream& stream, const Ten
stream << std::scientific << std::setprecision(4);
} else {
sz = expMax + 1;
stream << std::defaultfloat;
stream << defaultfloat;
}
} else {
if(expMax-expMin > 4) {
Expand Down Expand Up @@ -231,7 +228,7 @@ std::ostream& print(std::ostream& stream, const Tensor & tensor_, int64_t linesi
} else {
Tensor tensor = tensor_.toType(getType(kCPU,kDouble)).contiguous();
if(tensor.ndimension() == 0) {
stream << std::defaultfloat << tensor.data<double>()[0] << std::endl;
stream << defaultfloat << tensor.data<double>()[0] << std::endl;
stream << "[ " << tensor_.pImpl->toString() << "{} ]";
} else if(tensor.ndimension() == 1) {
double scale;
Expand Down

0 comments on commit 9d0c674

Please sign in to comment.