Skip to content

How to pass derivatives to dual number? How to combine analytical/numerical derivative computation with autodiff? #264

Answered by allanleal
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @Sajedeh1996 , please check possible solution below. As you see, you'll need to define a function wrapper Adual and Bdual as shown below, which inspect if incoming x and y arguments have been "seeded" in their grad member:

#include <iostream>

#include <autodiff/forward/dual.hpp>
using namespace autodiff;

auto  A(double x, double y) -> double { return x*y; }
auto Ax(double x, double y) -> double { return x; }
auto Ay(double x, double y) -> double { return y; }

auto  B(double x, double y) -> double { return x + y; }
auto Bx(double x, double y) -> double { return 1.0; }
auto By(double x, double y) -> double { return 1.0; }

auto Adual(dual const& x, dual const& y) -> dual
{
    dual re…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant