code: def test_average_quats():
      """Test averaging of quaternions."""
      sq2 = 1.0 / np.sqrt(2.0)
      quats = np.array(
          [
              [0, sq2, sq2],
              [0, sq2, sq2],
              [0, sq2, 0],
              [0, 0, sq2],
              [sq2, 0, 0],
          ],
          float,
      )
      # In MATLAB:
      # quats = [[0, sq2, sq2, 0]; [0, sq2, sq2, 0];
      #          [0, sq2, 0, sq2]; [0, 0, sq2, sq2]; [sq2, 0, 0, sq2]];
      expected = [
          quats[0],
          quats[0],
          [0, 0.788675134594813, 0.577350269189626],
          [0, 0.657192299694123, 0.657192299694123],
          [0.100406058540540, 0.616329446922803, 0.616329446922803],
      ]
      # Averaging the first two should give the same thing:
      for lim, ex in enumerate(expected):
          assert_allclose(
              _average_quats(quats[: lim + 1]), ex, atol=1e-7
          )
      quats[1] *= -1  # same quaternion (hidden value is zero here)!
      rot_0, rot_1 = quat_to_rot(quats[:2])
      assert_allclose(rot_0, rot_1, atol=1e-7)
      for lim, ex in enumerate(expected):
          assert_allclose(
              _average_quats(quats[: lim + 1]), ex, atol=1e-7
          )
      # Assert some symmetry
      count = 0
      extras = [[sq2, sq2, 0]] + list(np.eye(3))
      for quat in np.concatenate((quats, expected, extras)):
          if np.isclose(
              _quat_real(quat), 0.0, atol=1e-7
          ):  # can flip sign
              count += 1
              angle = _angle_between_quats(quat, -quat)
              assert_allclose(angle, 0.0, atol=1e-7)
              rot_0, rot_1 = quat_to_rot(np.array((quat, -quat)))
              assert_allclose(rot_0, rot_1, atol=1e-7)
      assert count == 4 + len(extras)
  
imports: import itertools
  import os
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_almost_equal, assert_array_equal, assert_array_less, assert_equal
  import mne
  from mne import read_trans, write_trans
  from mne.datasets import testing
  from mne.fixes import _get_img_fdata
  from mne.io import read_info
  from mne.transforms import _angle_between_quats, _average_quats, _cart_to_sph, _compute_r2, _euler_to_quat, _find_trans, _find_vector_rotation, _fit_matched_points, _get_trans, _MatchedDisplacementFieldInterpolator, _pol_to_cart, _quat_real, _quat_to_affine, _quat_to_euler, _read_fs_xfm, _sph_to_cart, _topo_to_sph, _validate_pipeline, _write_fs_xfm, apply_trans, combine_transforms, get_ras_to_neuromag_trans, invert_transform, quat_to_rot, rot_to_quat, rotation, rotation3d, rotation3d_align_z_axis, rotation_angles, translation
  from mne.transforms import _SphericalSurfaceWarp
label_desc: Use image node_id 17 for calling a global function with example usage: test_average_quats() without return types