code: def test_distance_matrix(rng):
      metric = dipysmetric.SumPointwiseEuclideanMetric()
  
      for dtype in [np.int32, np.int64, np.float32, np.float64]:
          # Compute distances of all tuples spawn by the Cartesian product
          # of `data` with itself.
          data = (rng.random((4, 10, 3)) * 10).astype(dtype)
          D = dipysmetric.distance_matrix(metric, data)
          assert_equal(D.shape, (len(data), len(data)))
          assert_array_equal(np.diag(D), np.zeros(len(data)))
  
          if metric.is_order_invariant:
              # Distance matrix should be symmetric
              assert_array_equal(D, D.T)
  
          for i in range(len(data)):
              for j in range(len(data)):
                  assert_equal(
                      D[i, j],
                      dipysmetric.dist(metric, data[i], data[j]),
                  )
  
          # Compute distances of all tuples spawn by the Cartesian product
          # of `data` with `data2`.
          data2 = (rng.random((3, 10, 3)) * 10).astype(dtype)
          D = dipysmetric.distance_matrix(metric, data, data2)
          assert_equal(D.shape, (len(data), len(data2)))
  
          for i in range(len(data)):
              for j in range(len(data2)):
                  assert_equal(
                      D[i, j],
                      dipysmetric.dist(metric, data[i], data2[j]),
                  )
  
file_path: dipy/dipy/segment/tests/test_metric.py
imports: import itertools
  import numpy
  from numpy.testing import assert_array_equal, assert_raises, assert_almost_equal, assert_equal
  import dipy.segment.featurespeed
  import dipy.segment.metric
  import dipy.segment.metricspeed
  from dipy.testing import assert_true, assert_false, assert_greater_equal, assert_less_equal
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 5 for calling a global function with example usage: test_distance_matrix(rng) without return types