|[eigen] Combining different types|
[ Thread Index |
| More lists.tuxfamily.org/eigen Archives
I understand that Eigen does not allow adding vectors of different
types. For example, the code
cout << (f+d) << endl;
yields the compilation error
I also understand the Eigen has this restriction because of the
difficulty (correctness?) of doing vectorization with such expressions.
However, casting a float vector to a double vector is, of course,
inefficient. Does it make sense to move the prohibition of mixing types
to be a pre-condition for vectorization, and allow the mixing of types
in general in Eigen?
A concrete situation where this is desirable is where a bunch of
parameters can be stored in a vector of floats (to save space), but the
main calculations are done in double, to maintain sufficient precision.
The following template
template< typename A, typename B >
typedef decltype( A(0) + B(0) ) type;
makes the promotion type explicit. [In my actual situation, this does
not work with a new scalar type, adouble (from ADOL-C) that I am using,
but this can be handled by writing down specializations for the above
I have been able to, largely, work around the prohibition of mixing
types with adouble by adding small amounts of code to specialize the
existing Eigen infrastructure that does the checking. However, I have
not been able to solve this definitively, for adouble, and may need to
(mildly) constrain my code, instead. It would be more elegant if Eigen,
from ground up, allowed the user the option to mix types
Any comments much appreciated ...