Change the underlying type of VectorXreal from double to float/long double #222
-
I am using auto diff to write a numerical library that uses meta-programming so that not just double, but float/long double can also be used. Currently, i can use eigen vector of type double to initialize ArrayXreal variable. This example is working.
This example is not working when the input vector is of float type.
This is the compilation error. /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h: In instantiation of ‘void Eigen::internal::call_assignment_no_alias(Dst&, const Src&, const Func&) [with Dst = Eigen::Array<autodiff::detail::Real<1, double>, -1, 1>; Src = Eigen::Matrix<float, -1, 1>; Func = Eigen::internal::assign_op<autodiff::detail::Real<1, double>, float>]’: /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:804:27: required from ‘void Eigen::internal::call_assignment(Dst&, const Src&, const Func&, typename Eigen::internal::enable_if<(! Eigen::internal::evaluator_assume_aliasing<Src>::value), void*>::type) [with Dst = Eigen::Array<autodiff::detail::Real<1, double>, -1, 1>; Src = Eigen::Matrix<float, -1, 1>; Func = Eigen::internal::assign_op<autodiff::detail::Real<1, double>, float>; typename Eigen::internal::enable_if<(! Eigen::internal::evaluator_assume_aliasing<Src>::value), void*>::type = void*]’ /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:782:18: required from ‘void Eigen::internal::call_assignment(Dst&, const Src&) [with Dst = Eigen::Array<autodiff::detail::Real<1, double>, -1, 1>; Src = Eigen::Matrix<float, -1, 1>]’ /usr/include/eigen3/Eigen/src/Core/PlainObjectBase.h:714:32: required from ‘Derived& Eigen::PlainObjectBase<Derived>::_set(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::Matrix<float, -1, 1>; Derived = Eigen::Array<autodiff::detail::Real<1, double>, -1, 1>]’ /usr/include/eigen3/Eigen/src/Core/Array.h:109:24: required from ‘Eigen::Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& Eigen::Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::operator=(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::Matrix<float, -1, 1>; _Scalar = autodiff::detail::Real<1, double>; int _Rows = -1; int _Cols = 1; int _Options = 0; int _MaxRows = -1; int _MaxCols = 1]’ /home/administrator/volesti/examples/Experiment/simple_hmc.cpp:283:5: required from here /usr/include/eigen3/Eigen/src/Core/util/XprHelper.h:819:96: error: static assertion failed: YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY 819 | gen::internal::has_ReturnType<ScalarBinaryOpTraits<LHS, RHS,BINOP> >::value), \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~ /usr/include/eigen3/Eigen/src/Core/util/StaticAssert.h:33:54: note: in definition of macro ‘EIGEN_STATIC_ASSERT’ 33 | #define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG); | ^ /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:834:3: note: in expansion of macro ‘EIGEN_CHECK_BINARY_COMPATIBILIY’ 834 | EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename ActualDstTypeCleaned::Scalar,typename Src::Scalar); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ make[2]: *** [CMakeFiles/simple_hmc.dir/build.make:76: CMakeFiles/simple_hmc.dir/simple_hmc.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:223: CMakeFiles/simple_hmc.dir/all] Error 2 make: *** [Makefile:91: all] Error 2 Ultimately i want to different wrt x of Eigen::Matrix<T ,Eigen::Dynamic,1> type where is T is a type supplied by user at compile time. The current Autodiff::real only support double and there is no way to support other data types as well.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
If you check the implementation of using realf = Real<1, float>; You'll need to use Eigen types with |
Beta Was this translation helpful? Give feedback.
If you check the implementation of
Real
, you'll see that the underlying floating point type is a template type (T
). So, you can achieve what you want withfloat
(or any other type).You'll need to use Eigen types with
float
too. Maybe create new aliases for them.