code: def _make_dipoles_sparse(
      X,
      active_set,
      forward,
      tmin,
      tstep,
      M,
      gain_active,
      active_is_idx=False,
      verbose=None,
  ):
      times = tmin + tstep * np.arange(X.shape[1])
  
      if not active_is_idx:
          active_idx = np.where(active_set)[0]
      else:
          active_idx = active_set
  
      # Compute the GOF split amongst the dipoles
      assert M.shape == (gain_active.shape[0], len(times))
      assert gain_active.shape[1] == len(active_idx) == X.shape[0]
      gof_split = _split_gof(M, X, gain_active)
      assert gof_split.shape == (len(active_idx), len(times))
      assert X.shape[0] in (len(active_idx), 3 * len(active_idx))
  
      n_dip_per_pos = 1 if is_fixed_orient(forward) else 3
      if n_dip_per_pos > 1:
          active_idx = active_idx // n_dip_per_pos
          _, keep = np.unique(active_idx, return_index=True)
          keep.sort()  # maintain old order
          active_idx = active_idx[keep]
          gof_split.shape = (len(active_idx), n_dip_per_pos, len(times))
          gof_split = gof_split.sum(1)
          assert (gof_split < 100).all()
      assert gof_split.shape == (len(active_idx), len(times))
  
      dipoles = []
      for k, i_dip in enumerate(active_idx):
          i_pos = forward["source_rr"][i_dip][np.newaxis, :]
          i_pos = i_pos.repeat(len(times), axis=0)
          X_ = X[k * n_dip_per_pos : (k + 1) * n_dip_per_pos]
          if n_dip_per_pos == 1:
              amplitude = X_[0]
              i_ori = forward["source_nn"][i_dip][np.newaxis, :]
              i_ori = i_ori.repeat(len(times), axis=0)
          else:
              if forward["surf_ori"]:
                  X_ = np.dot(
                      forward["source_nn"][
                          i_dip
                          * n_dip_per_pos : (i_dip + 1)
                          * n_dip_per_pos
                      ].T,
                      X_,
                  )
              amplitude = np.linalg.norm(X_, axis=0)
              i_ori = np.zeros((len(times), 3))
              i_ori[amplitude > 0.0] = (
                  X_[:, amplitude > 0.0] / amplitude[amplitude > 0.0]
              ).T
  
          dipoles.append(
              Dipole(times, i_pos, amplitude, i_ori, gof_split[k])
          )
  
      return dipoles
  
imports: import numpy
  from .._fiff.proj import deactivate_proj
  from ..dipole import Dipole
  from ..fixes import _safe_svd
  from ..forward import is_fixed_orient
  from ..minimum_norm.inverse import _check_reference, _log_exp_var, _prepare_forward, combine_xyz
  from ..source_estimate import SourceEstimate, _BaseSourceEstimate, _make_stc
  from ..utils import _check_depth, _check_option, _validate_type, check_random_state, logger, sum_squared, verbose, warn
  from .mxne_optim import _Phi, groups_norm2, iterative_mixed_norm_solver, iterative_tf_mixed_norm_solver, mixed_norm_solver, norm_epsilon_inf, norm_l2inf, tf_mixed_norm_solver
label_desc: Use image node_id 8 for calling a global function with example usage: _make_dipoles_sparse(X, active_set, forward, tmin, tstep, M, gain_active, active_is_idx, verbose) and returns: dipoles