code: def test_spmm(create_func, shape, nnz, out_dim):
      dev = F.ctx()
      A = create_func(shape, nnz, dev)
      if out_dim is not None:
          X = torch.randn(
              shape[1], out_dim, requires_grad=True, device=dev
          )
      else:
          X = torch.randn(shape[1], requires_grad=True, device=dev)
  
      X = rand_stride(X)
      sparse_result = matmul(A, X)
      grad = torch.randn_like(sparse_result)
      sparse_result.backward(grad)
  
      adj = sparse_matrix_to_dense(A)
      XX = clone_detach_and_grad(X)
      dense_result = torch.matmul(adj, XX)
      if out_dim is None:
          dense_result = dense_result.view(-1)
      dense_result.backward(grad)
      assert torch.allclose(sparse_result, dense_result, atol=1e-05)
      assert torch.allclose(X.grad, XX.grad, atol=1e-05)
      assert torch.allclose(
          dense_mask(adj.grad, A),
          sparse_matrix_to_dense(val_like(A, A.val.grad)),
          atol=1e-05,
      )
  
file_path: dgl/tests/python/pytorch/sparse/test_matmul.py
imports: import warnings
  import backend
  import pytest
  import torch
  from dgl.sparse import bspmm, diag, from_coo, val_like
  from dgl.sparse.matmul import matmul
  from .utils import clone_detach_and_grad, dense_mask, rand_coo, rand_csc, rand_csr, rand_stride, sparse_matrix_to_dense, sparse_matrix_to_torch_sparse
label_desc: Use image node_id 2 for calling a global function with example usage: test_spmm(create_func, shape, nnz, out_dim) without return types