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

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -