MCPcopy
hub / github.com/dmlc/dgl / test_index_select

Function test_index_select

tests/python/pytorch/graphbolt/test_base.py:258–274  ·  view source on GitHub ↗
(dtype, idtype, pinned)

Source from the content-addressed store, hash-verified

256@pytest.mark.parametrize("idtype", [torch.int32, torch.int64])
257@pytest.mark.parametrize("pinned", [False, True])
258def test_index_select(dtype, idtype, pinned):
259 if F._default_context_str != "gpu" and pinned:
260 pytest.skip("Pinned tests are available only on GPU.")
261 tensor = torch.tensor([[2, 3], [5, 5], [20, 13]], dtype=dtype)
262 tensor = tensor.pin_memory() if pinned else tensor.to(F.ctx())
263 index = torch.tensor([0, 2], dtype=idtype, device=F.ctx())
264 gb_result = gb.index_select(tensor, index)
265 torch_result = tensor.to(F.ctx())[index.long()]
266 assert torch.equal(torch_result, gb_result)
267 if pinned:
268 gb_result = gb.index_select(tensor.cpu(), index.cpu().pin_memory())
269 assert torch.equal(torch_result.cpu(), gb_result)
270 assert gb_result.is_pinned()
271
272 # Test the internal async API
273 future = torch.ops.graphbolt.index_select_async(tensor.cpu(), index.cpu())
274 assert torch.equal(torch_result.cpu(), future.wait())
275
276
277@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 8

index_selectMethod · 0.80
pin_memoryMethod · 0.45
toMethod · 0.45
ctxMethod · 0.45
longMethod · 0.45
cpuMethod · 0.45
is_pinnedMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected