Skip to content

Commit a4cc7a3

Browse files
ruotianluosoumith
authored andcommitted
Not changing dimension size for expand when target size is -1
1 parent a0bf77f commit a4cc7a3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/TH/THStorage.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ int THLongStorage_inferExpandGeometry(long *tensorSizes, long *tensorStrides, lo
132132
long stride = (dim >= 0) ?
133133
tensorStrides[dim] : expandedSizesCalc[i + 1] * expandedStridesCalc[i+1];
134134
long targetSize = THLongStorage_data(sizes)[i];
135+
if (targetSize == -1) {
136+
if (dim < 0) {
137+
THFree(expandedSizesCalc);
138+
THFree(expandedStridesCalc);
139+
snprintf(error_buffer, buffer_len, "The expanded size of the tensor (%ld) isn't allowed in a leading, non-existing dimension %ld.", targetSize, i);
140+
return -1;
141+
} else {
142+
targetSize = size;
143+
}
144+
}
135145
if (size != targetSize) {
136146
if (size == 1) {
137147
size = targetSize;

0 commit comments

Comments
 (0)