code: def test_val_like(val_shape, shape):
      def check_val_like(A, B):
          assert A.shape == B.shape
          assert A.nnz == B.nnz
          assert torch.allclose(
              torch.stack(A.coo()), torch.stack(B.coo())
          )
          assert A.val.device == B.val.device
  
      ctx = F.ctx()
  
      # COO
      row = torch.tensor([1, 1, 2]).to(ctx)
      col = torch.tensor([2, 4, 3]).to(ctx)
      val = torch.randn(3).to(ctx)
      coo_A = from_coo(row, col, val, shape)
      new_val = torch.randn(val_shape).to(ctx)
      coo_B = val_like(coo_A, new_val)
      check_val_like(coo_A, coo_B)
  
      # CSR
      indptr, indices, _ = coo_A.csr()
      csr_A = from_csr(indptr, indices, val, shape)
      csr_B = val_like(csr_A, new_val)
      check_val_like(csr_A, csr_B)
  
      # CSC
      indptr, indices, _ = coo_A.csc()
      csc_A = from_csc(indptr, indices, val, shape)
      csc_B = val_like(csc_A, new_val)
      check_val_like(csc_A, csc_B)
  
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 14 for calling a global function with example usage: test_val_like(val_shape, shape) without return types