Skip to content

Instantly share code, notes, and snippets.

@skeggse
Last active February 21, 2017 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skeggse/74b4eae92111e34dcfc5bd493441cd65 to your computer and use it in GitHub Desktop.
Save skeggse/74b4eae92111e34dcfc5bd493441cd65 to your computer and use it in GitHub Desktop.
import scipy.optimize
# let check_grad work for x0: ndarray, like the documentation says it should
# see also: http://stackoverflow.com/q/15040263
def check_grad(func, grad, x0, *args, **kwargs):
return scipy.optimize.check_grad(lambda xh: func(xh.reshape(x0.shape), *args),
lambda xh: grad(xh.reshape(x0.shape), *args).flatten(),
x0.flatten(), **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment