def check_grad(func, grad, x0, *args, **kwargs):
 step = kwargs.pop('epsilon', _epsilon)
 if kwargs:
  raise ValueError(('Unknown keyword arguments: %r' % (list(kwargs.keys()),)))
 return sqrt(sum(((grad(x0, *args) - approx_fprime(x0, func, step, *args)) ** 2)))

def check_grad ( func , grad , x0 , * args , ** kwargs ) : step = kwargs . pop ( 'epsilon' , _epsilon ) if kwargs : raise ValueError ( ( 'Unknown keyword arguments: %r' % ( list ( kwargs . keys ( ) ) , ) ) ) return sqrt ( sum ( ( ( grad ( x0 , * args ) - approx_fprime ( x0 , func , step , * args ) ) ** 2 ) ) )
check the correctness of a gradient function by comparing it against a finite-difference approximation of the gradient .