Comments (9)
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.
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.
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.
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.
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.
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.
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.
Yes, indeed.
from cppad.
Thanks a lot for your help. I fixed the bug related to my issues in joaoleal/CppADCodeGen#16
from cppad.
Related Issues (20)
- How to convert from an AD<double> to a double ? HOT 3
- Tried to set Option: xx. It is not a valid option. Please check the list of available options HOT 2
- Computing the Jacobian of an ODE HOT 2
- CPPAD_DISCRETE_FUNCTION does not work through base2ad HOT 2
- Eigen::NumTraits does not define infinity() or quiet_NaN() HOT 3
- How to add self defined functions to AD<Base>? HOT 8
- Using C++ conditional operators HOT 5
- AD<double> not working in Eigen with some complex function HOT 4
- Computing Derivatives of solutions of optimization Problems HOT 9
- Working with CppAD::ipopt::solve and CppADCodeGen HOT 4
- Leppov case missing in local/optimize/get_op_usage.hpp HOT 3
- Discrete coefficient sets for polynomial vary as a function of dependent variable HOT 16
- How to write the `.lp` file of a Ipopt model? HOT 6
- Linking error "undefined reference to `CppAD::local::temp_file()'" HOT 4
- solution vector is empty HOT 10
- Undefined reference to temp_file HOT 2
- ipopt and cppad tests HOT 11
- Problem to Link with CppAD and Ipopt HOT 16
- CppAD::cg::CGException: what(): GreaterThanZero cannot be called for non-parameters HOT 5
- Compiler warnings from use of bitwise '|' and '&' for bool arguments HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cppad.