code: def compute_grad(J, f):
      """Compute gradient of the least-squares cost function."""
      if isinstance(J, LinearOperator):
          return J.rmatvec(f)
      else:
          return J.T.dot(f)
  
imports: from __future__ import division, print_function, absolute_import
  from math import copysign
  import numpy
  from numpy.linalg import norm
  from scipy.linalg import cho_factor, cho_solve, LinAlgError
  from scipy.sparse import issparse
  from scipy.sparse.linalg import LinearOperator, aslinearoperator
label_desc: Use image node_id 18 for calling a global function with example usage: compute_grad(J, f) and returns: J, J