-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
53 lines (37 loc) · 1.11 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#All the user will need to import:
from operators import grad
import wrapped_numpy as np
#imports for testing
from wrappers import Box, sin
from operators import box_args
from tracer import toposort
from testing import numerical_grad_operator
def f(x,y,z):
return (x*y)**z+x**(y+z)-3*z*x
print(grad(f,0)(2.0,3.0,4.0)) #3028 #copy paste into wolframalpha: evaluate partial (x*y)^z+x^(y+z)-3*z*x wrt x where x=2,y=3,z=4.0
print(grad(f,1)(2.0,3.0,4.0))
print(grad(f,2)(2.0,3.0,4.0))
print(numerical_grad_operator(f,0)(2.0,3.0,4.0))
print(numerical_grad_operator(f,1)(2.0,3.0,4.0))
print(numerical_grad_operator(f,2)(2.0,3.0,4.0))
# for _ in toposort(f(Box(2.),Box(3.),Box(4.))):
# print(_)
# print()
# def f(x,y,z):
# return x*y, x*z
# def g(x, n):
# for _ in range(0,n):
# x = sin(x * 2)
# return x
# for _ in toposort(g(Box(2.0),3)):
# print(_)
# for _ in f(Box(2.0), Box(3.0), Box(4.0)):
# for __ in toposort(_):
# print(__)
# print(grad(f)(2.,3.))
# x = Box(5.0)
# y = Box(6.0)
# print((x+y).parents)
# print((x+5.0).parents)
# print((5.0+x).parents)
# print(Box(6.9))