1061
2015-08-30 00:04:35 +0000
Matrix operator== does not check for correct size and returns true for empty matrix comparisons.
2019-12-04 14:53:30 +0000
1
1
1
Unclassified
Eigen
Core - general
3.2
All
All
DECISIONNEEDED
Documentation
Normal
Unknown
---
1
slynen
eigen.nobody
chtz
gael.guennebaud
jacob.benoit.1
oldest_to_newest
4931
0
slynen
2015-08-30 00:04:35 +0000
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<double, 10, Eigen::Dynamic> 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<double, Eigen::Dynamic, Eigen::Dynamic> 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.
}
4932
1
chtz
2015-08-31 11:53:04 +0000
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.
4939
2
gael.guennebaud
2015-09-01 14:40:33 +0000
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.
9505
3
eigen.nobody
2019-12-04 14:53:30 +0000
-- 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.