code: def test_mxne_inverse_standard(forward):
      """Test (TF-)MxNE inverse computation."""
      # Read noise covariance matrix
      cov = read_cov(fname_cov)
  
      # Handling average file
      loose = 0.0
      depth = 0.9
  
      evoked = read_evokeds(fname_data, condition=0, baseline=(None, 0))
      evoked.crop(tmin=-0.05, tmax=0.2)
  
      evoked_l21 = evoked.copy()
      evoked_l21.crop(tmin=0.081, tmax=0.1)
      label = read_label(fname_label)
      assert label.hemi == "rh"
  
      forward = convert_forward_solution(forward, surf_ori=True)
  
      # Reduce source space to make test computation faster
      inverse_operator = make_inverse_operator(
          evoked_l21.info,
          forward,
          cov,
          loose=loose,
          depth=depth,
          fixed=True,
          use_cps=True,
      )
      stc_dspm = apply_inverse(
          evoked_l21, inverse_operator, lambda2=1.0 / 9.0, method="dSPM"
      )
      stc_dspm.data[np.abs(stc_dspm.data) < 12] = 0.0
      stc_dspm.data[np.abs(stc_dspm.data) >= 12] = 1.0
      weights_min = 0.5
  
      # MxNE tests
      alpha = 70  # spatial regularization parameter
  
      with _record_warnings():  # CD
          stc_cd = mixed_norm(
              evoked_l21,
              forward,
              cov,
              alpha,
              loose=loose,
              depth=depth,
              maxit=300,
              tol=1e-8,
              active_set_size=10,
              weights=stc_dspm,
              weights_min=weights_min,
              solver="cd",
          )
      stc_bcd = mixed_norm(
          evoked_l21,
          forward,
          cov,
          alpha,
          loose=loose,
          depth=depth,
          maxit=300,
          tol=1e-8,
          active_set_size=10,
          weights=stc_dspm,
          weights_min=weights_min,
          solver="bcd",
      )
      assert_array_almost_equal(stc_cd.times, evoked_l21.times, 5)
      assert_array_almost_equal(stc_bcd.times, evoked_l21.times, 5)
      assert_allclose(stc_cd.data, stc_bcd.data, rtol=1e-3, atol=0.0)
      assert stc_cd.vertices[1][0] in label.vertices
      assert stc_bcd.vertices[1][0] in label.vertices
  
      # vector
      with _record_warnings():  # no convergence
          stc = mixed_norm(
              evoked_l21, forward, cov, alpha, loose=1, maxit=2
          )
      with _record_warnings():  # no convergence
          stc_vec = mixed_norm(
              evoked_l21,
              forward,
              cov,
              alpha,
              loose=1,
              maxit=2,
              pick_ori="vector",
          )
      assert_stcs_equal(stc_vec.magnitude(), stc)
      with _record_warnings(), pytest.raises(
          ValueError, match="pick_ori="
      ):
          mixed_norm(
              evoked_l21,
              forward,
              cov,
              alpha,
              loose=0,
              maxit=2,
              pick_ori="vector",
          )
  
      with _record_warnings(), catch_logging() as log:  # CD
          dips = mixed_norm(
              evoked_l21,
              forward,
              cov,
              alpha,
              loose=loose,
              depth=depth,
              maxit=300,
              tol=1e-8,
              active_set_size=10,
              weights=stc_dspm,
              weights_min=weights_min,
              solver="cd",
              return_as_dipoles=True,
              verbose=True,
          )
      stc_dip = make_stc_from_dipoles(dips, forward["src"])
      assert isinstance(dips[0], Dipole)
      assert stc_dip.subject == "sample"
      assert_stcs_equal(stc_cd, stc_dip)
      assert_var_exp_log(log.getvalue(), 51, 53)  # 51.8
  
      # Single time point things should match
      with _record_warnings(), catch_logging() as log:
          dips = mixed_norm(
              evoked_l21.copy().crop(0.081, 0.081),
              forward,
              cov,
              alpha,
              loose=loose,
              depth=depth,
              maxit=300,
              tol=1e-8,
              active_set_size=10,
              weights=stc_dspm,
              weights_min=weights_min,
              solver="cd",
              return_as_dipoles=True,
              verbose=True,
          )
      assert_var_exp_log(log.getvalue(), 37.8, 38.0)  # 37.9
      gof = sum(
          dip.gof[0] for dip in dips
      )  # these are now partial exp vars
      assert_allclose(gof, 37.9, atol=0.1)
  
      with _record_warnings(), catch_logging() as log:
          stc, res = mixed_norm(
              evoked_l21,
              forward,
              cov,
              alpha,
              loose=loose,
              depth=depth,
              maxit=300,
              tol=1e-8,
              weights=stc_dspm,  # gh-6382
              active_set_size=10,
              return_residual=True,
              solver="cd",
              verbose=True,
          )
      assert_array_almost_equal(stc.times, evoked_l21.times, 5)
      assert stc.vertices[1][0] in label.vertices
      assert_var_exp_log(log.getvalue(), 51, 53)  # 51.8
      assert stc.data.min() < -1e-9  # signed
      assert_stc_res(evoked_l21, stc, forward, res)
  
      # irMxNE tests
      with _record_warnings(), catch_logging() as log:  # CD
          stc, residual = mixed_norm(
              evoked_l21,
              forward,
              cov,
              alpha,
              n_mxne_iter=5,
              loose=0.0001,
              depth=depth,
              maxit=300,
              tol=1e-8,
              active_set_size=10,
              solver="cd",
              return_residual=True,
              pick_ori="vector",
              verbose=True,
          )
      assert_array_almost_equal(stc.times, evoked_l21.times, 5)
      assert stc.vertices[1][0] in label.vertices
      assert stc.vertices == [[63152], [79017]]
      assert_var_exp_log(log.getvalue(), 51, 53)  # 51.8
      assert_stc_res(evoked_l21, stc, forward, residual)
  
      # Do with TF-MxNE for test memory savings
      alpha = 60.0  # overall regularization parameter
      l1_ratio = 0.01  # temporal regularization proportion
  
      stc, _ = tf_mixed_norm(
          evoked,
          forward,
          cov,
          loose=loose,
          depth=depth,
          maxit=100,
          tol=1e-4,
          tstep=4,
          wsize=16,
          window=0.1,
          weights=stc_dspm,
          weights_min=weights_min,
          return_residual=True,
          alpha=alpha,
          l1_ratio=l1_ratio,
      )
      assert_array_almost_equal(stc.times, evoked.times, 5)
      assert stc.vertices[1][0] in label.vertices
  
      # vector
      stc_nrm = tf_mixed_norm(
          evoked,
          forward,
          cov,
          loose=1,
          depth=depth,
          maxit=2,
          tol=1e-4,
          tstep=4,
          wsize=16,
          window=0.1,
          weights=stc_dspm,
          weights_min=weights_min,
          alpha=alpha,
          l1_ratio=l1_ratio,
      )
      stc_vec, residual = tf_mixed_norm(
          evoked,
          forward,
          cov,
          loose=1,
          depth=depth,
          maxit=2,
          tol=1e-4,
          tstep=4,
          wsize=16,
          window=0.1,
          weights=stc_dspm,
          weights_min=weights_min,
          alpha=alpha,
          l1_ratio=l1_ratio,
          pick_ori="vector",
          return_residual=True,
      )
      assert_stcs_equal(stc_vec.magnitude(), stc_nrm)
  
      pytest.raises(
          ValueError,
          tf_mixed_norm,
          evoked,
          forward,
          cov,
          alpha=101,
          l1_ratio=0.03,
      )
      pytest.raises(
          ValueError,
          tf_mixed_norm,
          evoked,
          forward,
          cov,
          alpha=50.0,
          l1_ratio=1.01,
      )
  
imports: import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_array_less
  import mne
  from mne import convert_forward_solution, read_cov, read_evokeds, read_forward_solution
  from mne.datasets import testing
  from mne.dipole import Dipole
  from mne.inverse_sparse import mixed_norm, tf_mixed_norm
  from mne.inverse_sparse.mxne_inverse import _compute_mxne_sure, _split_gof, make_stc_from_dipoles
  from mne.inverse_sparse.mxne_optim import norm_l2inf
  from mne.label import read_label
  from mne.minimum_norm import apply_inverse, make_inverse_operator
  from mne.minimum_norm.tests.test_inverse import assert_stc_res, assert_var_exp_log
  from mne.simulation import simulate_evoked, simulate_sparse_stc
  from mne.source_estimate import VolSourceEstimate
  from mne.utils import _record_warnings, assert_stcs_equal, catch_logging
label_desc: Use image node_id 2 for calling a global function with example usage: test_mxne_inverse_standard(forward) without return types