code: def test_random_sparse_mask(device):
      """Tests random_sparse_mask API."""
      if device == "cuda" and not torch.cuda.is_available():
          pytest.skip("no GPU")
  
      dense = torch.tensor([0.5000, 0.6000, 0.7000, 0.8000, 0.9000]).to(
          device
      )
      mask = random_sparse_mask(dense, 20, 0)
      assert mask.sum() == 1
      for d in [0, 1]:
          dense = torch.rand(100, 100).to(device)
          mask = random_sparse_mask(dense, 1, d)
          assert objects_are_equal(
              mask.sum(dim=d),
              torch.ones(100).to(device),
              raise_exception=True,
          )
          assert mask.sum() == 100
  
file_path: fairscale/tests/experimental/wgit/test_signal_sparsity.py
imports: import pytest
  import torch
  from fairscale.experimental.wgit.signal_sparsity import SignalSparsity, random_sparse_mask
  from fairscale.fair_dev.testing.testing import objects_are_equal
label_desc: Use image node_id 14 for calling a global function with example usage: test_random_sparse_mask(device) without return types