code: def test_compress_streamlines():
      for compress_func in [
          compress_streamlines_python,
          compress_streamlines,
      ]:
          # Small streamlines (less than two points) are incompressible.
          for small_streamline in [
              np.array([[]]),
              np.array([[1, 1, 1]]),
              np.array([[1, 1, 1], [2, 2, 2]]),
          ]:
              c_streamline = compress_func(small_streamline)
              assert_equal(len(c_streamline), len(small_streamline))
              assert_array_equal(c_streamline, small_streamline)
  
          # Compressing a straight streamline that is less than 10mm long
          # should output a two points streamline.
          linear_streamline = np.linspace(0, 5, 100 * 3).reshape(
              (100, 3)
          )
          c_streamline = compress_func(linear_streamline)
          assert_equal(len(c_streamline), 2)
          assert_array_equal(
              c_streamline,
              [linear_streamline[0], linear_streamline[-1]],
          )
  
          # The distance of consecutive points must be less or equal than some
          # value.
          max_segment_length = 10
          linear_streamline = np.linspace(0, 100, 100 * 3).reshape(
              (100, 3)
          )
          linear_streamline[:, 1:] = 0.0
          c_streamline = compress_func(
              linear_streamline, max_segment_length=max_segment_length
          )
          segments_length = np.sqrt(
              (np.diff(c_streamline, axis=0) ** 2).sum(axis=1)
          )
          assert_true(np.all(segments_length <= max_segment_length))
          assert_equal(len(c_streamline), 12)
          assert_array_equal(c_streamline, linear_streamline[::9])
  
          # A small `max_segment_length` should keep all points.
          c_streamline = compress_func(
              linear_streamline, max_segment_length=0.01
          )
          assert_array_equal(c_streamline, linear_streamline)
  
          # Test we can set `max_segment_length` to infinity
          # (like the C++ version)
          compress_func(streamline, max_segment_length=np.inf)
  
          # Incompressible streamline when `tol_error` == 1.
          simple_streamline = np.array(
              [
                  [0, 0, 0],
                  [1, 1, 0],
                  [1.5, np.inf, 0],
                  [2, 2, 0],
                  [2.5, 20, 0],
                  [3, 3, 0],
              ]
          )
  
          # Because of np.inf, compressing that streamline causes a warning.
          with np.errstate(invalid="ignore"):
              c_streamline = compress_func(
                  simple_streamline, tol_error=1
              )
              assert_array_equal(c_streamline, simple_streamline)
  
      # Create a special streamline where every other point is increasingly
      # farther from a straight line formed by the streamline endpoints.
      tol_errors = np.linspace(0, 10, 21)
      orthogonal_line = np.array(
          [[-np.sqrt(2) / 2, np.sqrt(2) / 2, 0]], dtype=np.float32
      )
      special_streamline = np.array(
          [range(len(tol_errors) * 2 + 1)] * 3, dtype=np.float32
      ).T
      special_streamline[1::2] += orthogonal_line * tol_errors[:, None]
  
      # # Uncomment to see the streamline.
      # import pylab as plt
      # plt.plot(special_streamline[:, 0], special_streamline[:, 1], '.-')
      # plt.axis('equal'); plt.show()
  
      # Test different values for `tol_error`.
      for i, tol_error in enumerate(tol_errors):
          cspecial_streamline = compress_streamlines(
              special_streamline,
              tol_error=tol_error + 1e-4,
              max_segment_length=np.inf,
          )
  
          # First and last points should always be the same as the original ones.
          assert_array_equal(
              cspecial_streamline[0], special_streamline[0]
          )
          assert_array_equal(
              cspecial_streamline[-1], special_streamline[-1]
          )
  
          assert_equal(
              len(cspecial_streamline),
              len(special_streamline) - ((i * 2) + 1),
          )
  
          # Make sure Cython and Python versions are the same.
          cstreamline_python = compress_streamlines_python(
              special_streamline,
              tol_error=tol_error + 1e-4,
              max_segment_length=np.inf,
          )
          assert_equal(
              len(cspecial_streamline), len(cstreamline_python)
          )
          assert_array_almost_equal(
              cspecial_streamline, cstreamline_python
          )
  
imports: import warnings
  import types
  import numpy
  from numpy.linalg import norm
  import numpy.testing
  from dipy.testing.memory import get_type_refcount
  from dipy.testing import assert_arrays_equal
  from dipy.testing.decorators import set_random_number_generator
  from dipy.testing import assert_true
  from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_raises, assert_allclose, assert_almost_equal, assert_equal
  from dipy.tracking.streamlinespeed import compress_streamlines, length, set_number_of_points
  from dipy.tracking.streamline import Streamlines
  from dipy.tracking.streamline import relist_streamlines, unlist_streamlines, center_streamlines, transform_streamlines, select_random_set_of_streamlines, select_by_rois, orient_by_rois, orient_by_streamline, values_from_volume, deform_streamlines, cluster_confidence
label_desc: Use image node_id 15 for calling a global function with example usage: test_compress_streamlines() without return types