Skip to content

Conversation

@MaxSagebaum
Copy link
Contributor

Additional steps for making autodiff work.

MaxSagebaum referenced this pull request Feb 7, 2025
…mple

The test @autodiff function can now handle the "r = a + b;" case.

This code:

   test: @autodiff @print type = {

      // A simple first function would be:
      // func: (a: double, b: double) -> double = { return a + b; }
      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;
      //     r = a * b;
      // }

   }

Generates the following, as reported by @print in the cppfront compile output:

   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,
         ) =
      {
         r_d = a * b_d + b * a_d;
         r = a * b;
         return;
      }
   }

And a bug fix: When a file that contains Cpp2 code begins with Cpp1 #includes, preserve their position at the top of the generated file too. This allows a Cpp2 type's template parameter list to use types a from Cpp1 header file.
@hsutter hsutter merged commit 496b75d into hsutter:main Feb 7, 2025
24 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants