Skip to content

Instantly share code, notes, and snippets.

@tswedish
Last active May 26, 2020 20:38
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 tswedish/f981f89d0cc8d2133a4026c59f8a1496 to your computer and use it in GitHub Desktop.
Save tswedish/f981f89d0cc8d2133a4026c59f8a1496 to your computer and use it in GitHub Desktop.
def forward_fn(x):
for n in range(5):
if n % 2 == 0:
x = 3.*x
else:
x = x**(1./n) + 1./n
return x
x = Variable(2.)
y = forward_fn(x)
print(y)
y.backward()
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment