Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,17 @@ def test_cached_addcdiv(self):
xm.mark_step()
self.assertEqual(met.metric_data("TransferToServerTime")[0], 4)

def test_index_types(self):

def test_fn(*indices):
x = torch.arange(10).to(indices[0].device)
return [x[idx] for idx in indices]

self.runAtenTest([
torch.randint(0, 1, size=(10,), dtype=dtype)
for dtype in (torch.long, torch.int32, torch.bool)
], test_fn)


class MNISTComparator(nn.Module):

Expand Down
11 changes: 6 additions & 5 deletions torch_xla/csrc/ops/index_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ void CheckIndexTensorTypes(
for (const c10::optional<at::Tensor>& tensor : indices) {
if (tensor.has_value() && tensor->defined()) {
at::ScalarType scalar_type = tensor->scalar_type();
if (scalar_type != at::kLong && scalar_type != at::kByte &&
scalar_type != at::kBool) {
XLA_ERROR() << "Tensors used as indices must be long, byte or boolean "
"tensors, found scalar type: "
<< scalar_type;
if (scalar_type != at::kLong && scalar_type != at::kInt &&
scalar_type != at::kByte && scalar_type != at::kBool) {
XLA_ERROR()
<< "Tensors used as indices must be long, int, byte or boolean "
"tensors, found scalar type: "
<< scalar_type;
}
}
}
Expand Down