kaskr / adcomp

AD computation with Template Model Builder (TMB)
Other
176 stars 80 forks source link

Included double sqrt(int) function and template specializations of co… #306

Closed yukio-takeuchi closed 4 years ago

yukio-takeuchi commented 4 years ago

…mplex<> operator/ and complex<> operator* for Apple clang++ compiler with complex header from libc++ in order to compile VAST_v8_5_0.cpp

As noted [here]https://github.com/kaskr/adcomp/issues/297#issuecomment-584986159, compilation of VAST_v*.cpp (eg VAST_v8_5_0.cpp) from [VAST]https://github.com/James-Thorson-NOAA/VAST on MacOS if Apple clang++ compiler is used. This problem is actually caused by the implementation of "complex<> operator/" in [complex header]https://github.com/llvm/llvm-project/blob/master/libcxx/include/complex. It requires conversion operator from AD to int as it has a piece of code (line 679)

 __ilogbw = static_cast<int>(__logbw);

where _logbw to be AD. In order to resolve this problem, a modification of definition of class CppAD::AD to include conversion operator from AD to int. As an alternative solution, I would like to propose to include template specializations of complex<> operator/ for AD, AD<AD> and AD<AD<AD>> into TMB.hpp. In addition Apple clang++ compiler often produce a compilation error if a piece of code.

sqrt(8)

I would also like to propose to include a function

double sqrt(int)

into TMB.hpp

These additions are conditional to the macro APPLE so that they will be enabled if and only if clang++ compiler is used on MacOS platform.

kaskr commented 4 years ago

Thanks for taking the time to make the PR.

However, I have to say right away that this does not belong in TMB. Cleaning up LLVM's implementation of STL should be a job for the LLVM developers.