Skip to content

Instantly share code, notes, and snippets.

@se4u
Last active August 29, 2015 14:19
Show Gist options
  • Save se4u/cdad977652d05e5d2219 to your computer and use it in GitHub Desktop.
Save se4u/cdad977652d05e5d2219 to your computer and use it in GitHub Desktop.
# Filename: test_autograd.py
# Description: Test autograd's limits.
# Author: Pushpendre Rastogi
# Created: Mon Apr 13 18:36:26 2015 (-0400)
# Last-Updated:
# By:
# Update #: 42
import autograd.numpy as np
from autograd import grad
from autograd.util import quick_grad_check
def assignment(y, x):
for i in range(3):
x['a'] = np.sum(np.array([y[i], x['a']]))
return x['a']
def test_assignment():
x = dict(a=1)
f = lambda y : assignment(y, x)
y = np.random.rand(3,1)
print f(y)
gradf = grad(f)
print gradf(y) # Works !
try:
print gradf(y) # Fails !!
except:
print "fail"
print gradf(y) # Works again !!!
return
if __name__ == "__main__":
test_assignment()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment