code: def _surf_upsampling_mat(idx_from, e, smooth):
      """Upsample data on a subject's surface given mesh edges."""
      # we're in CSR format and it's to==from
      assert isinstance(e, sparse.csr_matrix)
      n_tot = e.shape[0]
      assert e.shape == (n_tot, n_tot)
      # our output matrix starts out as a smaller matrix, and will gradually
      # increase in size
      data = sparse.eye(len(idx_from), format="csr")
      _validate_type(smooth, ("int-like", str, None), "smoothing steps")
      if smooth is not None:  # number of steps
          smooth = _ensure_int(smooth, "smoothing steps")
          if smooth <= 0:  # == 0 is handled in a shortcut above
              raise ValueError(
                  "The number of smoothing operations has to be at least 0, got "
                  f"{smooth}"
              )
          smooth = smooth - 1
      # idx will gradually expand from idx_from -> np.arange(n_tot)
      idx = idx_from
      recompute_idx_sum = True  # always compute at least once
      mult = np.zeros(n_tot)
      for k in range(100):  # the maximum allowed
          # on first iteration it's already restricted, so we need to re-restrict
          if k != 0 and len(idx) < n_tot:
              data = data[idx]
          # smoothing multiplication
          use_e = e[:, idx] if len(idx) < n_tot else e
          data = use_e * data
          del use_e
          # compute row sums + output indices
          if recompute_idx_sum:
              if len(idx) == n_tot:
                  row_sum = np.asarray(e.sum(-1))[:, 0]
                  idx = np.arange(n_tot)
                  recompute_idx_sum = False
              else:
                  mult[idx] = 1
                  row_sum = e * mult
                  idx = np.where(row_sum)[0]
          # do row normalization
          _csr_row_norm(data, row_sum)
          if k == smooth or (smooth is None and len(idx) == n_tot):
              break  # last iteration / done
      assert data.shape == (n_tot, len(idx_from))
      n_missing = n_tot - len(idx)
      n_iter = k + 1
      return data, n_missing, n_iter
  
imports: import copy
  import os.path
  import warnings
  import numpy
  from scipy import sparse
  from .fixes import _get_img_fdata
  from .morph_map import read_morph_map
  from .parallel import parallel_func
  from .source_estimate import _BaseSourceEstimate, _BaseSurfaceSourceEstimate, _BaseVolSourceEstimate, _get_ico_tris
  from .source_space._source_space import SourceSpaces, _ensure_src, _grid_interp
  from .surface import _compute_nearest, mesh_edges, read_surface
  from .utils import BunchConst, ProgressBar, _check_fname, _check_option, _custom_lru_cache, _ensure_int, _import_h5io_funcs, _import_nibabel, _validate_type, check_version, fill_doc, get_subjects_dir, logger, use_log_level, verbose, warn
  from .utils import warn
label_desc: Use image node_id 19 for calling a global function with example usage: _surf_upsampling_mat(idx_from, e, smooth) and returns: data,  n_missing,  n_iter