Skip to content

Commit 744ebcf

Browse files
authored
Fix CPPlint issues in fluid/inference (#10075)
1 parent 7a993ee commit 744ebcf

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

paddle/fluid/inference/io.cc

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ limitations under the License. */
1414

1515
#include "paddle/fluid/inference/io.h"
1616

17+
#include <algorithm>
1718
#include <fstream>
1819
#include "paddle/fluid/framework/block_desc.h"
1920
#include "paddle/fluid/framework/feed_fetch_type.h"
@@ -27,14 +28,14 @@ namespace inference {
2728
// linking the inference shared library.
2829
void Init(bool init_p2p) { framework::InitDevices(init_p2p); }
2930

30-
void ReadBinaryFile(const std::string& filename, std::string& contents) {
31+
void ReadBinaryFile(const std::string& filename, std::string* contents) {
3132
std::ifstream fin(filename, std::ios::in | std::ios::binary);
3233
PADDLE_ENFORCE(static_cast<bool>(fin), "Cannot open file %s", filename);
3334
fin.seekg(0, std::ios::end);
34-
contents.clear();
35-
contents.resize(fin.tellg());
35+
contents->clear();
36+
contents->resize(fin.tellg());
3637
fin.seekg(0, std::ios::beg);
37-
fin.read(&contents[0], contents.size());
38+
fin.read(&(contents->at(0)), contents->size());
3839
fin.close();
3940
}
4041

@@ -47,7 +48,7 @@ bool IsPersistable(const framework::VarDesc* var) {
4748
return false;
4849
}
4950

50-
void LoadPersistables(framework::Executor& executor, framework::Scope& scope,
51+
void LoadPersistables(framework::Executor* executor, framework::Scope* scope,
5152
const framework::ProgramDesc& main_program,
5253
const std::string& dirname,
5354
const std::string& param_filename) {
@@ -92,18 +93,18 @@ void LoadPersistables(framework::Executor& executor, framework::Scope& scope,
9293
op->CheckAttrs();
9394
}
9495

95-
executor.Run(*load_program, &scope, 0, true, true);
96+
executor->Run(*load_program, scope, 0, true, true);
9697

9798
delete load_program;
9899
}
99100

100-
std::unique_ptr<framework::ProgramDesc> Load(framework::Executor& executor,
101-
framework::Scope& scope,
101+
std::unique_ptr<framework::ProgramDesc> Load(framework::Executor* executor,
102+
framework::Scope* scope,
102103
const std::string& dirname) {
103104
std::string model_filename = dirname + "/__model__";
104105
std::string program_desc_str;
105106
VLOG(3) << "loading model from " << model_filename;
106-
ReadBinaryFile(model_filename, program_desc_str);
107+
ReadBinaryFile(model_filename, &program_desc_str);
107108

108109
std::unique_ptr<framework::ProgramDesc> main_program(
109110
new framework::ProgramDesc(program_desc_str));
@@ -113,11 +114,11 @@ std::unique_ptr<framework::ProgramDesc> Load(framework::Executor& executor,
113114
}
114115

115116
std::unique_ptr<framework::ProgramDesc> Load(
116-
framework::Executor& executor, framework::Scope& scope,
117+
framework::Executor* executor, framework::Scope* scope,
117118
const std::string& prog_filename, const std::string& param_filename) {
118119
std::string model_filename = prog_filename;
119120
std::string program_desc_str;
120-
ReadBinaryFile(model_filename, program_desc_str);
121+
ReadBinaryFile(model_filename, &program_desc_str);
121122

122123
std::unique_ptr<framework::ProgramDesc> main_program(
123124
new framework::ProgramDesc(program_desc_str));

paddle/fluid/inference/io.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ namespace inference {
2727

2828
void Init(bool init_p2p);
2929

30-
void LoadPersistables(framework::Executor& executor, framework::Scope& scope,
30+
void LoadPersistables(framework::Executor* executor, framework::Scope* scope,
3131
const framework::ProgramDesc& main_program,
3232
const std::string& dirname,
3333
const std::string& param_filename);
3434

35-
std::unique_ptr<framework::ProgramDesc> Load(framework::Executor& executor,
36-
framework::Scope& scope,
35+
std::unique_ptr<framework::ProgramDesc> Load(framework::Executor* executor,
36+
framework::Scope* scope,
3737
const std::string& dirname);
3838

39-
std::unique_ptr<framework::ProgramDesc> Load(framework::Executor& executor,
40-
framework::Scope& scope,
39+
std::unique_ptr<framework::ProgramDesc> Load(framework::Executor* executor,
40+
framework::Scope* scope,
4141
const std::string& prog_filename,
4242
const std::string& param_filename);
4343

paddle/fluid/inference/tests/test_helper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ void TestInference(const std::string& dirname,
133133
std::string prog_filename = "__model_combined__";
134134
std::string param_filename = "__params_combined__";
135135
inference_program = paddle::inference::Load(
136-
executor, *scope, dirname + "/" + prog_filename,
136+
&executor, scope, dirname + "/" + prog_filename,
137137
dirname + "/" + param_filename);
138138
} else {
139139
// Parameters are saved in separate files sited in the specified
140140
// `dirname`.
141-
inference_program = paddle::inference::Load(executor, *scope, dirname);
141+
inference_program = paddle::inference::Load(&executor, scope, dirname);
142142
}
143143
}
144144
// Disable the profiler and print the timing information

0 commit comments

Comments
 (0)