Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic Differentiation with CoDiPack

The following code:

#include <codi.hpp>
...
codi::RealForward Gcodi[l];
for (int p = 0; p < l; p++) 
{
     ...
     double a = Gcodi[p];
}

gives me the compilation error:

nnBFAD.cpp: In function ‘void OptBF()’:

nnBFAD.cpp:156:25: error: cannot convert ‘codi::RealForward {aka codi::ActiveReal >}’ to ‘double’ in initialization double

a = Gcodi[p];

Hints?

like image 819
Filippo Portera Avatar asked Apr 15 '26 10:04

Filippo Portera


1 Answers

According to the official doc here, RealForward is a type with an assignment operator overloaded, so you can assign that with a double..

like doing

codi::RealForward a = 3.0;

the opposite direction is of course not defined,

that is the raeson why you can not convert directly a codi::RealForward into a double just by doing:

double a = Gcodi[p];

but you can call the functions on that, i.e.

double a = Gcodi[p].getGradient();

UPDATE:

then you can assign a RealForward object with a double like doing

double myDouble{3.3};
RealForward a = myDouble;

but is not legal to assign a double directly from the REalForwad:

RealForward a = ...;
double myDouble = a; //not valid!

other examples

RealForward b = a * a; //this is ok because a * a is a double
like image 199
ΦXocę 웃 Пepeúpa ツ Avatar answered Apr 17 '26 00:04

ΦXocę 웃 Пepeúpa ツ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!