MCPcopy Index your code
hub / github.com/dmlc/dgl / test_spspmul

Function test_spspmul

tests/python/pytorch/sparse/test_elementwise_op_sp.py:114–136  ·  view source on GitHub ↗
(create_func1, create_func2, shape, nnz1, nnz2, nz_dim)

Source from the content-addressed store, hash-verified

112@pytest.mark.parametrize("nnz2", [1, 14])
113@pytest.mark.parametrize("nz_dim", [None, 3])
114def test_spspmul(create_func1, create_func2, shape, nnz1, nnz2, nz_dim):
115 dev = F.ctx()
116 A = create_func1(shape, nnz1, dev, nz_dim)
117 B = create_func2(shape, nnz2, dev, nz_dim)
118 C = mul(A, B)
119 assert not C.has_duplicate()
120
121 DA = sparse_matrix_to_dense(A)
122 DB = sparse_matrix_to_dense(B)
123 DC = DA * DB
124
125 grad = torch.rand_like(C.val)
126 C.val.backward(grad)
127 DC_grad = sparse_matrix_to_dense(val_like(C, grad))
128 DC.backward(DC_grad)
129
130 assert torch.allclose(sparse_matrix_to_dense(C), DC, atol=1e-05)
131 assert torch.allclose(
132 val_like(A, A.val.grad).to_dense(), DA.grad, atol=1e-05
133 )
134 assert torch.allclose(
135 val_like(B, B.val.grad).to_dense(), DB.grad, atol=1e-05
136 )
137
138
139@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 7

mulFunction · 0.90
val_likeFunction · 0.90
sparse_matrix_to_denseFunction · 0.85
has_duplicateMethod · 0.80
to_denseMethod · 0.80
ctxMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected