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

bool Matrix Comparison

Tags: None
(comma "," separated)
keithgould
Registered Member
Posts
2
Karma
0

bool Matrix Comparison

Sat Sep 21, 2013 6:40 pm
I'm trying to do comparison of two matrices. I'd like a bool result. The code I have feels hacky, and suspect there is a much cleaner way. Thank you for any help!

typedef Eigen::Array<bool, Eigen::Dynamic, Eigen::Dynamic> ArrayXb;

TEST(hammimg, generator_matrix)
{
ArrayXb correct_gm(4,7);

// here is what we are testing against
correct_gm << 0,1,1,1,0,0,0,
1,0,1,0,1,0,0,
1,1,0,0,0,1,0,
1,1,1,0,0,0,1;

// in the generator we we create the generator matrix
Hamming ham(parity_bits);

// hack starts here. I use a resultant matrix for the == operation
// and make sure it is all ones....
ArrayXXb all_ones(4,7);
all_ones = correct_gm == ham.generator_matrix;
ASSERT_EQ(true, all_ones.isOnes());
}
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: bool Matrix Comparison

Sat Sep 28, 2013 8:23 pm
The best is to use .all():
Code: Select all
assert( (correct_gm == ham.generator_matrix).all() );


Bookmarks



Who is online

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