code: def test_reorient_random_vector_fields(rng):
      # Test reorienting vector field
      for n_dims, func in (
          (2, vfu.reorient_vector_field_2d),
          (3, vfu.reorient_vector_field_3d),
      ):
          size = [20, 30, 40][:n_dims] + [n_dims]
          arr = rng.normal(size=size)
          arr_32 = arr.astype(floating)
          affine = from_matvec(
              rng.normal(size=(n_dims, n_dims)), np.zeros(n_dims)
          )
          func(arr_32, affine)
          assert_almost_equal(arr_32, apply_affine(affine, arr), 6)
          # Reorient reorients without translation
          trans = np.arange(n_dims) + 2
          affine[:-1, -1] = trans
          arr_32 = arr.astype(floating)
          func(arr_32, affine)
          assert_almost_equal(
              arr_32, apply_affine(affine, arr) - trans, 6
          )
  
          # Test exception is raised when the affine transform is not valid
          invalid = np.eye(n_dims)
          assert_raises(ValueError, func, arr_32, invalid)
  
imports: import numpy
  from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_almost_equal, assert_equal, assert_raises
  from scipy.ndimage import map_coordinates
  from nibabel.affines import apply_affine, from_matvec
  from dipy.core import geometry
  from dipy.align import floating
  from dipy.align import imwarp
  from dipy.align import vector_fields
  from dipy.align.transforms import regtransforms
  from dipy.align.parzenhist import sample_domain_regular
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 23 for calling a global function with example usage: test_reorient_random_vector_fields(rng) without return types