code: def test_sparse_spatial_check(sparse_spatial_data, metric, decimal=6):
      if metric in spdist.sparse_named_distances:
          dist_matrix = pairwise_distances(
              np.asarray(sparse_spatial_data.todense()).astype(
                  np.float32
              ),
              metric=metric,
          )
      if metric in ("braycurtis", "dice", "sokalsneath", "yule"):
          dist_matrix[np.where(~np.isfinite(dist_matrix))] = 0.0
      if metric in ("cosine", "correlation", "russellrao"):
          dist_matrix[np.where(~np.isfinite(dist_matrix))] = 1.0
          # And because distance between all zero vectors should be zero
          dist_matrix[10, 11] = 0.0
          dist_matrix[11, 10] = 0.0
  
      dist_function = spdist.sparse_named_distances[metric]
      if metric in spdist.sparse_need_n_features:
          test_matrix = np.array(
              [
                  [
                      dist_function(
                          sparse_spatial_data[i].indices,
                          sparse_spatial_data[i].data,
                          sparse_spatial_data[j].indices,
                          sparse_spatial_data[j].data,
                          sparse_spatial_data.shape[1],
                      )
                      for j in range(sparse_spatial_data.shape[0])
                  ]
                  for i in range(sparse_spatial_data.shape[0])
              ]
          )
      else:
          test_matrix = np.array(
              [
                  [
                      dist_function(
                          sparse_spatial_data[i].indices,
                          sparse_spatial_data[i].data,
                          sparse_spatial_data[j].indices,
                          sparse_spatial_data[j].data,
                      )
                      for j in range(sparse_spatial_data.shape[0])
                  ]
                  for i in range(sparse_spatial_data.shape[0])
              ]
          )
      assert_array_almost_equal(
          test_matrix,
          dist_matrix,
          err_msg="Sparse distances don't match for metric {}".format(
              metric
          ),
          decimal=decimal,
      )
  
imports: import pytest
  import numpy
  from numpy.testing import assert_array_equal, assert_array_almost_equal
  import pynndescent.distances
  import pynndescent.sparse
  from scipy import stats
  from scipy.sparse import csr_matrix
  from scipy.version import full_version
  from sklearn.metrics import pairwise_distances
  from sklearn.neighbors import BallTree
  from sklearn.preprocessing import normalize
label_desc: Use image node_id 3 for calling a global function with example usage: test_sparse_spatial_check(sparse_spatial_data, metric, decimal) without return types