Create a function that evaluates both f and the gradient of f.
f
When { hasAux: true } is passed, the function f is expected to return an [out, aux] tuple, and the return value will be [[out, aux], gradient].
{ hasAux: true }
[out, aux]
[[out, aux], gradient]
Optional
// Without hasAuxconst [value, gradient] = valueAndGrad(f)(x);// With hasAuxconst [[value, aux], gradient] = valueAndGrad(f, { hasAux: true })(x); Copy
// Without hasAuxconst [value, gradient] = valueAndGrad(f)(x);// With hasAuxconst [[value, aux], gradient] = valueAndGrad(f, { hasAux: true })(x);
Create a function that evaluates both
fand the gradient off.When
{ hasAux: true }is passed, the functionfis expected to return an[out, aux]tuple, and the return value will be[[out, aux], gradient].