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

Casting a MatrixXd to MatrixXi

Tags: None
(comma "," separated)
rkannan
Registered Member
Posts
3
Karma
0

Casting a MatrixXd to MatrixXi

Wed Jan 04, 2012 4:13 pm
I want to create a sign matrix from a dense matrix. A sign matrix S of a matrix A is one with coefficients +1 or -1, depending on whether the corresponding coeffs in A is positive or negative, i.e.

S(i,j) = 1 if A(i,j)>0 else S(i,j) = -1

I thought I could do this to generate one:
Eigen::MatrixXd A(n, m);
// initialize entries
Eigen::MatrixXi S(n, m);
S = (A.cwiseQuotient(A.cwiseAbs())).cast<Eigen::MatrixXi>();

but it refuses to compile with YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY.

which in itself is quite a helpful error.

Do I need to do anything differently or does something need implementing somewhere?

Thanks

Last edited by rkannan on Wed Jan 04, 2012 4:45 pm, edited 1 time in total.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Casting a MatrixXd to MatrixXi

Wed Jan 04, 2012 4:44 pm
in short:

(blabla).cast<int>();
rkannan
Registered Member
Posts
3
Karma
0

Re: Casting a MatrixXd to MatrixXi

Wed Jan 04, 2012 5:25 pm
Thanks ggael.


Bookmarks



Who is online

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