@@ -23,15 +23,15 @@ namespace operators {
23
23
24
24
#define CLOG std::cout
25
25
26
- const std::string kForward = " FORWARD" ;
27
- const std::string kBackward = " BACKWARD" ;
28
- const std::string kBoth = " BOTH" ;
26
+ const char kForward [] = " FORWARD" ;
27
+ const char kBackward [] = " BACKWARD" ;
28
+ const char kBoth [] = " BOTH" ;
29
29
30
30
struct Formater {
31
31
std::string message;
32
32
std::string name;
33
33
std::vector<int > dims;
34
- std::type_index dtype{typeid (char )};
34
+ std::type_index dtype{typeid (const char )};
35
35
framework::LoD lod;
36
36
int summarize;
37
37
void * data{nullptr };
@@ -62,7 +62,7 @@ struct Formater {
62
62
}
63
63
}
64
64
void PrintDtype () {
65
- if (dtype.hash_code () != typeid (char ).hash_code ()) {
65
+ if (dtype.hash_code () != typeid (const char ).hash_code ()) {
66
66
CLOG << " \t dtype: " << dtype.name () << std::endl;
67
67
}
68
68
}
@@ -83,15 +83,15 @@ struct Formater {
83
83
void PrintData (size_t size) {
84
84
PADDLE_ENFORCE_NOT_NULL (data);
85
85
// print float
86
- if (dtype.hash_code () == typeid (float ).hash_code ()) {
86
+ if (dtype.hash_code () == typeid (const float ).hash_code ()) {
87
87
Display<float >(size);
88
- } else if (dtype.hash_code () == typeid (double ).hash_code ()) {
88
+ } else if (dtype.hash_code () == typeid (const double ).hash_code ()) {
89
89
Display<double >(size);
90
- } else if (dtype.hash_code () == typeid (int ).hash_code ()) {
90
+ } else if (dtype.hash_code () == typeid (const int ).hash_code ()) {
91
91
Display<int >(size);
92
- } else if (dtype.hash_code () == typeid (int64_t ).hash_code ()) {
92
+ } else if (dtype.hash_code () == typeid (const int64_t ).hash_code ()) {
93
93
Display<int64_t >(size);
94
- } else if (dtype.hash_code () == typeid (bool ).hash_code ()) {
94
+ } else if (dtype.hash_code () == typeid (const bool ).hash_code ()) {
95
95
Display<bool >(size);
96
96
} else {
97
97
CLOG << " \t data: unprintable type: " << dtype.name () << std::endl;
@@ -100,7 +100,7 @@ struct Formater {
100
100
101
101
template <typename T>
102
102
void Display (size_t size) {
103
- auto * d = (T*) data;
103
+ auto * d = reinterpret_cast <T*>( data) ;
104
104
CLOG << " \t data: " ;
105
105
if (summarize != -1 ) {
106
106
summarize = std::min (size, (size_t )summarize);
@@ -135,7 +135,7 @@ class TensorPrintOp : public framework::OperatorBase {
135
135
void RunImpl (const framework::Scope& scope,
136
136
const platform::Place& place) const override {
137
137
const framework::Variable* in_var_ptr = nullptr ;
138
- std::string phase = kForward ;
138
+ std::string phase ( kForward ) ;
139
139
std::string printed_var_name = " " ;
140
140
141
141
auto & inputs = Inputs ();
@@ -146,7 +146,7 @@ class TensorPrintOp : public framework::OperatorBase {
146
146
!Inputs (" In@GRAD" ).empty ()) {
147
147
in_var_ptr = scope.FindVar (Input (" In@GRAD" ));
148
148
printed_var_name = Inputs (" In@GRAD" ).front ();
149
- phase = kBackward ;
149
+ phase = std::string ( kBackward ) ;
150
150
} else {
151
151
PADDLE_THROW (" Unknown phase, should be forward or backward." );
152
152
}
@@ -163,7 +163,7 @@ class TensorPrintOp : public framework::OperatorBase {
163
163
out_tensor.set_lod (in_tensor.lod ());
164
164
165
165
std::string print_phase = Attr<std::string>(" print_phase" );
166
- if (print_phase != phase && print_phase != kBoth ) {
166
+ if (print_phase != phase && print_phase != std::string ( kBoth ) ) {
167
167
return ;
168
168
}
169
169
@@ -199,7 +199,7 @@ class TensorPrintOp : public framework::OperatorBase {
199
199
formater.lod = printed_tensor.lod ();
200
200
}
201
201
formater.summarize = Attr<int >(" summarize" );
202
- formater.data = ( void *) printed_tensor.data <void >();
202
+ formater.data = reinterpret_cast < void *>( printed_tensor.data <void >() );
203
203
formater (printed_tensor.numel ());
204
204
}
205
205
@@ -223,8 +223,9 @@ class PrintOpProtoAndCheckMaker : public framework::OpProtoAndCheckerMaker {
223
223
" print_phase" ,
224
224
" (string, default 'BOTH') Which phase to display including 'FORWARD' "
225
225
" 'BACKWARD' and 'BOTH'." )
226
- .SetDefault (kBoth )
227
- .InEnum ({kForward , kBackward , kBoth });
226
+ .SetDefault (std::string (kBoth ))
227
+ .InEnum ({std::string (kForward ), std::string (kBackward ),
228
+ std::string (kBoth )});
228
229
AddOutput (" Out" , " Output tensor with same data as input tensor." );
229
230
AddComment (R"DOC(
230
231
Creates a print op that will print when a tensor is accessed.
0 commit comments