File tree 2 files changed +11
-2
lines changed
2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -171,7 +171,11 @@ def shiftLastMode(self, tensor):
171
171
# resultValues[i] = data[i]
172
172
# TODO (rohany): Temporarily use a constant as the value.
173
173
resultValues [i ] = 2
174
- resultCoords [- 1 ][i ] = (resultCoords [- 1 ][i ] + 1 ) % tensor .shape [- 1 ]
174
+ # For order 2 tensors, always shift the last coordinate. Otherwise, shift only coordinates
175
+ # that have even last coordinates. This ensures that there is at least some overlap
176
+ # between the original tensor and its shifted counter part.
177
+ if tensor .shape [- 1 ] <= 0 or resultCoords [- 1 ][i ] % 2 == 0 :
178
+ resultCoords [- 1 ][i ] = (resultCoords [- 1 ][i ] + 1 ) % tensor .shape [- 1 ]
175
179
return sparse .COO (resultCoords , resultValues , tensor .shape )
176
180
177
181
# ScipyTensorShifter shifts all elements in the last mode
Original file line number Diff line number Diff line change @@ -50,7 +50,12 @@ taco::Tensor<T> shiftLastMode(std::string name, taco::Tensor<T2> original) {
50
50
coords[i] = value.first [i];
51
51
}
52
52
int lastMode = original.getOrder () - 1 ;
53
- coords[lastMode] = (coords[lastMode] + 1 ) % original.getDimension (lastMode);
53
+ // For order 2 tensors, always shift the last coordinate. Otherwise, shift only coordinates
54
+ // that have even last coordinates. This ensures that there is at least some overlap
55
+ // between the original tensor and its shifted counter part.
56
+ if (original.getOrder () <= 2 || (coords[lastMode] % 2 == 0 )) {
57
+ coords[lastMode] = (coords[lastMode] + 1 ) % original.getDimension (lastMode);
58
+ }
54
59
// TODO (rohany): Temporarily use a constant value here.
55
60
result.insert (coords, T (2 ));
56
61
}
You can’t perform that action at this time.
0 commit comments