Skip to content

Commit dd704be

Browse files
committed
Handling of member function calls.
First basic setup for declared variable lookup.
1 parent 247a79d commit dd704be

10 files changed

+1436
-884
lines changed

regression-tests/pure2-autodiff-higher-order.cpp2

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ func_outer: (x: double, y: double) -> (ret: double) = {
99

1010
type_outer: type = {
1111
public a: double = 0.0;
12+
13+
add: (this, b: double) -> double = {
14+
return a + b;
15+
}
1216
}
1317

1418
ad_test: @autodiff<"order=6"> @print type = {
@@ -173,6 +177,13 @@ ad_test: @autodiff<"order=6"> @print type = {
173177

174178
r = t.a + y;
175179
}
180+
181+
type_outer_call: (x: double, y: double) -> (r: double) = {
182+
t : type_outer = ();
183+
t.a = x;
184+
185+
r = t.add(y);
186+
}
176187
}
177188
}
178189

@@ -220,4 +231,5 @@ main: () = {
220231
write_output("do while loop", x, x_d, y, y_d, ad_name::ad_test::do_while_loop_d(x, x_d, y, y_d));
221232
write_output("for loop", x, x_d, y, y_d, ad_name::ad_test::for_loop_d(x, x_d, y, y_d));
222233
write_output("tye_outer.a + y", x, x_d, y, y_d, ad_name::ad_test::type_outer_use_d(x, x_d, y, y_d));
234+
write_output("type_outer.add(y)", x, x_d, y, y_d, ad_name::ad_test::type_outer_call_d(x, x_d, y, y_d));
223235
}

regression-tests/pure2-autodiff.cpp2

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ func_outer: (x: double, y: double) -> (ret: double) = {
66

77
type_outer: type = {
88
public a: double = 0.0;
9+
10+
add: (this, b: double) -> double = {
11+
return a + b;
12+
}
913
}
1014

1115
ad_test: @autodiff @print type = {
@@ -170,6 +174,13 @@ ad_test: @autodiff @print type = {
170174

171175
r = t.a + y;
172176
}
177+
178+
type_outer_call: (x: double, y: double) -> (r: double) = {
179+
t : type_outer = ();
180+
t.a = x;
181+
182+
r = t.add(y);
183+
}
173184
}
174185
}
175186

@@ -217,6 +228,7 @@ main: () = {
217228
write_output("do while loop", x, x_d, y, y_d, ad_name::ad_test::do_while_loop_d(x, x_d, y, y_d));
218229
write_output("for loop", x, x_d, y, y_d, ad_name::ad_test::for_loop_d(x, x_d, y, y_d));
219230
write_output("tye_outer.a + y", x, x_d, y, y_d, ad_name::ad_test::type_outer_use_d(x, x_d, y, y_d));
231+
write_output("type_outer.add(y)", x, x_d, y, y_d, ad_name::ad_test::type_outer_call_d(x, x_d, y, y_d));
220232

221233
r_twice := ad_test_twice::mul_1_d_d2(x, x_d, x_d, 0.0);
222234
std::cout << "2nd order diff of x*x at (x)$ = (r_twice.r_d_d2)$" << std::endl;

regression-tests/test-results/gcc-13-c++2b/pure2-autodiff-higher-order.cpp.execution

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,11 @@ diff(tye_outer.a + y) at (x = 2.000000, x_d = ( 1.000000 0.000000 0.000000 0.000
214214
d4 = 0.000000
215215
d5 = 0.000000
216216
d6 = 0.000000
217+
diff(type_outer.add(y)) at (x = 2.000000, x_d = ( 1.000000 0.000000 0.000000 0.000000 0.000000 0.000000 ), y = 3.000000, y_d = ( 2.000000 0.000000 0.000000 0.000000 0.000000 0.000000 )):
218+
r = 5.000000
219+
d1 = 3.000000
220+
d2 = 0.000000
221+
d3 = 0.000000
222+
d4 = 0.000000
223+
d5 = 0.000000
224+
d6 = 0.000000

regression-tests/test-results/gcc-13-c++2b/pure2-autodiff.cpp.execution

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ diff(while loop) at (x = 2.000000, x_d = 1.000000, y = 3.000000, y_d = 2.000000)
2525
diff(do while loop) at (x = 2.000000, x_d = 1.000000, y = 3.000000, y_d = 2.000000) = (r = 8.000000, r_d = 5.000000)
2626
diff(for loop) at (x = 2.000000, x_d = 1.000000, y = 3.000000, y_d = 2.000000) = (r = 5.000000, r_d = 3.000000)
2727
diff(tye_outer.a + y) at (x = 2.000000, x_d = 1.000000, y = 3.000000, y_d = 2.000000) = (r = 5.000000, r_d = 3.000000)
28+
diff(type_outer.add(y)) at (x = 2.000000, x_d = 1.000000, y = 3.000000, y_d = 2.000000) = (r = 5.000000, r_d = 3.000000)
2829
2nd order diff of x*x at 2.000000 = 2.000000

0 commit comments

Comments
 (0)