code: def _to_forward_dict(
      fwd,
      names,
      fwd_grad=None,
      coord_frame=FIFF.FIFFV_COORD_HEAD,
      source_ori=FIFF.FIFFV_MNE_FREE_ORI,
  ):
      """Convert forward solution matrices to dicts."""
      assert names is not None
      sol = dict(
          data=fwd.T,
          nrow=fwd.shape[1],
          ncol=fwd.shape[0],
          row_names=names,
          col_names=[],
      )
      fwd = Forward(
          sol=sol,
          source_ori=source_ori,
          nsource=sol["ncol"],
          coord_frame=coord_frame,
          sol_grad=None,
          nchan=sol["nrow"],
          _orig_source_ori=source_ori,
          _orig_sol=sol["data"].copy(),
          _orig_sol_grad=None,
      )
      if fwd_grad is not None:
          sol_grad = dict(
              data=fwd_grad.T,
              nrow=fwd_grad.shape[1],
              ncol=fwd_grad.shape[0],
              row_names=names,
              col_names=[],
          )
          fwd.update(
              dict(sol_grad=sol_grad),
              _orig_sol_grad=sol_grad["data"].copy(),
          )
      return fwd
  
imports: import os
  import os.path
  from contextlib import contextmanager
  from copy import deepcopy
  from pathlib import Path
  import numpy
  from .._fiff.compensator import get_current_comp, make_compensator
  from .._fiff.constants import FIFF, FWD
  from .._fiff.meas_info import Info, read_info
  from .._fiff.pick import _has_kit_refs, pick_info, pick_types
  from .._fiff.tag import _loc_to_coil_trans, _loc_to_eeg_loc
  from ..bem import ConductorModel, _bem_find_surface, read_bem_solution
  from ..source_estimate import VolSourceEstimate
  from ..source_space._source_space import _complete_vol_src, _ensure_src, _filter_source_spaces, _make_discrete_source_space
  from ..surface import _CheckInside, _normalize_vectors
  from ..transforms import Transform, _coord_frame_name, _ensure_trans, _get_trans, _print_coord_trans, apply_trans, invert_transform, transform_surface_to
  from ..utils import _check_fname, _pl, _validate_type, logger, verbose, warn
  from ._compute_forward import _compute_forwards
  from .forward import _FWD_ORDER, Forward, _merge_fwds, convert_forward_solution
label_desc: Use image node_id 14 for calling a global function with example usage: _to_forward_dict(fwd, names, fwd_grad, coord_frame, source_ori) and returns: fwd