Skip to content

Commit cdbc5e7

Browse files
committed
Add some comments
1 parent 53185fd commit cdbc5e7

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

paddle/fluid/operators/math/sequence_pooling.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,32 @@ class LastFirstSeqPoolFunctor {
109109
void operator()(const platform::CPUDeviceContext& context,
110110
const framework::LoDTensor& input, framework::Tensor* output,
111111
const std::string pooltype) {
112+
//Create pointers to input and output data
112113
auto* in_data = input.data<T>();
113114
auto* out_data = output->data<T>();
115+
116+
//Calculate length of each word
114117
int64_t word_len = input.numel() / input.dims()[0];
115118
auto lod = input.lod()[0];
116-
auto dims = input.dims();
117119
if (pooltype == "LAST"){
118120
for (int i=0; i < static_cast<int>(lod.size()) - 1; ++i ){
121+
//Calculate the length of each sequence
119122
int64_t seq_len = static_cast<int64_t>(lod[i + 1] - lod[i]);
123+
//Point to the begin of next sequence
120124
in_data += seq_len* word_len;
121-
std::memcpy(out_data,(in_data-word_len),word_len*sizeof(int));
125+
//Copy the last words to output
126+
std::memcpy(out_data,(in_data-word_len),word_len*sizeof(T));
122127
out_data += word_len;
123128

124129
}
125130
}
126131
else if(pooltype == "FIRST"){
127132
for (int i=0; i < static_cast<int>(lod.size()) - 1; ++i ){
133+
//Calculate the length of each sequence
128134
int64_t seq_len = static_cast<int64_t>(lod[i + 1] - lod[i]);
129-
std::memcpy(out_data,in_data,word_len*sizeof(int));
135+
//Copy the first words of sequence to output
136+
std::memcpy(out_data,in_data,word_len*sizeof(T));
137+
//Point to the next sequence
130138
in_data += seq_len * word_len;
131139
out_data += word_len;
132140

0 commit comments

Comments
 (0)