GithubHelp home page GithubHelp logo

namespace CppAD about cppad HOT 9 CLOSED

coin-or avatar coin-or commented on July 23, 2024
namespace CppAD

from cppad.

Comments (9)

bradbell avatar bradbell commented on July 23, 2024

ad_value is in the CppAD namespace and so the CppAD version of abs is being called; see
https://coin-or.github.io/CppAD/doc/unary_standard_math.htm

There is more going on here. In the CppAD namespace, the abs function has been extended to the base type; see
https://coin-or.github.io/CppAD/doc/base_std_math.htm

Perhaps it would have been better if CppAD had left abs alone and just used fabs, which it also defines for both cases.

from cppad.

jcarpent avatar jcarpent commented on July 23, 2024

Ok. I got it. I did have in mind that because abs and ad_value are inside the same CppAD namespace, then the compiler will then be able to use abs without any precise namespace.

This means that https://github.com/joaoleal/CppADCodeGen/blob/2f88701530fed57dcd1793ba769fbe8d53a9bee1/include/cppad/cg/math.hpp#L20
may lead to some trouble, because CppAD::cg::CG and the related math functions are in two different namespaces.

Thanks a lot for your quick reply!

from cppad.

bradbell avatar bradbell commented on July 23, 2024

I think that that putting these definitions in the CppAD::cg namespace will work for code in the CppAD::cg name space and putting it in the CppAD namespace will work everywhere.

from cppad.

jcarpent avatar jcarpent commented on July 23, 2024

I tried to call for instance abs function on a CppAD::cg::CG<Scalar> object and it was not working when abs was only defined in CppAD namespace.
But if we define abs in CppAD::cg namespace, it perfectly works.

from cppad.

bradbell avatar bradbell commented on July 23, 2024

Would it be possible for you to construct a very short example that demonstrates this just using CppAD ? I want to make sure I understand the exact problem.

from cppad.

jcarpent avatar jcarpent commented on July 23, 2024

Yes, of course. This is an example of what I tried to mention:

# include <cppad/cg.hpp>

int main()
{
  CppAD::AD<double> ad_value(-1.);
  abs(ad_value); // works perfectly
  
  CppAD::cg::CG<double> cg_value(-1.);
  abs(cg_value); // does not compile because abs<double>(const CppAD::cg::CG<double>&) is defined in namespace CppAD and not CppAD::cg
  return -1;
}

from cppad.

bradbell avatar bradbell commented on July 23, 2024

The type CppAD::cg::CG is not a CppAD type.
On the other hand, abs should work for

typedef CppAD::cg::CG<double> Base;
CppAD::AD<Base> cg_value(-1);
abs(cg_value);

OH, there is a problem here. CppAD needs to compute the base type values, as well as the AD values, for each entry.

from cppad.

jcarpent avatar jcarpent commented on July 23, 2024

Yes, indeed.

from cppad.

jcarpent avatar jcarpent commented on July 23, 2024

Thanks a lot for your help. I fixed the bug related to my issues in joaoleal/CppADCodeGen#16

from cppad.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.