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

Function test_spspdiv

tests/python/pytorch/sparse/test_elementwise_op_sp.py:145–157  ·  view source on GitHub ↗
(create_func, nnz, shape, nz_dim)

Source from the content-addressed store, hash-verified

143@pytest.mark.parametrize("nnz", [1, 14])
144@pytest.mark.parametrize("nz_dim", [None, 3])
145def test_spspdiv(create_func, nnz, shape, nz_dim):
146 dev = F.ctx()
147 A = create_func(shape, nnz, dev, nz_dim)
148
149 perm = torch.randperm(A.nnz, device=dev)
150 rperm = torch.argsort(perm)
151 B = spmatrix(A.indices()[:, perm], A.val[perm], A.shape)
152 C = div(A, B)
153 assert not C.has_duplicate()
154 assert torch.allclose(C.val, A.val / B.val[rperm], atol=1e-05)
155 assert torch.allclose(C.indices(), A.indices(), atol=1e-05)
156
157 # No need to test backward here, since it is handled by Pytorch

Callers

nothing calls this directly

Calls 5

spmatrixFunction · 0.90
divFunction · 0.90
has_duplicateMethod · 0.80
ctxMethod · 0.45
indicesMethod · 0.45

Tested by

no test coverage detected