Skip to content

Instantly share code, notes, and snippets.

@cavaunpeu
Created January 28, 2018 03:19
Show Gist options
  • Save cavaunpeu/43dad7900050891a34ba8f902b24ed0f to your computer and use it in GitHub Desktop.
Save cavaunpeu/43dad7900050891a34ba8f902b24ed0f to your computer and use it in GitHub Desktop.
# halp?
def foo(x, y):
return f(x, y) + g(x, y)
g_foo = grad(foo, argnum=1)
bar = a + b
g_bar = tf.gradients(bar, var_list)
# g_bar == g_foo(x, y) ... TRUE
# Now, changing the respective plus signs to minus signs ...
def foo(x, y):
return f(x, y) - g(x, y)
g_foo = grad(foo, argnum=1)
bar = a - b
g_bar = tf.gradients(bar, var_list)
# g_bar == g_foo(x, y) ... FALSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment