Skip to content

Commit 2328a69

Browse files
authored
Merge pull request #13012 from tensor-tang/refine/seq2batch
refine seq2batch
2 parents 82671e9 + fd4f7c3 commit 2328a69

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

paddle/fluid/operators/math/sequence2batch.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ class CopyMatrixRowsFunctor<platform::CPUDeviceContext, T> {
3838
auto width = dst_dims[1];
3939
auto* src_data = src.data<T>();
4040
auto* dst_data = dst->data<T>();
41-
for (int i = 0; i < height; ++i) {
42-
if (is_src_index) {
43-
memcpy(dst_data + i * width, src_data + index[i] * width,
44-
width * sizeof(T));
45-
} else {
46-
memcpy(dst_data + index[i] * width, src_data + i * width,
47-
width * sizeof(T));
41+
const int sz = width * sizeof(T);
42+
if (is_src_index) {
43+
for (int i = 0; i < height; ++i) {
44+
memcpy(dst_data + i * width, src_data + index[i] * width, sz);
45+
}
46+
} else {
47+
for (int i = 0; i < height; ++i) {
48+
memcpy(dst_data + index[i] * width, src_data + i * width, sz);
4849
}
4950
}
5051
}

0 commit comments

Comments
 (0)