code: def test_lcmv_vector():
      """Test vector LCMV solutions."""
      info = mne.io.read_raw_fif(fname_raw).info
  
      # For speed and for rank-deficiency calculation simplicity,
      # just use grads
      info = mne.pick_info(
          info, mne.pick_types(info, meg="grad", exclude=())
      )
      with info._unlock():
          info.update(bads=[], projs=[])
  
      forward = mne.read_forward_solution(fname_fwd)
      forward = mne.pick_channels_forward(forward, info["ch_names"])
      vertices = [s["vertno"][::200] for s in forward["src"]]
      n_vertices = sum(len(v) for v in vertices)
      assert n_vertices == 4
  
      amplitude = 100e-9
      stc = mne.SourceEstimate(
          amplitude * np.eye(n_vertices),
          vertices,
          0,
          1.0 / info["sfreq"],
      )
      forward_sim = mne.convert_forward_solution(
          forward, force_fixed=True, use_cps=True, copy=True
      )
      forward_sim = mne.forward.restrict_forward_to_stc(
          forward_sim, stc
      )
      noise_cov = mne.make_ad_hoc_cov(info)
      noise_cov.update(data=np.diag(noise_cov["data"]), diag=False)
      evoked = simulate_evoked(
          forward_sim, stc, info, noise_cov, nave=1
      )
      source_nn = forward_sim["source_nn"]
      source_rr = forward_sim["source_rr"]
  
      # Figure out our indices
      mask = np.concatenate(
          [
              np.isin(s["vertno"], v)
              for s, v in zip(forward["src"], vertices)
          ]
      )
      mapping = np.where(mask)[0]
      assert_array_equal(source_rr, forward["source_rr"][mapping])
  
      # Don't check NN because we didn't rotate to surf ori
      del forward_sim
  
      # Let's do minimum norm as a sanity check (dipole_fit is slower)
      inv = make_inverse_operator(info, forward, noise_cov, loose=1.0)
      stc_vector_mne = apply_inverse(evoked, inv, pick_ori="vector")
      mne_ori = stc_vector_mne.data[mapping, :, np.arange(n_vertices)]
      mne_ori /= np.linalg.norm(mne_ori, axis=-1)[:, np.newaxis]
      mne_angles = np.rad2deg(
          np.arccos(np.sum(mne_ori * source_nn, axis=-1))
      )
      assert np.mean(mne_angles) < 35
  
      # Now let's do LCMV
      data_cov = mne.make_ad_hoc_cov(info)  # just a stub for later
      with pytest.raises(ValueError, match="pick_ori"):
          make_lcmv(
              info, forward, data_cov, 0.05, noise_cov, pick_ori="bad"
          )
  
      lcmv_ori = list()
      for ti in range(n_vertices):
          this_evoked = evoked.copy().crop(
              evoked.times[ti], evoked.times[ti]
          )
          data_cov["diag"] = False
          data_cov["data"] = (
              np.outer(this_evoked.data, this_evoked.data)
              + noise_cov["data"]
          )
          vals = linalg.svdvals(data_cov["data"])
          assert vals[0] / vals[-1] < 1e5  # not rank deficient
  
          with catch_logging() as log:
              filters = make_lcmv(
                  info, forward, data_cov, 0.05, noise_cov, verbose=True
              )
          log = log.getvalue()
          assert "498 sources" in log
          with catch_logging() as log:
              filters_vector = make_lcmv(
                  info,
                  forward,
                  data_cov,
                  0.05,
                  noise_cov,
                  pick_ori="vector",
                  verbose=True,
              )
          log = log.getvalue()
          assert "498 sources" in log
          stc = apply_lcmv(this_evoked, filters)
          stc_vector = apply_lcmv(this_evoked, filters_vector)
          assert isinstance(stc, mne.SourceEstimate)
          assert isinstance(stc_vector, mne.VectorSourceEstimate)
          assert_allclose(stc.data, stc_vector.magnitude().data)
  
          # Check the orientation by pooling across some neighbors, as LCMV can
          # have some "holes" at the points of interest
          idx = np.where(
              cdist(forward["source_rr"], source_rr[[ti]]) < 0.02
          )[0]
          lcmv_ori.append(np.mean(stc_vector.data[idx, :, 0], axis=0))
          lcmv_ori[-1] /= np.linalg.norm(lcmv_ori[-1])
  
      lcmv_angles = np.rad2deg(
          np.arccos(np.sum(lcmv_ori * source_nn, axis=-1))
      )
      assert np.mean(lcmv_angles) < 55
  
imports: from contextlib import nullcontext
  from copy import deepcopy
  from inspect import signature
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_array_less
  from scipy import linalg
  from scipy.spatial.distance import cdist
  import mne
  from mne import EvokedArray, VolSourceEstimate, VolVectorSourceEstimate, compute_rank, convert_forward_solution, pick_channels_cov, read_forward_solution, read_vectorview_selection
  from mne._fiff.compensator import set_current_comp
  from mne._fiff.constants import FIFF
  from mne.beamformer import Beamformer, apply_lcmv, apply_lcmv_cov, apply_lcmv_epochs, apply_lcmv_raw, make_dics, make_lcmv, read_beamformer
  from mne.beamformer._compute_beamformer import _prepare_beamformer_input
  from mne.datasets import testing
  from mne.minimum_norm import apply_inverse, make_inverse_operator
  from mne.minimum_norm.tests.test_inverse import _assert_free_ori_match
  from mne.simulation import simulate_evoked
  from mne.transforms import apply_trans, invert_transform
  from mne.utils import _record_warnings, catch_logging, object_diff
label_desc: Use image node_id 3 for calling a global function with example usage: test_lcmv_vector() without return types