code: def test_grad_metrics_match_metrics(spatial_data, spatial_distances):
      for metric in dist.named_distances_with_gradients:
          if metric in spatial_distances:
              spatial_check(
                  metric,
                  spatial_data,
                  spatial_distances,
                  with_grad=True,
              )
  
      # Handle the few special distances separately
      # SEuclidean
      v = np.abs(np.random.randn(spatial_data.shape[1]))
      dist_matrix = pairwise_distances(
          spatial_data, metric="seuclidean", V=v
      )
      test_matrix = np.array(
          [
              [
                  dist.standardised_euclidean_grad(
                      spatial_data[i], spatial_data[j], v
                  )[0]
                  for j in range(spatial_data.shape[0])
              ]
              for i in range(spatial_data.shape[0])
          ]
      )
      assert_array_almost_equal(
          test_matrix,
          dist_matrix,
          err_msg="Distances don't match " "for metric seuclidean",
      )
  
      if scipy_full_version >= (1, 8):
          # Weighted minkowski
          dist_matrix = pairwise_distances(
              spatial_data, metric="minkowski", w=v, p=3
          )
          test_matrix = np.array(
              [
                  [
                      dist.weighted_minkowski_grad(
                          spatial_data[i], spatial_data[j], v, p=3
                      )[0]
                      for j in range(spatial_data.shape[0])
                  ]
                  for i in range(spatial_data.shape[0])
              ]
          )
          assert_array_almost_equal(
              test_matrix,
              dist_matrix,
              err_msg="Distances don't match "
              "for metric weighted_minkowski",
          )
  
      # Mahalanobis
      v = np.abs(
          np.random.randn(spatial_data.shape[1], spatial_data.shape[1])
      )
      dist_matrix = pairwise_distances(
          spatial_data, metric="mahalanobis", VI=v
      )
      test_matrix = np.array(
          [
              [
                  dist.mahalanobis_grad(
                      spatial_data[i], spatial_data[j], v
                  )[0]
                  for j in range(spatial_data.shape[0])
              ]
              for i in range(spatial_data.shape[0])
          ]
      )
      assert_array_almost_equal(
          test_matrix,
          dist_matrix,
          decimal=5,
          err_msg="Distances don't match " "for metric mahalanobis",
      )
  
      # Hellinger
      dist_matrix = dist.pairwise_special_metric(
          np.abs(spatial_data[:-2]), np.abs(spatial_data[:-2])
      )
      test_matrix = np.array(
          [
              [
                  dist.hellinger_grad(
                      np.abs(spatial_data[i]), np.abs(spatial_data[j])
                  )[0]
                  for j in range(spatial_data.shape[0] - 2)
              ]
              for i in range(spatial_data.shape[0] - 2)
          ]
      )
      assert_array_almost_equal(
          test_matrix,
          dist_matrix,
          err_msg="Distances don't match " "for metric hellinger",
      )
  
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 48 for calling a global function with example usage: test_grad_metrics_match_metrics(spatial_data, spatial_distances) without return types