You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
0 commit comments