}
void TensorIterator::serial_for_each(const loop2d_t& loop, Range range) const {
+ if (range.size() == 0) {
+ return;
+ }
auto strides = get_strides();
while (strides.size() < 2 * ntensors()) {
strides.push_back(0);
int64_t ndim = values.size();
for (int dim = 0; dim < ndim; dim++) {
int64_t size = shape[dim];
- values[dim] = linear_offset % size;
- linear_offset /= size;
+ if (size > 0) {
+ values[dim] = linear_offset % size;
+ linear_offset /= size;
+ }
}
AT_ASSERT(linear_offset == 0);
}
v = torch.tensor([1.])
self.assertEqual(v[v == 0], torch.tensor([]))
+ def test_byte_mask_accumulate(self):
+ mask = torch.zeros(size=(10, ), dtype=torch.uint8)
+ y = torch.ones(size=(10, 10))
+ y.index_put_((mask, ), y[mask], accumulate=True)
+ self.assertEqual(y, torch.ones(size=(10, 10)))
+
def test_multiple_byte_mask(self):
v = torch.randn(5, 7, 3)
# note: these broadcast together and are transposed to the first dim