function valueAndGrad(f) {
	  assert(isFunction(f), function () {
	    return 'The f passed in valueAndGrad(f) must be a function';
	  });
	  return function (x, dy) {
	    assert(x instanceof Tensor, function () {
	      return 'The x passed in valueAndGrad(f)(x) must be a tensor';
	    });
	    assert(dy == null || dy instanceof Tensor, function () {
	      return 'The dy passed in valueAndGrad(f)(x, dy) must be a tensor';
	    });

	    var _ENGINE$gradients3 = ENGINE.gradients(function () {
	      return f(x);
	    }, [x], dy),
	        grads = _ENGINE$gradients3.grads,
	        value = _ENGINE$gradients3.value;

	    checkGrads(grads);
	    return {
	      grad: grads[0],
	      value: value
	    };
	  };
	}
Like `tf.grad`, but also returns the value of `f()`. Useful when `f()`
returns a metric you want to show.

The result is a rich object with the following properties:
- grad: The gradient of `f(x)` w.r.t `x` (result of `tf.grad`).
- value: The value returned by `f(x)`.

```js
// f(x) = x ^ 2
const f = x => x.square();
// f'(x) = 2x
const g = tf.valueAndGrad(f);

const x = tf.tensor1d([2, 3]);
const {value, grad} = g(x);

console.log('value');
value.print();
console.log('grad');
grad.print();
```

@doc {heading: 'Training', subheading: 'Gradients'}