Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Optimize AddTakeGrad Tensor Sum #17906

Merged
merged 1 commit into from
Apr 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions 3rdparty/mshadow/mshadow/tensor_cpu-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,17 +503,20 @@ template<bool clip, typename IndexType, typename DType>
inline void AddTakeGrad(Tensor<cpu, 2, DType> dst,
const Tensor<cpu, 1, IndexType>& index,
const Tensor<cpu, 2, DType> &src) {
const int K = dst.shape_[0];
const index_t K = dst.shape_[0];
const index_t C = dst.shape_[1];
for (index_t y = 0; y < index.size(0); ++y) {
int j = index[y];
index_t j = index[y];
if (clip) {
if (j <= 0) j = 0;
else if (j >= K) j = K - 1;
} else {
j %= K;
if (j < 0) j += K;
}
dst[j] += src[y];
for (index_t i = 0; i < C; ++i) {
dst[j][i] += src[y][i];
}
}
}

Expand Down