code: def _projector_on_tvl1_dual(grad, l1_ratio):
      """Compute TV-l1 duality gap.
  
      Modifies IN PLACE the gradient + id to project it
      on the l21 unit ball in the gradient direction and the L1 ball in the
      identity direction.
      """
      # The l21 ball for the gradient direction
      if l1_ratio < 1.0:
          # infer number of axes and include an additional axis if l1_ratio > 0
          end = len(grad) - int(l1_ratio > 0.0)
          norm = np.sqrt(np.sum(grad[:end] * grad[:end], 0))
          norm.clip(1.0, out=norm)  # set everythx < 1 to 1
          for grad_comp in grad[:end]:
              grad_comp /= norm
  
      # The L1 ball for the identity direction
      if l1_ratio > 0.0:
          norm = np.abs(grad[-1])
          norm.clip(1.0, out=norm)
          grad[-1] /= norm
  
      return grad
  
file_path: nilearn/nilearn/decoding/_proximal_operators.py
imports: from math import sqrt
  import numpy
  from ._objective_functions import divergence_id, gradient_id, tv_l1_from_gradient
label_desc: Use image node_id 3 for calling a global function with example usage: _projector_on_tvl1_dual(grad, l1_ratio) and returns: grad