From 286e0d8358045fc1fa6bf956845b0b1b2de2b710 Mon Sep 17 00:00:00 2001 From: sneaxiy Date: Sun, 5 May 2019 09:30:47 +0800 Subject: [PATCH 1/2] fix tensor_py,test=develop --- paddle/fluid/pybind/tensor_py.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/paddle/fluid/pybind/tensor_py.h b/paddle/fluid/pybind/tensor_py.h index fd48f26f41102..240920937e4f8 100644 --- a/paddle/fluid/pybind/tensor_py.h +++ b/paddle/fluid/pybind/tensor_py.h @@ -431,14 +431,14 @@ inline void PyCUDAPinnedTensorSetFromArray( namespace details { template -constexpr bool IsValidDTypeToPyArray() { - return false; -} - -#define DECLARE_VALID_DTYPE_TO_PY_ARRAY(type) \ - template <> \ - constexpr bool IsValidDTypeToPyArray() { \ - return true; \ +struct IsValidDTypeToPyArray { + static constexpr bool kValue = false; +}; + +#define DECLARE_VALID_DTYPE_TO_PY_ARRAY(type) \ + template <> \ + struct IsValidDTypeToPyArray { \ + static constexpr bool kValue = true; \ } DECLARE_VALID_DTYPE_TO_PY_ARRAY(platform::float16); @@ -457,7 +457,8 @@ inline std::string TensorDTypeToPyDTypeStr( if (std::is_same::value) { \ return "e"; \ } else { \ - PADDLE_ENFORCE(IsValidDTypeToPyArray, \ + constexpr auto kIsValidDType = IsValidDTypeToPyArray::kValue; \ + PADDLE_ENFORCE(kIsValidDType, \ "This type of tensor cannot be expose to Python"); \ return py::format_descriptor::format(); \ } \ From ebf2d2ed531fc1808cc0f5f9f02b62ce6042cd9e Mon Sep 17 00:00:00 2001 From: sneaxiy Date: Sun, 5 May 2019 20:52:54 +0800 Subject: [PATCH 2/2] change class name,test=develop --- paddle/fluid/pybind/tensor_py.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/paddle/fluid/pybind/tensor_py.h b/paddle/fluid/pybind/tensor_py.h index 240920937e4f8..cec21f40073e2 100644 --- a/paddle/fluid/pybind/tensor_py.h +++ b/paddle/fluid/pybind/tensor_py.h @@ -431,13 +431,13 @@ inline void PyCUDAPinnedTensorSetFromArray( namespace details { template -struct IsValidDTypeToPyArray { +struct ValidDTypeToPyArrayChecker { static constexpr bool kValue = false; }; #define DECLARE_VALID_DTYPE_TO_PY_ARRAY(type) \ template <> \ - struct IsValidDTypeToPyArray { \ + struct ValidDTypeToPyArrayChecker { \ static constexpr bool kValue = true; \ } @@ -452,16 +452,16 @@ DECLARE_VALID_DTYPE_TO_PY_ARRAY(int64_t); inline std::string TensorDTypeToPyDTypeStr( framework::proto::VarType::Type type) { -#define TENSOR_DTYPE_TO_PY_DTYPE(T, proto_type) \ - if (type == proto_type) { \ - if (std::is_same::value) { \ - return "e"; \ - } else { \ - constexpr auto kIsValidDType = IsValidDTypeToPyArray::kValue; \ - PADDLE_ENFORCE(kIsValidDType, \ - "This type of tensor cannot be expose to Python"); \ - return py::format_descriptor::format(); \ - } \ +#define TENSOR_DTYPE_TO_PY_DTYPE(T, proto_type) \ + if (type == proto_type) { \ + if (std::is_same::value) { \ + return "e"; \ + } else { \ + constexpr auto kIsValidDType = ValidDTypeToPyArrayChecker::kValue; \ + PADDLE_ENFORCE(kIsValidDType, \ + "This type of tensor cannot be expose to Python"); \ + return py::format_descriptor::format(); \ + } \ } _ForEachDataType_(TENSOR_DTYPE_TO_PY_DTYPE);