code: def _compare_forwards(
      fwd,
      fwd_py,
      n_sensors,
      n_src,
      meg_rtol=1e-4,
      meg_atol=1e-9,
      meg_corr_tol=0.99,
      meg_rdm_tol=0.01,
      eeg_rtol=1e-3,
      eeg_atol=1e-3,
      eeg_corr_tol=0.99,
      eeg_rdm_tol=0.01,
  ):
      """Test forwards."""
      # check source spaces
      assert len(fwd["src"]) == len(fwd_py["src"])
      _compare_source_spaces(fwd["src"], fwd_py["src"], mode="approx")
      for surf_ori, force_fixed in product(
          [False, True], [False, True]
      ):
          # use copy here to leave our originals unmodified
          fwd = convert_forward_solution(
              fwd, surf_ori, force_fixed, copy=True, use_cps=True
          )
          fwd_py = convert_forward_solution(
              fwd_py, surf_ori, force_fixed, copy=True, use_cps=True
          )
          check_src = n_src // 3 if force_fixed else n_src
  
          for key in (
              "nchan",
              "source_rr",
              "source_ori",
              "surf_ori",
              "coord_frame",
              "nsource",
          ):
              assert_allclose(
                  fwd_py[key],
                  fwd[key],
                  rtol=1e-4,
                  atol=1e-7,
                  err_msg=key,
              )
          # In surf_ori=True only Z matters for source_nn
          if surf_ori and not force_fixed:
              ori_sl = slice(2, None, 3)
          else:
              ori_sl = slice(None)
          assert_allclose(
              fwd_py["source_nn"][ori_sl],
              fwd["source_nn"][ori_sl],
              rtol=1e-4,
              atol=1e-6,
          )
          assert_allclose(
              fwd_py["mri_head_t"]["trans"],
              fwd["mri_head_t"]["trans"],
              rtol=1e-5,
              atol=1e-8,
          )
  
          assert fwd_py["sol"]["data"].shape == (n_sensors, check_src)
          assert len(fwd["sol"]["row_names"]) == n_sensors
          assert len(fwd_py["sol"]["row_names"]) == n_sensors
  
          # check MEG
          fwd_meg = fwd["sol"]["data"][:306, ori_sl]
          fwd_meg_py = fwd_py["sol"]["data"][:306, ori_sl]
          assert_allclose(
              fwd_meg,
              fwd_meg_py,
              rtol=meg_rtol,
              atol=meg_atol,
              err_msg="MEG mismatch",
          )
          meg_corrs = _col_corrs(fwd_meg, fwd_meg_py)
          assert_array_less(
              meg_corr_tol, meg_corrs, err_msg="MEG corr/MAG"
          )
          meg_rdm = _rdm(fwd_meg, fwd_meg_py)
          assert_allclose(
              meg_rdm, 1, atol=meg_rdm_tol, err_msg="MEG RDM"
          )
          # check EEG
          if fwd["sol"]["data"].shape[0] > 306:
              fwd_eeg = fwd["sol"]["data"][306:, ori_sl]
              fwd_eeg_py = fwd["sol"]["data"][306:, ori_sl]
              assert_allclose(
                  fwd_eeg,
                  fwd_eeg_py,
                  rtol=eeg_rtol,
                  atol=eeg_atol,
                  err_msg="EEG mismatch",
              )
              # To test so-called MAG we use correlation (related to cosine
              # similarity) and also RDM to test the amplitude mismatch
              eeg_corrs = _col_corrs(fwd_eeg, fwd_eeg_py)
              assert_array_less(
                  eeg_corr_tol, eeg_corrs, err_msg="EEG corr/MAG"
              )
              eeg_rdm = _rdm(fwd_eeg, fwd_eeg_py)
              assert_allclose(
                  eeg_rdm, 1, atol=eeg_rdm_tol, err_msg="EEG RDM"
              )
  
imports: from itertools import product
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_array_less
  from mne import convert_forward_solution, create_info, get_volume_labels_from_aseg, make_forward_solution, make_sphere_model, pick_info, pick_types, pick_types_forward, read_cov, read_dipole, read_evokeds, read_forward_solution, read_source_spaces, setup_volume_source_space, write_forward_solution
  from mne._fiff.constants import FIFF
  from mne.bem import make_bem_solution, read_bem_surfaces
  from mne.channels import make_standard_montage
  from mne.datasets import testing
  from mne.dipole import Dipole, fit_dipole
  from mne.forward import Forward, _do_forward_solution, use_coil_def
  from mne.forward._compute_forward import _magnetic_dipole_field_vec
  from mne.forward._make_forward import _create_meg_coils, make_forward_dipole
  from mne.forward.tests.test_forward import assert_forward_allclose
  from mne.io import read_info, read_raw_bti, read_raw_fif, read_raw_kit
  from mne.simulation import simulate_evoked
  from mne.source_estimate import VolSourceEstimate
  from mne.source_space._source_space import _compare_source_spaces, setup_source_space, write_source_spaces
  from mne.surface import _get_ico_surface
  from mne.transforms import Transform
  from mne.utils import catch_logging, requires_mne, requires_mne_mark, requires_openmeeg_mark, run_subprocess
label_desc: Use image node_id 3 for calling a global function with example usage: _compare_forwards(fwd, fwd_py, n_sensors, n_src, meg_rtol, meg_atol, meg_corr_tol, meg_rdm_tol, eeg_rtol, eeg_atol, eeg_corr_tol, eeg_rdm_tol) without return types