code: def dgap_l21(M, G, X, active_set, alpha, n_orient):
      """Duality gap for the mixed norm inverse problem.
  
      See :footcite:`GramfortEtAl2012`.
  
      Parameters
      ----------
      M : array, shape (n_sensors, n_times)
          The data.
      G : array, shape (n_sensors, n_active)
          The gain matrix a.k.a. lead field.
      X : array, shape (n_active, n_times)
          Sources.
      active_set : array of bool, shape (n_sources, )
          Mask of active sources.
      alpha : float
          The regularization parameter.
      n_orient : int
          Number of dipoles per locations (typically 1 or 3).
  
      Returns
      -------
      gap : float
          Dual gap.
      p_obj : float
          Primal objective.
      d_obj : float
          Dual objective. gap = p_obj - d_obj.
      R : array, shape (n_sensors, n_times)
          Current residual (M - G * X).
  
      References
      ----------
      .. footbibilography::
      """
      p_obj, R, nR2, GX = _primal_l21(
          M, G, X, active_set, alpha, n_orient
      )
      dual_norm = norm_l2inf(np.dot(G.T, R), n_orient, copy=False)
      scaling = alpha / dual_norm
      scaling = min(scaling, 1.0)
      d_obj = (scaling - 0.5 * (scaling**2)) * nR2 + scaling * np.sum(
          R * GX
      )
  
      gap = p_obj - d_obj
      return gap, p_obj, d_obj, R
  
imports: import functools
  from math import sqrt
  import numpy
  from ..time_frequency._stft import istft, stft, stft_norm1, stft_norm2
  from ..utils import _check_option, _get_blas_funcs, _validate_type, logger, sum_squared, verbose, warn
  from .mxne_debiasing import compute_bias
label_desc: Use image node_id 6 for calling a global function with example usage: dgap_l21(M, G, X, active_set, alpha, n_orient) and returns: gap,  p_obj,  d_obj,  R