diff --git a/cpp/Matrix.cpp b/cpp/Matrix.cpp index 95dc1f528..074ad44a4 100644 --- a/cpp/Matrix.cpp +++ b/cpp/Matrix.cpp @@ -142,6 +142,19 @@ bool assert_equal(const Matrix& expected, const Matrix& actual, double tol) { return false; } +/* ************************************************************************* */ +bool assert_equal(const std::list& As, const std::list& Bs, double tol) { + if (As.size() != Bs.size()) return false; + + list::const_iterator itA, itB; + itA = As.begin(); itB = Bs.begin(); + for (; itA != As.end(); itA++, itB++) + if (!assert_equal(*itB, *itA, tol)) + return false; + + return true; +} + /* ************************************************************************* */ void multiplyAdd(double alpha, const Matrix& A, const Vector& x, Vector& e) { #if defined CBLAS diff --git a/cpp/Matrix.h b/cpp/Matrix.h index 7e8705901..491e6ff26 100644 --- a/cpp/Matrix.h +++ b/cpp/Matrix.h @@ -81,6 +81,11 @@ inline bool operator!=(const Matrix& A, const Matrix& B) { */ bool assert_equal(const Matrix& A, const Matrix& B, double tol = 1e-9); +/** + * equals with an tolerance, prints out message if unequal + */ +bool assert_equal(const std::list& As, const std::list& Bs, double tol = 1e-9); + /** * overload * for matrix-vector multiplication (as BOOST does not) */