diff --git a/paddle/framework/tensor_array.cc b/paddle/framework/tensor_array.cc index d54714c66c04f3f923aae4288c0d2bac8be5972c..2728bce1c1af848285e80d8ee8b3b61ec046342e 100644 --- a/paddle/framework/tensor_array.cc +++ b/paddle/framework/tensor_array.cc @@ -217,12 +217,11 @@ LoDTensor DynamicBatchUnpacker::GetBatch(size_t index) { // collect indice need to copy to the batch std::vector indice; - for (size_t seq_id = 0; seq_id < meta.size(); seq_id++) { - const auto& seq_meta = meta[seq_id]; - if (index >= seq_meta.end) break; - indice.push_back(seq_meta.begin + index); + for (const auto& seq : meta) { + size_t id = seq.begin + index; + if (id >= seq.end) break; + indice.push_back(id); } - PADDLE_ENFORCE(!indice.empty(), "invalid batch at %d", index); // copy the indice of records in LoDTensor @@ -232,16 +231,18 @@ LoDTensor DynamicBatchUnpacker::GetBatch(size_t index) { result.Resize(make_ddim(record_dims_vec)); result.mutable_data(platform::CPUPlace()); - for (size_t i = 0; i < indice.size() - 1; i++) { + for (size_t i = 0; i < indice.size(); i++) { auto index = indice[i]; auto target = result.Slice(i, i + 1); auto source_ = source->Slice(index, index + 1); + target.CopyFrom(source_, platform::CPUPlace()); } return result; } +// TODO(supejom) to cache lod if reasonable LoDTensor PackDynamicBatch(const std::vector& source, const std::vector& meta, const LoD& lod, size_t level) { @@ -273,7 +274,6 @@ LoDTensor PackDynamicBatch(const std::vector& source, } result.set_lod(lod); - return result; }