From b07ca1de1fa53a6cafa177b474bd6d79b3c1aef6 Mon Sep 17 00:00:00 2001 From: yangyaming Date: Fri, 19 Jan 2018 16:03:24 +0800 Subject: [PATCH] resize before computing LoD. --- paddle/operators/sequence_reshape_op.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/paddle/operators/sequence_reshape_op.h b/paddle/operators/sequence_reshape_op.h index 623904ec7c2..dd9b611250b 100644 --- a/paddle/operators/sequence_reshape_op.h +++ b/paddle/operators/sequence_reshape_op.h @@ -46,8 +46,8 @@ class SequenceReshapeKernel : public framework::OpKernel { } else { auto& out_lod = *out->mutable_lod(); out_lod.resize(1); - out_lod[0].clear(); - out_lod[0].push_back(0); + out_lod[0].resize(seq_num + 1); + out_lod[0][0] = 0; for (int i = 0; i < seq_num; ++i) { size_t seq_len = in_lod_l0[i + 1] - in_lod_l0[i]; size_t offset = 0; @@ -57,11 +57,10 @@ class SequenceReshapeKernel : public framework::OpKernel { "be divided by new_dim with no remainder for each " "sequence. The %dth sequence is invalid.", i + 1); - out_lod[0].push_back(out_lod[0].back() + offset); + out_lod[0][i + 1] = out_lod[0][i] + offset; } } - out->mutable_data(context.GetPlace()); framework::Copy(*in, context.GetPlace(), out); out->Resize({static_cast(out->lod()[0].back()), out_width}); } -- GitLab