code: def run_test_metric(metric, test_data, dist_matrix, with_grad=False):
      """Core utility function to test target metric on test data"""
      if with_grad:
          dist_function = dist.named_distances_with_gradients[metric]
      else:
          dist_function = dist.named_distances[metric]
      sample_size = test_data.shape[0]
      test_matrix = [
          [
              dist_function(test_data[i], test_data[j])
              for j in range(sample_size)
          ]
          for i in range(sample_size)
      ]
      if with_grad:
          test_matrix = [
              d for pairs in test_matrix for d, grad in pairs
          ]
  
      test_matrix = np.array(test_matrix).reshape(
          sample_size, sample_size
      )
  
      assert_array_almost_equal(
          test_matrix,
          dist_matrix,
          err_msg="Distances don't match "
          "for metric {}".format(metric),
      )
  
imports: import numpy
  from numpy.testing import assert_array_almost_equal
  import umap.distances
  import umap.sparse
  from sklearn.metrics import pairwise_distances
  from sklearn.neighbors import BallTree
  from scipy.version import full_version
  import pytest
label_desc: Use image node_id 1 for calling a global function with example usage: run_test_metric(metric, test_data, dist_matrix, with_grad) without return types