Mercurial > lbo > hg > autodiff
changeset 9:84d09d282bdb
gad: print expression tree in example section
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Mon, 27 Dec 2021 23:36:35 +0100 |
parents | f71ade2784c4 |
children | cec279d69c6b |
files | gad.py |
diffstat | 1 files changed, 11 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/gad.py Mon Dec 27 23:31:40 2021 +0100 +++ b/gad.py Mon Dec 27 23:36:35 2021 +0100 @@ -281,7 +281,10 @@ z = np.array([sqrt(log(e)) for e in y]) return z +# # ...or automatically using @gradify +# +# Mini benchmarks: print jacobians of gradify'd functions # Equivalent to (without @gradify): print(ade.grad([complex_calculation(x,y,z)], [1,4,5])) before = time.time_ns() print(pres_calculation(1,4,5)) @@ -292,3 +295,11 @@ print(complex_calculation2(*list(range(1, 100, 2)))[1].shape) after = time.time_ns() print((after-before)/1e9) + +before = time.time_ns() +print(complex_calculation(5,6,7)[1].shape) +after = time.time_ns() +print((after-before)/1e9) + +# Print expression tree +print([str(e) for e in complex_calculation.orig()(x,y,z)])