rjhogan / Adept-2

Combined array and automatic differentiation library in C++
http://www.met.reading.ac.uk/clouds/adept/
Apache License 2.0
163 stars 29 forks source link

Fabs(.) fails to compile. #5

Closed JackCibc closed 6 years ago

JackCibc commented 6 years ago

Hi. I think there is a typo in UnaryOperation.h, Line 190. In the definition of Fabs, it should say std::fabs, not std::abs.

The following test program fails to compile (Visual Studio 15.5.2 on Windows 7), and is fixed by the patch above. I don't have other systems available to test on I'm afraid.

Best wishes,

John.

`#include "adept.h" using adept::adouble;

int main() { adouble x = 1.0; adouble y = fabs(x); return 0; }`

with

Error 'adept::fabs': no matching overloaded function found d:\dev\exoticagit\aad\adept-2\adept-2.0.3\include\adept\unaryoperation.h 190 Error 'adept::internal::UnaryOperation<Type,adept::internal::Fabs,R> adept::fabs(const adept::Expression<Type,A> &)': could not deduce template argument for 'const adept::Expression<Type,A> &' from 'const adept::Real' d:\dev\exoticagit\aad\adept-2\adept-2.0.3\include\adept\unaryoperation.h 190

This patch fixes it for me:

`--- a/3rdParty/Adept-2/adept-2.0.4/adept-2.0.4/include/adept/UnaryOperation.h +++ b/3rdParty/Adept-2/adept-2.0.4/adept-2.0.4/include/adept/UnaryOperation.h @@ -239,7 +239,7 @@ namespace adept { ADEPT_DEF_UNARY_FUNC(Sinh, sinh, std::sinh, "sinh", cosh(val), false) ADEPT_DEF_UNARY_FUNC(Cosh, cosh, std::cosh, "cosh", sinh(val), false) ADEPT_DEF_UNARY_FUNC(Abs, abs, std::abs, "abs", ((val>0.0)-(val<0.0)), false)

// Functions y(x) whose derivative depends on the result of the // function, i.e. dy(x)/dx = f(y) --`

rjhogan commented 6 years ago

P {margin-top:0;margin-bottom:0;}

Thanks - I must have thought that fabs depended on C++11, which it doesn't.  I've made the change on github. Best wishes, Robin

From: JackCibc [notifications@github.com] Sent: 10 January 2018 09:55 To: rjhogan/Adept-2 Cc: Subscribed Subject: [rjhogan/Adept-2] Fabs(.) fails to compile. (#5)

Hi. I think there is a typo in UnaryOperation.h, Line 190. In the definition of Fabs, it should say std::fabs, not std::abs. The following test program fails to compile (Visual Studio 15.5.2 on Windows 7), and is fixed by the patch above. I don't have other systems available to test on I'm afraid. Best wishes, John. #include "adept.h" using adept::adouble; int main() { adouble x = 1.0; adouble y = fabs(x); return 0; } with Error 'adept::fabs': no matching overloaded function found d:\dev\exoticagit\aad\adept-2\adept-2.0.3\include\adept\unaryoperation.h 190 Error 'adept::internal::UnaryOperation<Type,adept::internal::Fabs,R> adept::fabs(const adept::Expression<Type,A> &)': could not deduce template argument for 'const adept::Expression<Type,A> &' from 'const adept::Real' d:\dev\exoticagit\aad\adept-2\adept-2.0.3\include\adept\unaryoperation.h 190 This patch fixes it for me: `--- a/3rdParty/Adept-2/adept-2.0.4/adept-2.0.4/include/adept/UnaryOperation.h +++ b/3rdParty/Adept-2/adept-2.0.4/adept-2.0.4/include/adept/UnaryOperation.h @@ -239,7 +239,7 @@ namespace adept { ADEPT_DEF_UNARY_FUNC(Sinh, sinh, std::sinh, "sinh", cosh(val), false) ADEPT_DEF_UNARY_FUNC(Cosh, cosh, std::cosh, "cosh", sinh(val), false) ADEPT_DEF_UNARY_FUNC(Abs, abs, std::abs, "abs", ((val>0.0)-(val<0.0)), false)

ADEPT_DEF_UNARY_FUNC(Fabs, fabs, std::abs, "fabs", ((val>0.0)-(val<0.0)), false)

ADEPT_DEF_UNARY_FUNC(Fabs, fabs, std::fabs, "fabs", ((val>0.0)-(val<0.0)), false)

// Functions y(x) whose derivative depends on the result of the // function, i.e. dy(x)/dx = f(y) --` — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.