Skip to content

Commit 6f83142

Browse files
authored
Fix cpplint issues with beam_search_op and beam_search_decode_op (#9962)
* Fix cpplint warnings in beam_search_decode_op * Fix cpplint warnings in beam_search_op * Fix test * fix
1 parent 2d1a6f8 commit 6f83142

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

paddle/fluid/operators/beam_search_decode_op.cc

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

1515
#include "paddle/fluid/operators/beam_search_decode_op.h"
16+
#include <string>
1617
#include "paddle/fluid/platform/device_context.h"
1718

1819
namespace paddle {

paddle/fluid/operators/beam_search_decode_op.h

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

1515
#pragma once
1616

17+
#include <vector>
1718
#include "paddle/fluid/framework/lod_tensor_array.h"
1819
#include "paddle/fluid/framework/op_registry.h"
1920

@@ -87,7 +88,7 @@ struct BeamSearchDecoder {
8788
*/
8889
std::vector<BeamNodeVector<T>> PackTwoSteps(
8990
const LoDTensor& cur_ids, const LoDTensor& cur_scores,
90-
std::vector<BeamNodeVector<T>>& prefixes_list,
91+
std::vector<BeamNodeVector<T>>* prefixes_list,
9192
std::vector<SentenceVector<T>>* sentence_vector_list) const;
9293

9394
/**
@@ -140,7 +141,7 @@ Sentence<T> BeamSearchDecoder<T>::MakeSentence(const BeamNode<T>* node) const {
140141
template <typename T>
141142
std::vector<BeamNodeVector<T>> BeamSearchDecoder<T>::PackTwoSteps(
142143
const LoDTensor& cur_ids, const LoDTensor& cur_scores,
143-
std::vector<BeamNodeVector<T>>& prefixes_list,
144+
std::vector<BeamNodeVector<T>>* prefixes_list,
144145
std::vector<SentenceVector<T>>* sentence_vector_list) const {
145146
std::vector<BeamNodeVector<T>> result;
146147

@@ -153,7 +154,7 @@ std::vector<BeamNodeVector<T>> BeamSearchDecoder<T>::PackTwoSteps(
153154

154155
// if prefixes size is 0, it means this is the first step. In this step,
155156
// all candidate id is the start of candidate sentences.
156-
if (prefixes_list.empty()) {
157+
if (prefixes_list->empty()) {
157158
PADDLE_ENFORCE_EQ(cur_ids.lod().at(kSourceLevel).back(),
158159
cur_ids.lod().at(kSentenceLevel).back(),
159160
"in the first step");
@@ -162,7 +163,7 @@ std::vector<BeamNodeVector<T>> BeamSearchDecoder<T>::PackTwoSteps(
162163
cur_ids.data<int64_t>()[id_idx], cur_scores.data<T>()[id_idx])));
163164
}
164165
} else {
165-
BeamNodeVector<T>& prefixes = prefixes_list[src_idx];
166+
BeamNodeVector<T>& prefixes = prefixes_list->at(src_idx);
166167
SentenceVector<T>& sentence_vector = (*sentence_vector_list)[src_idx];
167168

168169
PADDLE_ENFORCE_EQ(src_end - src_start, prefixes.size(),
@@ -262,7 +263,7 @@ void BeamSearchDecoder<T>::PackAllSteps(const LoDTensorArray& step_ids,
262263
for (size_t step_id = 0; step_id < step_num; ++step_id) {
263264
beamnode_vector_list =
264265
PackTwoSteps(step_ids.at(step_id), step_scores.at(step_id),
265-
beamnode_vector_list, &sentence_vector_list);
266+
&beamnode_vector_list, &sentence_vector_list);
266267
}
267268
// append last beam_node to result
268269
for (size_t src_idx = 0; src_idx < src_num; ++src_idx) {

paddle/fluid/operators/beam_search_decode_op_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ TEST(BeamSearchDecodeOp, PackTwoStepsFistStep) {
125125

126126
BeamSearchDecoder<float> helper;
127127
beamnode_vector_list = helper.PackTwoSteps(
128-
ids[0], scores[0], beamnode_vector_list, &sentence_vector_list);
128+
ids[0], scores[0], &beamnode_vector_list, &sentence_vector_list);
129129
ASSERT_EQ(beamnode_vector_list.size(), 2UL);
130130
ASSERT_EQ(beamnode_vector_list[0].size(), 2UL);
131131
ASSERT_EQ(beamnode_vector_list[1].size(), 4UL);
@@ -167,7 +167,7 @@ TEST(BeamSearchDecodeOp, PackTwoSteps) {
167167

168168
BeamSearchDecoder<float> helper1;
169169
beamnode_vector_list = helper1.PackTwoSteps(
170-
ids[0], scores[0], beamnode_vector_list, &sentence_vector_list);
170+
ids[0], scores[0], &beamnode_vector_list, &sentence_vector_list);
171171

172172
ASSERT_EQ(sentence_vector_list[0].size(), 1UL);
173173
ASSERT_EQ(sentence_vector_list[1].size(), 0UL);

paddle/fluid/operators/beam_search_op.cc

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

1515
#include "paddle/fluid/operators/beam_search_op.h"
1616

17+
#include <algorithm>
1718
#include <map>
19+
#include <string>
20+
#include <vector>
1821
#include "paddle/fluid/framework/lod_tensor.h"
1922
#include "paddle/fluid/framework/op_registry.h"
2023

paddle/fluid/operators/beam_search_op.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ limitations under the License. */
1818
#include "gtest/gtest.h"
1919
#endif
2020

21+
#include <string>
22+
#include <vector>
2123
#include "paddle/fluid/framework/lod_tensor.h"
2224
#include "paddle/fluid/framework/operator.h"
2325

0 commit comments

Comments
 (0)