Commit 2884b34
committed
Add param/return list reflection + autodiff stub (so far just differentiated signature generation)
My short-term goal is to implement a narrow slice of functionality that's just enough to unblock basic autodiff, then once that's working to later go back and generalize those features.
Example: This commit supports return lists (e.g., `-> (r: double)`), then in the future I'll add support for single anonymous returns (e.g., `-> double`).
Example: This commit still supports metafunctions only on types and so focuses on param/return lists for type-scope functions, then in the future I'll add support for reflecting namespace-scope functions and generating additional functions in the same namespace scope.
As a test case, this commit also adds baby-step scaffolding for an `autodiff` metafunction that can be used like this:
test: @autodiff @print type = {
// A simple first function would be:
func: (a: double, b: double) -> (r: double) = { r = a + b; }
// The generated autodiff forward transformation would be:
// func_diff: (a: double, a_d: double, b: double, b_d: double) -> (r: double, r_d: double) = {
// r_d = a * b_d + b * a_d; // this body is not yet
// r = a * b; // generated in this commit
// }
}
This commit does not yet reflect the function body, but does generate the following `@print` pretty-preinted output for the above to show what is generated for the function signature:
test:/* @autodiff @print */ type =
{
func:(
in a: double,
in b: double,
) -> (out r: double, ) =
{
r = a + b;
return;
}
func_diff:(
in a: double,
in a_d: double,
in b: double,
in b_d: double,
) -> (
out r: double = 1,
out r_d: double = 1,
) =
{
return;
}
}
Note: Thanks again to the folks who persisted in convincing me to allow extra optional trailing commas in lists throughout Cpp2. It's only a little thing to avoid writing the extra code to generate the commas only for non-last parameters, but avoiding that little extra work is surprisingly "nice" when generating code and makes the metafunction that much cleaner and simpler.1 parent ec1f98a commit 2884b34
File tree
4 files changed
+718
-554
lines changed- regression-tests/test-results
- source
4 files changed
+718
-554
lines changedLines changed: 0 additions & 3 deletions
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3979 | 3979 | | |
3980 | 3980 | | |
3981 | 3981 | | |
3982 | | - | |
| 3982 | + | |
3983 | 3983 | | |
3984 | 3984 | | |
3985 | 3985 | | |
3986 | 3986 | | |
3987 | 3987 | | |
3988 | 3988 | | |
3989 | 3989 | | |
| 3990 | + | |
| 3991 | + | |
| 3992 | + | |
| 3993 | + | |
| 3994 | + | |
| 3995 | + | |
| 3996 | + | |
| 3997 | + | |
| 3998 | + | |
| 3999 | + | |
| 4000 | + | |
| 4001 | + | |
| 4002 | + | |
| 4003 | + | |
| 4004 | + | |
| 4005 | + | |
| 4006 | + | |
| 4007 | + | |
| 4008 | + | |
3990 | 4009 | | |
3991 | 4010 | | |
3992 | 4011 | | |
| |||
0 commit comments