code: def total_variation(domain, grad=None):
      
  
      if grad is None:
          grad = odl.Gradient(domain, method='forward', pad_mode='symmetric')
          grad.norm = 2 * np.sqrt(sum(1 / grad.domain.cell_sides**2))
      else:
          grad = grad
  
      f = odl.solvers.GroupL1Norm(grad.range, exponent=2)
  
      return f * grad
docs: Total variation functional.
  
      Parameters
      ----------
      domain : odlspace
          domain of TV functional
      grad : gradient operator, optional
          Gradient operator of the total variation functional. This may be any
          linear operator and thereby generalizing TV. default=forward
          differences with Neumann boundary conditions
  
      Examples
      --------
      Check that the total variation of a constant is zero
  
      >>> import odl.contrib.spdhg as spdhg, odl
      >>> space = odl.uniform_discr([0, 0], [3, 3], [3, 3])
      >>> tv = spdhg.total_variation(space)
      >>> x = space.one()
      >>> tv(x) < 1e-10