# tf.test.compute_gradient

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 1 version](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/test/compute_gradient) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/ops/gradient_checker_v2.py#L296-L332) |

Computes the theoretical and numeric Jacobian of `f`.

    tf.test.compute_gradient(
        f, x, delta=0.001
    )

With y = f(x), computes the theoretical and numeric Jacobian dy/dx.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `f` | the function. |
| `x` | a list arguments for the function |
| `delta` | (optional) perturbation used to compute numeric Jacobian. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A pair of lists, where the first is a list of 2-d numpy arrays representing the theoretical Jacobians for each argument, and the second list is the numerical ones. Each 2-d array has "x_size" rows and "y_size" columns where "x_size" is the number of elements in the corresponding argument and "y_size" is the number of elements in f(x). ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If result is empty but the gradient is nonzero. |
| `ValueError` | If x is not list, but any other type. |

<br />

#### Example:

    @tf.function
    def test_func(x):
      return x*x

    theoretical, numerical = tf.test.compute_gradient(test_func, [1.0])
    theoretical, numerical
    # ((array([[2.]], dtype=float32),), (array([[2.000004]], dtype=float32),))