code: def test_orient_by_streamline():
      streamlines = Streamlines(
          [
              np.array([[0, 0.0, 0], [1, 0.0, 0.0], [2, 0.0, 0.0]]),
              np.array([[2, 0.0, 0.0], [1, 0.0, 0], [0, 0, 0.0]]),
          ]
      )
  
      # If there is an affine, we'll use it:
      affine = np.eye(4)
      affine[:, 3] = [-1, 100, -20, 1]
      # Transform the streamlines:
      x_streamlines = Streamlines(
          [sl + affine[:3, 3] for sl in streamlines]
      )
  
      standard_streamline = streamlines[0]
  
      # After reorientation, this should be the answer:
      flipped_sl = Streamlines([streamlines[0], streamlines[1][::-1]])
  
      new_streamlines = orient_by_streamline(
          streamlines, standard_streamline, n_points=12, in_place=False
      )
  
      npt.assert_array_equal(new_streamlines, flipped_sl)
      npt.assert_(new_streamlines is not streamlines)
  
      # Test with affine:
      x_flipped_sl = Streamlines(
          [s + affine[:3, 3] for s in flipped_sl]
      )
      new_streamlines = orient_by_streamline(
          x_streamlines, standard_streamline, in_place=False
      )
      npt.assert_array_equal(new_streamlines, x_flipped_sl)
      npt.assert_(new_streamlines is not x_streamlines)
  
      # Test with as_generator set to True
      new_streamlines = orient_by_streamline(
          streamlines,
          standard_streamline,
          in_place=False,
          as_generator=True,
      )
  
      npt.assert_(isinstance(new_streamlines, types.GeneratorType))
      ll = Streamlines(new_streamlines)
      npt.assert_array_equal(ll, flipped_sl)
  
      # Test with as_generator set to True and with the affine
      new_streamlines = orient_by_streamline(
          x_streamlines,
          standard_streamline,
          in_place=False,
          as_generator=True,
      )
  
      npt.assert_(isinstance(new_streamlines, types.GeneratorType))
      ll = Streamlines(new_streamlines)
      npt.assert_array_equal(ll, x_flipped_sl)
  
      # Modify in-place:
      new_streamlines = orient_by_streamline(
          streamlines, standard_streamline, in_place=True
      )
  
      npt.assert_array_equal(new_streamlines, flipped_sl)
      # The two objects are one and the same:
      npt.assert_(new_streamlines is streamlines)
  
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 21 for calling a global function with example usage: test_orient_by_streamline() without return types