function valueAndGrad(f) {
    _util.assert(_util.isFunction(f), ()=>"The f passed in valueAndGrad(f) must be a function");
    return (x, dy)=>{
        _util.assert(x instanceof (0, _tensor.Tensor), ()=>"The x passed in valueAndGrad(f)(x) must be a tensor");
        _util.assert(dy == null || dy instanceof (0, _tensor.Tensor), ()=>"The dy passed in valueAndGrad(f)(x, dy) must be a tensor");
        const { grads, value } = (0, _engine.ENGINE).gradients(()=>f(x), [
            x
        ], dy);
        checkGrads(grads);
        return {
            grad: grads[0],
            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'}