code: def test_jac(x, dtype, func_str, backend_fw):
      if backend_fw == "numpy":
          pytest.skip()
  
      with BackendHandler.update_backend(backend_fw) as ivy_backend:
          f = ivy_backend.__dict__[func_str]
  
          def func(x):
              return ivy_backend.mean(f(x))
  
          _variable_fn = (
              ivy_backend.ivy.functional.ivy.gradients._variable
          )
          var = _variable_fn(ivy_backend.array(x, dtype=dtype))
          fn = ivy_backend.jac(func)
          jacobian = fn(var)
          jacobian_np = helpers.flatten_and_to_np(
              ret=jacobian, backend=backend_fw
          )
          assert jacobian_np != []
  
      with BackendHandler.update_backend("tensorflow") as gt_backend:
          f = gt_backend.__dict__[func_str]
  
          def func(x):
              return gt_backend.mean(f(x))
  
          _variable_fn = (
              gt_backend.ivy.functional.ivy.gradients._variable
          )
          var = _variable_fn(gt_backend.array(x, dtype=dtype))
          fn = gt_backend.jac(func)
          jacobian_gt = fn(var)
          jacobian_np_from_gt = helpers.flatten_and_to_np(
              ret=jacobian_gt, backend="tensorflow"
          )
          for jacobian, jacobian_from_gt in zip(
              jacobian_np, jacobian_np_from_gt
          ):
              assert jacobian.shape == jacobian_from_gt.shape
              assert np.allclose(jacobian, jacobian_from_gt)
  
      # Test nested input
      def func(xs):
          return 2 * xs[1]["x2"], xs[0]
  
      with BackendHandler.update_backend(backend_fw) as ivy_backend:
          _variable_fn = (
              ivy_backend.ivy.functional.ivy.gradients._variable
          )
          var1 = _variable_fn(ivy_backend.array(x[0], dtype=dtype))
          var2 = _variable_fn(ivy_backend.array(x[1], dtype=dtype))
          var = [var1, {"x2": var2}]
          fn = ivy_backend.jac(func)
          jacobian = fn(var)
          jacobian_np = helpers.flatten_and_to_np(
              ret=jacobian, backend=backend_fw
          )
  
      with BackendHandler.update_backend("tensorflow") as gt_backend:
          _variable_fn = (
              gt_backend.ivy.functional.ivy.gradients._variable
          )
          var1 = _variable_fn(gt_backend.array(x[0], dtype=dtype))
          var2 = _variable_fn(gt_backend.array(x[1], dtype=dtype))
          var = [var1, {"x2": var2}]
          fn = gt_backend.jac(func)
          jacobian_gt = fn(var)
          jacobian_np_from_gt = helpers.flatten_and_to_np(
              ret=jacobian_gt, backend="tensorflow"
          )
  
      for jacobian, jacobian_from_gt in zip(
          jacobian_np, jacobian_np_from_gt
      ):
          assert jacobian.shape == jacobian_from_gt.shape
          assert np.allclose(jacobian, jacobian_from_gt)
  
      # Test func with non 0-dim output
      with BackendHandler.update_backend(backend_fw) as ivy_backend:
          func = ivy_backend.__dict__[func_str]
          _variable_fn = (
              ivy_backend.ivy.functional.ivy.gradients._variable
          )
          var = _variable_fn(ivy_backend.array(x, dtype=dtype))
          fn = ivy_backend.jac(func)
          jacobian = fn(var)
          jacobian_np = helpers.flatten_and_to_np(
              ret=jacobian, backend=backend_fw
          )
  
      with BackendHandler.update_backend("tensorflow") as gt_backend:
          func = gt_backend.__dict__[func_str]
          _variable_fn = (
              gt_backend.ivy.functional.ivy.gradients._variable
          )
          var = _variable_fn(gt_backend.array(x, dtype=dtype))
          fn = gt_backend.jac(func)
          jacobian_gt = fn(var)
          jacobian_np_from_gt = helpers.flatten_and_to_np(
              ret=jacobian_gt, backend="tensorflow"
          )
          for jacobian, jacobian_from_gt in zip(
              jacobian_np, jacobian_np_from_gt
          ):
              assert jacobian.shape == jacobian_from_gt.shape
              assert np.allclose(jacobian, jacobian_from_gt)
  
file_path: ivy/ivy_tests/test_ivy/test_functional/test_core/test_gradients.py
imports: from hypothesis import strategies
  import pytest
  import numpy
  import ivy
  import ivy_tests.test_ivy.helpers
  from ivy_tests.test_ivy.helpers import handle_test, BackendHandler
label_desc: Use image node_id 7 for calling a global function with example usage: test_jac(x, dtype, func_str, backend_fw) and returns: unknown,  xs, ivy_backend, gt_backend