code: def test_inverse_residual(evoked, method, pick_ori):
      """Test MNE inverse application."""
      if method == "eLORETA" and pick_ori == "vector":  # works but slow
          return
      # use fname_inv as it will be faster than fname_full (fewer verts and chs)
      evoked = evoked.pick("meg", exclude="bads")
      if pick_ori is None:  # use fixed
          inv = read_inverse_operator(fname_inv_fixed_depth)
      else:
          inv = read_inverse_operator(fname_inv)
      fwd = read_forward_solution(fname_fwd)
      pick_channels_forward(fwd, evoked.ch_names, copy=False)
      fwd = convert_forward_solution(
          fwd, force_fixed=True, surf_ori=True
      )
  
      # make it complex to ensure we handle it properly
      evoked.data = 1j * evoked.data
      with catch_logging() as log:
          stc, residual = apply_inverse(
              evoked,
              inv,
              method=method,
              return_residual=True,
              verbose=True,
              pick_ori=pick_ori,
          )
      assert_array_equal(residual.data.real, 0)
      residual.data = (-1j * residual.data).real
      evoked.data = (-1j * evoked.data).real
      assert stc.data.min() < 0
      stc.data = -1j * stc.data
      assert_var_exp_log(log.getvalue(), 45, 52)
      if method not in ("dSPM", "sLORETA"):
          assert_stc_res(evoked, stc, fwd, residual, atol=1e-16)
  
      if method != "sLORETA":  # XXX divide by zero error
          with catch_logging() as log:
              _, residual = apply_inverse(
                  evoked,
                  inv,
                  0.0,
                  method,
                  return_residual=True,
                  verbose=True,
              )
          assert_var_exp_log(log.getvalue(), 100, 100)
          assert_array_less(np.abs(residual.data), 1e-15)
  
imports: import copy
  import re
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_array_less, assert_equal
  from scipy import sparse
  import mne
  from mne import Covariance, EvokedArray, SourceEstimate, combine_evoked, compute_raw_covariance, convert_forward_solution, make_ad_hoc_cov, make_forward_solution, make_sphere_model, pick_channels_forward, pick_types, pick_types_forward, read_cov, read_evokeds, read_forward_solution
  from mne.datasets import testing
  from mne.epochs import Epochs, EpochsArray, make_fixed_length_epochs
  from mne.event import read_events
  from mne.forward import apply_forward, is_fixed_orient, restrict_forward_to_stc
  from mne.io import read_info, read_raw_fif
  from mne.label import label_sign_flip, read_label
  from mne.minimum_norm import INVERSE_METHODS, apply_inverse, apply_inverse_cov, apply_inverse_epochs, apply_inverse_raw, apply_inverse_tfr_epochs, compute_rank_inverse, make_inverse_operator, prepare_inverse_operator, read_inverse_operator, write_inverse_operator
  from mne.source_estimate import VolSourceEstimate, read_source_estimate
  from mne.source_space._source_space import _get_src_nn
  from mne.surface import _normal_orth
  from mne.time_frequency import EpochsTFR
  from mne.utils import _record_warnings, catch_logging
label_desc: Use image node_id 18 for calling a global function with example usage: test_inverse_residual(evoked, method, pick_ori) without return types