7 #include <gtest/gtest.h> 10 #define ASSERT_MATRICES_EQ_WITH_NAN(first, second) assertMatrixesEqualWithNan((first), #first, (second), #second, __LINE__) 12 Eigen::Ref<const Eigen::MatrixXf> second, std::string secondName,
int line) {
13 ASSERT_EQ(first.rows(), second.rows());
14 ASSERT_EQ(first.cols(), second.cols());
16 bool matricesAreEqual =
true;
17 for (
Eigen::Index row = 0; row < first.rows() && matricesAreEqual; ++row) {
18 for (
Eigen::Index col = 0; col < first.cols() && matricesAreEqual; ++col) {
19 bool ifRealThenValid = first.block<1, 1>(row, col).isApprox(second.block<1, 1>(row, col));
20 bool bothNaN = std::isnan(first(row, col)) && std::isnan(second(row, col));
21 if (ifRealThenValid || bothNaN) {
24 matricesAreEqual =
false;
29 Eigen::IOFormat compactFormat(2, 0,
",",
"\n",
"[",
"]");
30 ASSERT_TRUE(matricesAreEqual)
31 <<
"L. " << std::to_string(line) <<
": Matrices are not equal" 34 << first.format(compactFormat) <<
"\n" 36 << second.format(compactFormat) <<
"\n";
static void assertMatrixesEqualWithNan(Eigen::Ref< const Eigen::MatrixXf > first, std::string firstName, Eigen::Ref< const Eigen::MatrixXf > second, std::string secondName, int line)