Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the value of a CppADCodeGen scalar type #79

Open
FenglongSong opened this issue Aug 30, 2022 · 1 comment
Open

How to get the value of a CppADCodeGen scalar type #79

FenglongSong opened this issue Aug 30, 2022 · 1 comment

Comments

@FenglongSong
Copy link

Hi,

First of all, thanks for developing this great tool! I'm new to CppADCodeGen, I'd like to ask is there any way to get the value of a scalar type CppAD::AD<CppAD::cg::CG<double>> (or convert this type to the double type). I know in CppAD this is possible by using CppAD::Value() of Var2Par() function, but I don't know how to do that in CppADCodeGen. Would you please give me any advice? Thanks a lot!

@joaoleal
Copy link
Owner

Hello,

It is possible to CppAD::Value() and Var2Par() to retrieve the CG<double> and then CG<double>::getValue() to retrive the value (which can throw an exception if the value is not defined).
For instance:

        CppAD::vector<ADCG> x(2);
        x[0] = 2.; // values must be defined!
        x[1] = 3.; // values must be defined!
        Independent(x);

        ADCG a = x[0] / 1. + x[1] * x[1];
        ADCG b = a / 2e-6;

        std::cout << CppAD::Value(CppAD::Var2Par(b)).getValue() << std::endl;

Kind regards

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

No branches or pull requests

2 participants