@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
13
13
limitations under the License. */
14
14
15
15
#pragma once
16
+ #include < string>
16
17
#include < typeindex>
17
18
#include " paddle/fluid/framework/framework.pb.h"
18
19
#include " paddle/fluid/platform/enforce.h"
@@ -22,26 +23,28 @@ namespace paddle {
22
23
namespace framework {
23
24
24
25
inline proto::VarType::Type ToDataType (std::type_index type) {
25
- using namespace paddle ::framework::proto;
26
26
if (typeid (platform::float16).hash_code () == type.hash_code ()) {
27
27
return proto::VarType::FP16;
28
- } else if (typeid (float ).hash_code () == type.hash_code ()) {
28
+ } else if (typeid (const float ).hash_code () == type.hash_code ()) {
29
+ // CPPLint complains Using C-style cast. Use static_cast<float>() instead
30
+ // One fix to this is to replace float with const float because
31
+ // typeid(T) == typeid(const T)
32
+ // http://en.cppreference.com/w/cpp/language/typeid
29
33
return proto::VarType::FP32;
30
- } else if (typeid (double ).hash_code () == type.hash_code ()) {
34
+ } else if (typeid (const double ).hash_code () == type.hash_code ()) {
31
35
return proto::VarType::FP64;
32
- } else if (typeid (int ).hash_code () == type.hash_code ()) {
36
+ } else if (typeid (const int ).hash_code () == type.hash_code ()) {
33
37
return proto::VarType::INT32;
34
- } else if (typeid (int64_t ).hash_code () == type.hash_code ()) {
38
+ } else if (typeid (const int64_t ).hash_code () == type.hash_code ()) {
35
39
return proto::VarType::INT64;
36
- } else if (typeid (bool ).hash_code () == type.hash_code ()) {
40
+ } else if (typeid (const bool ).hash_code () == type.hash_code ()) {
37
41
return proto::VarType::BOOL;
38
42
} else {
39
43
PADDLE_THROW (" Not supported" );
40
44
}
41
45
}
42
46
43
47
inline std::type_index ToTypeIndex (proto::VarType::Type type) {
44
- using namespace paddle ::framework::proto;
45
48
switch (type) {
46
49
case proto::VarType::FP16:
47
50
return typeid (platform::float16);
@@ -62,7 +65,6 @@ inline std::type_index ToTypeIndex(proto::VarType::Type type) {
62
65
63
66
template <typename Visitor>
64
67
inline void VisitDataType (proto::VarType::Type type, Visitor visitor) {
65
- using namespace paddle ::framework::proto;
66
68
switch (type) {
67
69
case proto::VarType::FP16:
68
70
visitor.template operator ()<platform::float16>();
@@ -88,7 +90,6 @@ inline void VisitDataType(proto::VarType::Type type, Visitor visitor) {
88
90
}
89
91
90
92
inline std::string DataTypeToString (const proto::VarType::Type type) {
91
- using namespace paddle ::framework::proto;
92
93
switch (type) {
93
94
case proto::VarType::FP16:
94
95
return " float16" ;
0 commit comments