if (!hasContiguousSubspace(indices)) {
std::tie(self, indices) = transposeToFront(self, indices);
}
+ // Ensure indices are on the same device as self
+ for (size_t i = 0; i < indices.size(); i++) {
+ if (indices[i].defined() && indices[i].device() != self.device()) {
+ indices[i] = indices[i].to(self.device());
+ }
+ }
return AdvancedIndex(self, indices);
}
dim3 grid((N + block.x * vt - 1) / (block.x * vt));
auto stream = at::cuda::getCurrentCUDAStream();
elementwise_kernel<nt, vt, func_t><<<grid, block, 0, stream>>>(N, f);
+ AT_CUDA_CHECK(cudaGetLastError());
}
template<typename func_t>
// Throw StartsWith("Can only index with tensors that are scalars (zero-dim)")
ASSERT_ANY_THROW(tensor[ones({2, 3, 4}, kInt)].equal(one));
}
+void TestIndexingMixedDevice(Type& type) {
+ Tensor tensor = randn({20, 20}, type);
+ Tensor index = arange(10, kLong).cpu();
+ Tensor result = tensor.index({index});
+ ASSERT_TRUE(result[0].equal(tensor[0]));
+}
void TestDispatch() {
Tensor tensor = randn({20, 20});
Tensor other = randn({20, 20});
TestToString();
TestIndexingByScalar();
TestIndexingByZerodimTensor();
+ TestIndexingMixedDevice(type);
TestDispatch();
TestCore();
}