Last active
May 26, 2020 20:38
-
-
Save tswedish/849c2f3ef0d3a2db0b65a8ea3e4b369b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_diff_fn(fn): | |
def diff_fn(*argv): | |
jacobian = [] | |
Dual_arguments = [Dual(x, 0.) for x in argv] | |
for input_arg in Dual_arguments: | |
input_arg.derivative = 1. | |
result = fn(*Dual_arguments) | |
jacobian.append(result.derivative) | |
input_arg.derivative = 0. | |
return jacobian | |
return diff_fn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment