code: def _check_fit_matched_points(
      p, x, weights, do_scale, angtol=1e-5, dtol=1e-5, stol=1e-7
  ):
      __tracebackhide__ = True
      mne.coreg._ALLOW_ANALITICAL = False
      try:
          params = mne.coreg.fit_matched_points(
              p, x, weights=weights, scale=do_scale, out="params"
          )
      finally:
          mne.coreg._ALLOW_ANALITICAL = True
      quat_an, scale_an = _fit_matched_points(
          p, x, weights, scale=do_scale
      )
      assert len(params) == 6 + int(do_scale)
      q_co = _euler_to_quat(params[:3])
      translate_co = params[3:6]
      angle = np.rad2deg(_angle_between_quats(quat_an[:3], q_co))
      dist = np.linalg.norm(quat_an[3:] - translate_co)
      assert 0 <= angle < angtol, "angle"
      assert 0 <= dist < dtol, "dist"
      if do_scale:
          scale_co = params[6]
          assert_allclose(
              scale_an, scale_co, rtol=stol, err_msg="scale"
          )
      # errs
      trans = _quat_to_affine(quat_an)
      trans[:3, :3] *= scale_an
      weights = np.ones(1) if weights is None else weights
      err_an = np.linalg.norm(
          weights[:, np.newaxis] * apply_trans(trans, p) - x
      )
      trans = mne.coreg._trans_from_params(
          (True, True, do_scale), params
      )
      err_co = np.linalg.norm(
          weights[:, np.newaxis] * apply_trans(trans, p) - x
      )
      if err_an > 1e-14:
          assert err_an < err_co * 1.5
      return quat_an, scale_an
  
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 20 for calling a global function with example usage: _check_fit_matched_points(p, x, weights, do_scale, angtol, dtol, stol) and returns: quat_an,  scale_an