Skip to content

Commit d08791d

Browse files
authored
Fix CPPLint issues with Chunk_eval_op (#9964)
1 parent 8352f93 commit d08791d

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

paddle/fluid/operators/chunk_eval_op.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#include "paddle/fluid/operators/chunk_eval_op.h"
16+
#include <string>
17+
#include <vector>
1618

1719
namespace paddle {
1820
namespace operators {

paddle/fluid/operators/chunk_eval_op.h

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

1515
#pragma once
1616
#include <set>
17+
#include <string>
18+
#include <vector>
19+
1720
#include "paddle/fluid/framework/eigen.h"
1821
#include "paddle/fluid/framework/op_registry.h"
1922

@@ -36,11 +39,11 @@ class ChunkEvalKernel : public framework::OpKernel<T> {
3639
};
3740

3841
void GetSegments(const int64_t* label, int length,
39-
std::vector<Segment>& segments, int num_chunk_types,
42+
std::vector<Segment>* segments, int num_chunk_types,
4043
int num_tag_types, int other_chunk_type, int tag_begin,
4144
int tag_inside, int tag_end, int tag_single) const {
42-
segments.clear();
43-
segments.reserve(length);
45+
segments->clear();
46+
segments->reserve(length);
4447
int chunk_start = 0;
4548
bool in_chunk = false;
4649
int tag = -1;
@@ -58,7 +61,7 @@ class ChunkEvalKernel : public framework::OpKernel<T> {
5861
i - 1, // end
5962
prev_type,
6063
};
61-
segments.push_back(segment);
64+
segments->push_back(segment);
6265
in_chunk = false;
6366
}
6467
if (ChunkBegin(prev_tag, prev_type, tag, type, other_chunk_type,
@@ -73,7 +76,7 @@ class ChunkEvalKernel : public framework::OpKernel<T> {
7376
length - 1, // end
7477
type,
7578
};
76-
segments.push_back(segment);
79+
segments->push_back(segment);
7780
}
7881
}
7982

@@ -177,8 +180,8 @@ class ChunkEvalKernel : public framework::OpKernel<T> {
177180
for (int i = 0; i < num_sequences; ++i) {
178181
int seq_length = lod[0][i + 1] - lod[0][i];
179182
EvalOneSeq(inference_data + lod[0][i], label_data + lod[0][i], seq_length,
180-
output_segments, label_segments, *num_infer_chunks_data,
181-
*num_label_chunks_data, *num_correct_chunks_data,
183+
&output_segments, &label_segments, num_infer_chunks_data,
184+
num_label_chunks_data, num_correct_chunks_data,
182185
num_chunk_types, num_tag_types, other_chunk_type, tag_begin,
183186
tag_inside, tag_end, tag_single, excluded_chunk_types);
184187
}
@@ -197,10 +200,10 @@ class ChunkEvalKernel : public framework::OpKernel<T> {
197200
}
198201

199202
void EvalOneSeq(const int64_t* output, const int64_t* label, int length,
200-
std::vector<Segment>& output_segments,
201-
std::vector<Segment>& label_segments,
202-
int64_t& num_output_segments, int64_t& num_label_segments,
203-
int64_t& num_correct, int num_chunk_types, int num_tag_types,
203+
std::vector<Segment>* output_segments,
204+
std::vector<Segment>* label_segments,
205+
int64_t* num_output_segments, int64_t* num_label_segments,
206+
int64_t* num_correct, int num_chunk_types, int num_tag_types,
204207
int other_chunk_type, int tag_begin, int tag_inside,
205208
int tag_end, int tag_single,
206209
const std::set<int>& excluded_chunk_types) const {
@@ -209,25 +212,29 @@ class ChunkEvalKernel : public framework::OpKernel<T> {
209212
GetSegments(label, length, label_segments, num_chunk_types, num_tag_types,
210213
other_chunk_type, tag_begin, tag_inside, tag_end, tag_single);
211214
size_t i = 0, j = 0;
212-
while (i < output_segments.size() && j < label_segments.size()) {
213-
if (output_segments[i] == label_segments[j] &&
214-
excluded_chunk_types.count(output_segments[i].type) != 1) {
215-
++num_correct;
215+
while (i < output_segments->size() && j < label_segments->size()) {
216+
if (output_segments->at(i) == label_segments->at(j) &&
217+
excluded_chunk_types.count(output_segments->at(i).type) != 1) {
218+
++(*num_correct);
216219
}
217-
if (output_segments[i].end < label_segments[j].end) {
220+
if (output_segments->at(i).end < label_segments->at(j).end) {
218221
++i;
219-
} else if (output_segments[i].end > label_segments[j].end) {
222+
} else if (output_segments->at(i).end > label_segments->at(j).end) {
220223
++j;
221224
} else {
222225
++i;
223226
++j;
224227
}
225228
}
226-
for (auto& segment : label_segments) {
227-
if (excluded_chunk_types.count(segment.type) != 1) ++num_label_segments;
229+
for (auto& segment : (*label_segments)) {
230+
if (excluded_chunk_types.count(segment.type) != 1) {
231+
++(*num_label_segments);
232+
}
228233
}
229-
for (auto& segment : output_segments) {
230-
if (excluded_chunk_types.count(segment.type) != 1) ++num_output_segments;
234+
for (auto& segment : (*output_segments)) {
235+
if (excluded_chunk_types.count(segment.type) != 1) {
236+
++(*num_output_segments);
237+
}
231238
}
232239
}
233240
};

0 commit comments

Comments
 (0)