From cdbc5e7353ff13a92a7f2ab59c784aa556926101 Mon Sep 17 00:00:00 2001 From: bingyanghuang Date: Tue, 11 Sep 2018 12:13:45 +0800 Subject: [PATCH] Add some comments --- paddle/fluid/operators/math/sequence_pooling.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/paddle/fluid/operators/math/sequence_pooling.cc b/paddle/fluid/operators/math/sequence_pooling.cc index 1ffbe3d820..f48c321c73 100644 --- a/paddle/fluid/operators/math/sequence_pooling.cc +++ b/paddle/fluid/operators/math/sequence_pooling.cc @@ -109,24 +109,32 @@ class LastFirstSeqPoolFunctor { void operator()(const platform::CPUDeviceContext& context, const framework::LoDTensor& input, framework::Tensor* output, const std::string pooltype) { + //Create pointers to input and output data auto* in_data = input.data(); auto* out_data = output->data(); + + //Calculate length of each word int64_t word_len = input.numel() / input.dims()[0]; auto lod = input.lod()[0]; - auto dims = input.dims(); if (pooltype == "LAST"){ for (int i=0; i < static_cast(lod.size()) - 1; ++i ){ + //Calculate the length of each sequence int64_t seq_len = static_cast(lod[i + 1] - lod[i]); + //Point to the begin of next sequence in_data += seq_len* word_len; - std::memcpy(out_data,(in_data-word_len),word_len*sizeof(int)); + //Copy the last words to output + std::memcpy(out_data,(in_data-word_len),word_len*sizeof(T)); out_data += word_len; } } else if(pooltype == "FIRST"){ for (int i=0; i < static_cast(lod.size()) - 1; ++i ){ + //Calculate the length of each sequence int64_t seq_len = static_cast(lod[i + 1] - lod[i]); - std::memcpy(out_data,in_data,word_len*sizeof(int)); + //Copy the first words of sequence to output + std::memcpy(out_data,in_data,word_len*sizeof(T)); + //Point to the next sequence in_data += seq_len * word_len; out_data += word_len; -- GitLab