Is it possible to do autodiff based on macro?

I'm thinking about the probability of implementing auto-diff in RUST by using the macro.

This is inspired by the fact that in Julia, it is possible to implement autodiff with macro, e.g.,

In C++, it is also possible to do similar things by using templates.

Rust macros are executed before the types are analyzed, so you won't be able to know the types of expressions. Macros operate on tokens of the syntax. In this way they're closer to the C preprocessor.

Rust's closest analogy of C++ templates is traits/generics.

In practice you'd probably end up using both: macros to give it nice syntax, and generics under the hood to execute type-specific operations.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.