Re: [eigen] Coercion of matrices with mixed types ?

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


On 04.08.2012 16:52, Brad Bell wrote:
It appears that Eigen will not coerce matrices, even if the scalar type
does. Is this a design decision or am I missing something ?

It's a design decision.

[...]

int main(void)
{    typedef Eigen::Matrix<     double, Eigen::Dynamic, 1  > d_vector;
      typedef Eigen::Matrix< OTHER_TYPE, Eigen::Dynamic, 1  > other_vector;

      size_t n = 10;
      other_vector  u(n);
      d_vector  v(n), w(n);
[...]
      w = v - u;

You need to cast u to double here:
	w = v - u.cast<double>();

Be aware that in some cases you need to write
	u.template cast<double>(),
not in this case, though. See here:
http://eigen.tuxfamily.org/dox-devel/TopicTemplateKeyword.html



Christoph



--
----------------------------------------------
Dipl.-Inf. Christoph Hertzberg
Cartesium 0.049
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen

Tel: +49 (421) 218-64252
----------------------------------------------





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/