code: def test_quickbundles_2D(rng):
      # Test quickbundles clustering using 2D points and the Eulidean metric.
      data = []
      data += [
          rng.standard_normal((1, 2)) + np.array([0, 0])
          for _ in range(1)
      ]
      data += [
          rng.standard_normal((1, 2)) + np.array([10, 10])
          for _ in range(2)
      ]
      data += [
          rng.standard_normal((1, 2)) + np.array([-10, 10])
          for _ in range(3)
      ]
      data += [
          rng.standard_normal((1, 2)) + np.array([10, -10])
          for _ in range(4)
      ]
      data += [
          rng.standard_normal((1, 2)) + np.array([-10, -10])
          for _ in range(5)
      ]
      data = np.array(data, dtype=dtype)
  
      clusters_truth = [
          [0],
          [1, 2],
          [3, 4, 5],
          [6, 7, 8, 9],
          [10, 11, 12, 13, 14],
      ]
  
      # # Uncomment the following to visualize this test
      # import pylab as plt
      # plt.plot(*zip(*data[0:1, 0]), linestyle='None', marker='s')
      # plt.plot(*zip(*data[1:3, 0]), linestyle='None', marker='o')
      # plt.plot(*zip(*data[3:6, 0]), linestyle='None', marker='+')
      # plt.plot(*zip(*data[6:10, 0]), linestyle='None', marker='.')
      # plt.plot(*zip(*data[10:, 0]), linestyle='None', marker='*')
      # plt.show()
  
      # Theoretically, using a threshold above the following value will not
      # produce expected results.
      threshold = np.sqrt(2 * (10**2)) - np.sqrt(2)
      metric = dipysmetric.SumPointwiseEuclideanMetric()
      ordering = np.arange(len(data))
      for i in range(100):
          rng.shuffle(ordering)
          clusters = quickbundles(
              data, metric, threshold, ordering=ordering
          )
  
          # Check if clusters are the same as 'clusters_truth'
          for cluster in clusters:
              # Find the corresponding cluster in 'clusters_truth'
              for cluster_truth in clusters_truth:
                  if cluster_truth[0] in cluster.indices:
                      assert_equal(
                          sorted(cluster.indices), sorted(cluster_truth)
                      )
  
      # Cluster each cluster again using a small threshold
      for cluster in clusters:
          subclusters = quickbundles(
              data, metric, threshold=0, ordering=cluster.indices
          )
          assert_equal(len(subclusters), len(cluster))
          assert_equal(
              sorted(itertools.chain(*subclusters)),
              sorted(cluster.indices),
          )
  
      # A very large threshold should produce only 1 cluster
      clusters = quickbundles(data, metric, threshold=np.inf)
      assert_equal(len(clusters), 1)
      assert_equal(len(clusters[0]), len(data))
      assert_array_equal(clusters[0].indices, range(len(data)))
  
      # A very small threshold should produce only N clusters where N=len(data)
      clusters = quickbundles(data, metric, threshold=0)
      assert_equal(len(clusters), len(data))
      assert_array_equal(list(map(len, clusters)), np.ones(len(data)))
      assert_array_equal(
          [idx for cluster in clusters for idx in cluster.indices],
          range(len(data)),
      )
  
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 4 for calling a global function with example usage: test_quickbundles_2D(rng) without return types