code: def test_sample_columnwise(create_func, index, replace, bias):
      ctx = F.ctx()
      shape = (5, 5)
      sample_dim = 1
      sample_num = 3
      A = create_func(shape, 10, ctx)
      A = val_like(A, torch.abs(A.val))
  
      index = torch.tensor(index).to(ctx)
  
      A_sample = A.sample(sample_dim, sample_num, index, replace, bias)
      A_dense = sparse_matrix_to_dense(A)
      A_sample_to_dense = sparse_matrix_to_dense(A_sample)
  
      ans_shape = (shape[0], index.size(0))
      # Verify sample elements in origin columns
      for i, col in enumerate(list(index)):
          ans_ele = list(A_dense[:, col].nonzero().reshape(-1))
          ret_ele = list(A_sample_to_dense[:, i].nonzero().reshape(-1))
          for e in ret_ele:
              assert e in ans_ele
          if replace:
              # The number of sample elements in one column should be equal to
              # 'sample_num' if the column is not empty otherwise should be
              # equal to 0.
              assert list(A_sample.col).count(torch.tensor(i)) == (
                  sample_num if len(ans_ele) != 0 else 0
              )
          else:
              assert len(ret_ele) == min(sample_num, len(ans_ele))
  
      assert A_sample.shape == ans_shape
      if not replace:
          assert not A_sample.has_duplicate()
  
imports: import unittest
  import warnings
  import backend
  import pytest
  import torch
  from dgl.sparse import diag, from_coo, from_csc, from_csr, from_torch_sparse, identity, to_torch_sparse_coo, to_torch_sparse_csc, to_torch_sparse_csr, val_like
  from .utils import rand_coo, rand_csc, rand_csr, rand_diag, sparse_matrix_to_dense
label_desc: Use image node_id 20 for calling a global function with example usage: test_sample_columnwise(create_func, index, replace, bias) without return types