code: def test_quickbundles_with_python_metric():
      class MDFpy(dipysmetric.Metric):
          def are_compatible(self, shape1, shape2):
              return shape1 == shape2
  
          def dist(self, features1, features2):
              dist = np.sqrt(
                  np.sum((features1 - features2) ** 2, axis=1)
              )
              dist = np.sum(dist / len(features1))
              return dist
  
      rdata = streamline_utils.set_number_of_points(data, 10)
      qb = QuickBundles(threshold=2 * threshold, metric=MDFpy())
  
      clusters = qb.cluster(rdata)
  
      # By default `refdata` refers to data being clustered.
      assert_equal(clusters.refdata, rdata)
      # Set `refdata` to return indices instead of actual data points.
      clusters.refdata = None
      assert_array_equal(
          list(itertools.chain(*clusters)),
          list(itertools.chain(*clusters_truth)),
      )
  
      # Cluster read-only data
      for datum in rdata:
          datum.setflags(write=False)
  
      # Cluster data with different dtype (should be converted into float32)
      for datatype in [np.float64, np.int32, np.int64]:
          newdata = [datum.astype(datatype) for datum in rdata]
          clusters = qb.cluster(newdata)
          assert_equal(clusters.centroids[0].dtype, np.float32)
  
file_path: dipy/dipy/segment/tests/test_quickbundles.py
imports: import numpy
  import itertools
  from numpy.testing import assert_array_equal, assert_equal, assert_raises
  from dipy.testing.memory import get_type_refcount
  from dipy.testing import assert_arrays_equal
  from dipy.segment.clustering import QuickBundles
  import dipy.segment.featurespeed
  import dipy.segment.metricspeed
  from dipy.segment.clustering_algorithms import quickbundles
  import dipy.tracking.streamline
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 6 for calling a global function with example usage: test_quickbundles_with_python_metric() and returns: unknown, dist