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

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

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] Coercion of matrices with mixed types ?*From*: Norman Goldstein <normvcr@xxxxxxxxx>*Date*: Wed, 08 Aug 2012 08:21:07 -0700*Cc*: Brad Bell <bradbell@xxxxxxxxxx>

Firstly, I want to thank everyone for their explanations. Also, I
wish to explain why this is an issue for me, and how I have solved
it. Referring to the same two types, double and OTHER_TYPE, the
difference of the two scalars is also of type OTHER_TYPE. This is
a type of some complexity, so it would be inefficient to cast a
vector<double> to be vector<OTHER_TYPE>. Instead, I
have written my own (very simple) vector<OTHER_TYPE> operator-(const vector<double>&, const vector<OTHER_TYPE>& ) and this has resolved the issue for me (I also needed to augment some of the Eigen Traits, etc). Another aspect to this is that I do not want to include casting as a matter of course into my source code, for two reasons: -- The code is harder to read/write and resembles less the mathematics that it is implementing, and -- As a coding practice, explicit casting is frowned upon. I know very little about meta programming, so the solution I have outlined can probably be done in a better, or more efficient way, with guidelines from the Eigen experts. Thanks, again! *To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] Coercion of matrices with mixed types ?*From*: Christoph Hertzberg <chtz@xxxxxxxxxxxxxxxxxxxxxxxx>*Date*: Mon, 06 Aug 2012 10:34:10 +0200
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 ---------------------------------------------- |

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] Coercion of matrices with mixed types ?** - Next by Date:
**[eigen] Typos in "Getting Started"** - Previous by thread:
**Re: [eigen] Coercion of matrices with mixed types ?** - Next by thread:
**[eigen] Missing "const" in Transpose.h**

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