c++ - Error mixing types with Eigen matrices -
there no quick find answer see on stack problem thought add one.
say have following example code c++ eigen library:
eigen::matrix4d m1; eigen::matrix4f m2; m1 << 1, 2, 3, 4 ... 16 m2 = m1; //compile error here.
i compile error on final line boils down this:
you_mixed_different_numeric_types__you_need_to_use_the_cast_method_of_matrixbase_to_cast_numeric_types_explicitly
what easy way fix this?
so way fix took me annoyingly long time find use derived cast
method described here. definition this:
internal::cast_return_type<derived,const cwiseunaryop<internal::scalar_cast_op<typenameinternal::traits<derived>::scalar, newtype>, const derived> >::type cast() const
which ill admit, phased me little. turns out pretty easy (and explanation find in eigen 2.0 doc frustrating). need this:
m2 = m1.cast<float>();
problem solved.
Comments
Post a Comment