This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen

# Bug 1061

Summary: Product: Matrix operator== does not check for correct size and returns true for empty matrix comparisons. Eigen Simon Lynen Core - general Nobody DECISIONNEEDED --- Unknown chtz, gael.guennebaud, jacob.benoit.1 Normal Documentation 3.2 All All

 Simon Lynen 2015-08-30 00:04:35 UTC ```Operator == does not check for size and incorrectly returns true for comparison of (partically) dynamic matrix with random matrix. TEST(A, B) { typedef Eigen::Matrix Type; Type a; a.setRandom(10, 5); Type b; EXPECT_FALSE(a == b); // Fails. Type c; c.setRandom(10, 5); EXPECT_FALSE(a == c); // Passes. } TEST(A, C) { typedef Eigen::Matrix Type; Type a; a.setRandom(10, 5); Type b; EXPECT_FALSE(a == b); // Fails. Type c; c.setRandom(10, 5); EXPECT_FALSE(a == c); // Passes. }``` Christoph Hertzberg 2015-08-31 11:53:04 UTC ```So far, we had a==b be equivalent to a.cwiseEqual(b).all(), which means we assume (and assert) that the sizes match. But checking for matching sizes before that actually makes sense (and I doubt it would break anything). Should we want to keep the current behavior, we must at least document it. If we change it, we should suggest the alternative .cwiseEqual().all(), in case someone really wishes to avoid the minor overhead of checking the dimension first.``` Gael Guennebaud 2015-09-01 14:40:33 UTC ```Such a change would make operator== equivalent to Matlab's isequal behavior, so why not. Another solution would be to add a isEqual() member (and maybe even a isEqualN() to deal with NaN) mimicking Matlab's isequal*, but if we do so, then for consistency we should probably also update isApprox to check for the size first.``` Nobody 2019-12-04 14:53:30 UTC ```-- GitLab Migration Automatic Message -- This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1061.```