def approx_fprime(x, f, eps=None, *args):
    if eps is None:
        eps = np.sqrt(np.finfo(ca.float_).eps)
    grad = np.zeros_like(x)
    step = np.zeros_like(x)
    for idx in np.ndindex(x.shape):
        step[idx] = eps * max(abs(x[idx]), 1.0)
        grad[idx] = (f(*((x+step,) + args)) -
                     f(*((x-step,) + args))) / (2*step[idx])
        step[idx] = 0.0
    return grad
Central difference approximation of the gradient of a scalar function.
dataset/ETHPy150Open andersbll/deeppy/test/unit/feedforward/test_layers.py/approx_fprime