This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Casting different numeric types

Tags: None
(comma "," separated)
vernal
Registered Member
Posts
37
Karma
0

Casting different numeric types

Mon Sep 27, 2010 1:13 pm
Hi all,

I want to cast an Eigen::MatrixXi (containing ints) to a matrix containing doubles.

When I do
Code: Select all
myintmatrix.cast<double>()
it yields an
Code: Select all
YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY
error.
Although the error is quite verbose (kudos to the devs, it's generally helpful), I can't solve it. I tried
Code: Select all
myintmatrix.base().cast<double>()
hoping that would be the cast method of MatrixBase, but I get the same error.

So how can I use an integer matrix as if it contained doubles?
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: Casting different numeric types

Mon Sep 27, 2010 1:20 pm
This error means that you are using this matrix in a larger expressions that expects a different type. Just the snippet you showed here is not enough to help you --- the problem is not there. Can you please make a compilable test case?


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
vernal
Registered Member
Posts
37
Karma
0
Thank you! You are right, the problem is not where I thought it would be. :<
Now I have to check, where the problem lies. Should I be unable to solve it, I'll post back.

EDIT
I found the error: A matrix that should've been MatrixXd was of type MatrixXi. Whoops. Sorry for the noise...


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]