Ceres Jet incompatible with Matrix Functions
Hello,
I would like to use the Eigen matrix functions .pow()
and .exp()
with Ceres auto-differentiation. This does not appear to work, with Eigen HEAD and Ceres 1.14.0-7 (both installed via vcpkg
) compiled with an up-to-date Apple Clang. Here is my minimal example:
#include "ceres/Jet.h"
#include <unsupported/Eigen/MatrixFunctions>
int main() {
Eigen::Matrix<ceres::Jet<double, 4>, 4, 4> A, B;
B.setZero();
A = B.pow(2);
A = B.exp();
}
The .pow()
line produces the following pertinent errors (I have cut the remaining error lines, happy to upload the full lot if required). This seems fairly straightforward, the definition assumes the exponent type is implicitly convertible to the matrix scalar type:
[build] ../Source/RUFIS/test.cpp:7:11: error: no matching member function for call to 'pow'
[build] A = B.pow(2);
[build] ~~^~~
[build] /Users/tobias/Code/vcpkg/installed/x64-osx/include/Eigen/src/Core/MatrixBase.h:480:60: note: candidate function not viable: no known conversion from 'int' to 'const Eigen::MatrixBase<Eigen::Matrix<ceres::Jet<double, 4>, 4, 4, 0, 4, 4> >::RealScalar' (aka 'const Jet<double, 4>') for 1st argument
[build] EIGEN_MATRIX_FUNCTION_1(MatrixPowerReturnValue, pow, power to \c p, const RealScalar& p)
[build] ^
[build] /Users/tobias/Code/vcpkg/installed/x64-osx/include/Eigen/src/Core/MatrixBase.h:464:31: note: expanded from macro 'EIGEN_MATRIX_FUNCTION_1'
[build] const ReturnType<Derived> Name(Argument) const;
[build] ^
[build] /Users/tobias/Code/vcpkg/installed/x64-osx/include/Eigen/src/Core/MatrixBase.h:481:60: note: candidate function not viable: no known conversion from 'int' to 'const std::complex<RealScalar>' (aka 'const complex<Jet<double, 4> >') for 1st argument
[build] EIGEN_MATRIX_FUNCTION_1(MatrixComplexPowerReturnValue, pow, power to \c p, const std::complex<RealScalar>& p)
The .exp()
line produces the following errors:
[build] In file included from /Users/tobias/Code/vcpkg/installed/x64-osx/include/ceres/Jet.h:159:
[build] /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:590:12: error: no matching function for call to 'isinf'
[build] return isinf(__lcpp_x);
[build] ^~~~~
[build] /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/complex:1063:9: note: in instantiation of function template specialization 'std::__1::__libcpp_isinf_or_builtin<ceres::Jet<double, 4> >' requested here
[build] if (__libcpp_isinf_or_builtin(__x.real()))
[build] ^
[build] /Users/tobias/Code/vcpkg/installed/x64-osx/include/unsupported/Eigen/src/MatrixFunctions/StemFunction.h:22:10: note: in instantiation of function template specialization 'std::__1::exp<ceres::Jet<double, 4> >' requested here
[build] return exp(x);
I previously discussed .exp()
on the Ceres mailing list here: https://groups.google.com/forum/#!msg/ceres-solver/k8OdZolGq5Y/0xYtge85AwAJ but it seems that the Clang STL has been changed since then as the exact error message is slightly different.
If either of these functions could work with Ceres Jets I would be immensely happy. Thanks.