-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b1a83f
commit 5fb2596
Showing
10 changed files
with
88 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef EIGEN_CHECKS_GTEST_H_ | ||
#define EIGEN_CHECKS_GTEST_H_ | ||
#include <eigen-checks/internal/gtest-equal.h> | ||
|
||
#define EIGEN_MATRIX_EQUAL(MatrixA, MatrixB) \ | ||
eigen_checks::internal::matricesNear(MatrixA, #MatrixA, MatrixB, #MatrixB,\ | ||
static_cast<decltype(MatrixA)::Scalar>(0.0)); | ||
|
||
#define EIGEN_MATRIX_EQUAL_DOUBLE(MatrixA, MatrixB) \ | ||
eigen_checks::internal::matricesNear(MatrixA, #MatrixA, MatrixB, #MatrixB, \ | ||
eigen_checks::internal::kDefaultPrecision); | ||
|
||
#define EIGEN_MATRIX_NEAR(MatrixA, MatrixB, Precision) \ | ||
eigen_checks::internal::matricesNear(MatrixA, #MatrixA, MatrixB, #MatrixB, \ | ||
Precision); | ||
|
||
#endif // EIGEN_CHECKS_GTEST_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#ifndef EIGEN_CHECKS_INTERNAL_GTEST_H_ | ||
#define EIGEN_CHECKS_INTERNAL_GTEST_H_ | ||
|
||
#include <Eigen/Dense> | ||
#include <gtest/gtest.h> | ||
|
||
namespace eigen_checks { | ||
namespace internal { | ||
constexpr double kDefaultPrecision = 1e-20; | ||
|
||
template<typename LHSMatrix, typename RHSMatrix> | ||
::testing::AssertionResult matricesEqual( | ||
const Eigen::MatrixBase<LHSMatrix>& lhs, | ||
const std::string& name_lhs, | ||
const Eigen::MatrixBase<RHSMatrix>& rhs, | ||
const std::string& name_rhs, | ||
typename Eigen::MatrixBase<LHSMatrix>::Scalar tolerance) { | ||
if (lhs.rows() != rhs.rows()) { | ||
::testing::AssertionResult failure_reason(false); | ||
failure_reason << "Matrices have a different number of rows: " | ||
<< name_lhs << " has " << lhs.rows() << " rows while " << name_rhs | ||
<< " has " << rhs.rows() << " rows." << std::endl; | ||
return failure_reason; | ||
} | ||
if (lhs.cols() != rhs.cols()) { | ||
::testing::AssertionResult failure_reason(false); | ||
failure_reason << "Matrices have a different number of cols: " | ||
<< name_lhs << " has " << lhs.cols() << " cols while " << name_rhs | ||
<< " cols " << rhs.cols() << " cols." << std::endl; | ||
return failure_reason; | ||
} | ||
|
||
if (lhs.isApprox(rhs, tolerance)) { | ||
return ::testing::AssertionSuccess(); | ||
} else { | ||
::testing::AssertionResult failure_reason(false); | ||
for (int i = 0; i < lhs.rows(); ++i) { | ||
for (int j = 0; j < lhs.cols(); ++j) { | ||
const double& lij = lhs(i, j); | ||
const double& rij = rhs(i, j); | ||
if (!std::isfinite(lij) || | ||
!std::isfinite(rij) || | ||
!Eigen::internal::isApprox(lij, rij, tolerance)) { | ||
if (lhs.rows() == 1) { | ||
failure_reason << | ||
"\nMismatch at position " << j << ": " << lij << " != " << lij; | ||
} else if (lhs.cols() == 1) { | ||
failure_reason << | ||
"\nMismatch at position " << i << ": " << lij << " != " << rij; | ||
} else { | ||
failure_reason << "\nMismatch at " | ||
<< i << "," << j << ": " << lij << " != " << rij; | ||
} | ||
} | ||
} | ||
} | ||
failure_reason << "\n"; | ||
return failure_reason; | ||
} | ||
} | ||
} // namespace internal | ||
} // namespace eigen_checks | ||
#endif // EIGEN_CHECKS_INTERNAL_GTEST_H_ |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#include <eigen-checks/entrypoint.h> | ||
#include <eigen-checks/gtest.h> | ||
|
||
|
||
|
||
|
File renamed without changes.