def compute_grad(J, f):
 if isinstance(J, LinearOperator):
  return J.rmatvec(f)
 else:
  return J.T.dot(f)

def compute_grad ( J , f ) : if isinstance ( J , LinearOperator ) : return J . rmatvec ( f ) else : return J . T . dot ( f )
compute gradient of the least-squares cost function .