Skip to content

Instantly share code, notes, and snippets.

@kayhman
Created October 5, 2020 11:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
from forward_autodiff import DualFloat
def simple_polynome(a, b):
return lambda x : x**2 * a + b
def squared_polynome(a, b, c):
return lambda x : x**2 * a + x * b + c
def squared_polynome_check(a, b, c):
return lambda x : 2*x * a + b
f1 = simple_polynome(3.0, 0.0)
f2 = squared_polynome(3.0, 2.0, 1.0)
f3 = squared_polynome_check(3.0, 2.0, 1.0)
r = f1(DualFloat(4, 1.0))
print(r)
# > DF(48.0, 24.0)
r = f2(DualFloat(3, 1.0))
check = f3(3)
print(r)
# > DF(34.0, 20.0)
print(check)
# > 20.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment