Skip to content

Commit a063dcc

Browse files
committed
example: remove input
Otherwise the test won't finish. While here, fix style
1 parent 946d66d commit a063dcc

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

example/add_eq.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,51 @@
33
from pycppad import AD, Independent, ADFun, Value
44
import numpy as np
55

6-
76
# domain space vector
8-
n = 1;
7+
n = 1
98
x0 = 0.5
109

11-
x = np.array([AD(x0),]*n)
10+
x = np.array([AD(x0)] * n)
1211

1312
# declare independent variables and start tape recording
1413
Independent(x)
1514

1615
# range space vector
17-
m = 2;
18-
y = np.zeros((m,),dtype=AD)
19-
y[0] = x[0]; # initial value
20-
y[0] += AD(2); # AD<double> += int
21-
y[0] += AD(4.); # AD<double> += double
16+
m = 2
17+
y = np.zeros(m, dtype=AD)
18+
y[0] = x[0]
19+
# initial value
20+
y[0] += AD(2)
21+
# AD<double> += int
22+
y[0] += AD(4.)
23+
# AD<double> += double
2224
y[0] += x[0]
23-
y[1] = y[0]; # use the result of a compound assignment
25+
y[1] = y[0]
26+
# use the result of a compound assignment
2427

2528
# create f: x -> y and stop tape recording
26-
f = ADFun(x,y);
27-
input("raw_input")
29+
f = ADFun(x, y)
30+
# input("raw_input")
2831

29-
#f.optimize("no_compare_op")
32+
# f.optimize("no_compare_op")
3033

31-
assert(Value(y[0]) == x0+2.+4.+x0)
32-
assert(Value(y[1]) == Value(y[0]))
34+
assert Value(y[0]) == x0 + 2. + 4. + x0
35+
assert Value(y[1]) == Value(y[0])
3336

3437
dx = np.zeros(n)
3538
dy = np.zeros(m)
3639

3740
dx[0] = 1.
38-
dy = f.Forward(1 ,dx)
39-
assert(dy[0] == 2.)
40-
assert(dy[1] == 2.)
41+
dy = f.Forward(1, dx)
42+
assert dy[0] == 2.
43+
assert dy[1] == 2.
4144

4245
# reverse computation of derivative of y[0]
43-
w = np.zeros((m,))
44-
dw = np.zeros((n),)
46+
w = np.zeros(m)
47+
dw = np.zeros(n)
4548

4649
w[0] = 1.
4750
w[1] = 0.
4851
dw = f.Reverse(1, w)
4952

50-
assert(dw[0] == 2.)
53+
assert dw[0] == 2.

0 commit comments

Comments
 (0)