code: def test_sddmm(create_func, shape, nnz, hidden):
      dev = F.ctx()
      A = create_func(shape, nnz, dev)
      if hidden > 1:
          B = torch.rand(
              shape[0], hidden, requires_grad=True, device=dev
          )
          C = torch.rand(
              hidden, shape[1], requires_grad=True, device=dev
          )
      else:
          B = torch.rand(shape[0], requires_grad=True, device=dev)
          C = torch.rand(shape[1], requires_grad=True, device=dev)
  
      B = rand_stride(B)
      C = rand_stride(C)
  
      A_val_clone = clone_detach_and_grad(A.val)
      dense_B = clone_detach_and_grad(B)
      dense_C = clone_detach_and_grad(C)
  
      sparse_result = sddmm(A, B, C)
  
      grad = torch.rand_like(sparse_result.val)
      sparse_result.val.backward(grad)
  
      if hidden == 1:
          dense_result = dense_B.view(-1, 1) @ dense_C.view(1, -1)
      else:
          dense_result = dense_B @ dense_C
  
      row, col = A.coo()
      dense_val = dense_result[row, col] * A_val_clone
      dense_val.backward(grad)
  
      assert torch.allclose(dense_val, sparse_result.val, atol=1e-05)
      assert torch.allclose(dense_C.grad, C.grad, atol=1e-05)
      assert torch.allclose(dense_B.grad, B.grad, atol=1e-05)
      assert torch.allclose(A_val_clone.grad, A.val.grad, atol=1e-05)
  
file_path: dgl/tests/python/pytorch/sparse/test_sddmm.py
imports: import sys
  import backend
  import pytest
  import torch
  from dgl.sparse import bsddmm, sddmm
  from .utils import clone_detach_and_grad, rand_coo, rand_csc, rand_csr, rand_stride
label_desc: Use image node_id 1 for calling a global function with example usage: test_sddmm(create_func, shape, nnz, hidden) without return types