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

coefficientWise evaluations?

Tags: None
(comma "," separated)
HeadsDownCoder
Registered Member
Posts
4
Karma
0
OS

coefficientWise evaluations?

Tue Jan 24, 2012 6:47 am
Is there an efficient Eigen way of doing the following?

I need to examine a matrix coefficientWise for values great than zero and assign a zero or 1 to a corresponding element in a new matrix

Code: Select all
for (x = 0; x < numRows; x++)
   {
     for (x = 0; x < numRows; x++)
        {
       if (mtxfCold( x, z ) > 0)
       {
         mtxfBinary( x, z ) = 1;
       }
       else
       {
         mtxfBinary( x, z ) = 0;
       }
    }
  }




It seems I read some where something like this might be possible:

mtxfBinary = (mtxfCold > 0).somefunction();

Thanks
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: coefficientWise evaluations?

Tue Jan 24, 2012 7:33 am
for instance:

MatrixXd mtxfBinary;
mtxfBinary = (mtxCold > 0).cast<double>()

replace double by the scalar type you like, (mtxCold > 0) returns an expression of double.
HeadsDownCoder
Registered Member
Posts
4
Karma
0
OS

Re: coefficientWise evaluations?

Tue Jan 24, 2012 7:49 am
Thx ggael,

I tried this since both matricies were floats

mtxfBinary = ( mtxfCorrelation > 0).cast<float>();

However I'm getting compile errors after that implementation:

error C2784: 'bool std::operator >(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)' : could not deduce template argument for 'const std::unique_ptr<_Ty,_Dx> &' from 'Eigen::MatrixXf'
1> c:\Program Files\Microsoft Visual Studio 10.0\VC\include\memory(2602) : see declaration of 'std::operator >'


First in a series of about 60 of them. Would this be a MSVS 2010 compiler issue?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: coefficientWise evaluations?

Tue Jan 24, 2012 7:55 am
oh, you need to go to the array world for such comparisons: dest = (mat.array() > 0).cast<float>();
HeadsDownCoder
Registered Member
Posts
4
Karma
0
OS

Re: coefficientWise evaluations?

Wed Jan 25, 2012 6:31 am
Thank you ggael, works great.


Bookmarks



Who is online

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