code: def test_sparse():
      weight = torch.randn(5, 1).cuda().requires_grad_()
      weight_sparse = weight.detach().clone().requires_grad_()
      optimizer_dense = MADGRAD([weight], lr=1e-3, momentum=0)
      optimizer_sparse = MADGRAD([weight_sparse], lr=1e-3, momentum=0)
  
      weight.grad = torch.rand_like(weight)
      weight.grad[0] = 0.0  # Add a zero
      weight_sparse.grad = weight.grad.to_sparse()
  
      optimizer_dense.step()
      optimizer_sparse.step()
      assert torch.allclose(weight, weight_sparse)
  
      weight.grad = torch.rand_like(weight)
      weight.grad[1] = 0.0  # Add a zero
      weight_sparse.grad = weight.grad.to_sparse()
  
      optimizer_dense.step()
      optimizer_sparse.step()
      assert torch.allclose(weight, weight_sparse)
  
      weight.grad = torch.rand_like(weight)
      weight.grad[0] = 0.0  # Add a zero
      weight_sparse.grad = weight.grad.to_sparse()
  
      optimizer_dense.step()
      optimizer_sparse.step()
      assert torch.allclose(weight, weight_sparse)
  
file_path: madgrad/tests/test_madgrad.py
imports: import pytest
  import torch
  from madgrad import MADGRAD
label_desc: Use image node_id 10 for calling a global function with example usage: test_sparse() without return types