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

Function test_coalesce

tests/python/pytorch/sparse/test_sparse_matrix.py:417–435  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

415
416
417def test_coalesce():
418 ctx = F.ctx()
419
420 row = torch.tensor([1, 0, 0, 0, 1]).to(ctx)
421 col = torch.tensor([1, 1, 1, 2, 2]).to(ctx)
422 val = torch.arange(len(row)).to(ctx)
423 A = from_coo(row, col, val, (4, 4))
424
425 assert A.has_duplicate()
426
427 A_coalesced = A.coalesce()
428
429 assert A_coalesced.nnz == 4
430 assert A_coalesced.shape == (4, 4)
431 assert list(A_coalesced.row) == [0, 0, 1, 1]
432 assert list(A_coalesced.col) == [1, 2, 1, 2]
433 # Values of duplicate indices are added together.
434 assert list(A_coalesced.val) == [3, 3, 0, 4]
435 assert not A_coalesced.has_duplicate()
436
437
438def test_has_duplicate():

Callers

nothing calls this directly

Calls 5

from_cooFunction · 0.90
has_duplicateMethod · 0.80
coalesceMethod · 0.80
ctxMethod · 0.45
toMethod · 0.45

Tested by

no test coverage detected