Skip to content

Commit f92c5aa

Browse files
ngimelsoumith
authored andcommitted
slightly simplified indexing (#4040)
1 parent ea7652e commit f92c5aa

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

aten/src/THC/THCTensorInfo.cuh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,13 @@ struct IndexToOffset {
233233
IndexType offset = 0;
234234

235235
// Use static dims
236-
for (int i = Dims - 1; i >= 0; --i) {
236+
for (int i = Dims - 1; i > 0; --i) {
237237
IndexType curDimIndex = linearId % info.sizes[i];
238238
IndexType curDimOffset = curDimIndex * info.strides[i];
239239
offset += curDimOffset;
240-
241-
if (i > 0) {
242-
linearId /= info.sizes[i];
243-
}
240+
linearId /= info.sizes[i];
244241
}
242+
offset += linearId * info.strides[0];
245243

246244
return offset;
247245
}

0 commit comments

Comments
 (0)