39 #include <visp3/core/vpConfig.h>
41 #if defined(VISP_HAVE_CATCH2)
44 #include <visp3/core/vpMatrix.h>
46 #include <catch_amalgamated.hpp>
48 #ifdef ENABLE_VISP_NAMESPACE
56 bool areEqual = (rowsA == rowsB) && (colsA == colsB);
62 for (
unsigned int r = 0; r < rowsA; ++r) {
63 for (
unsigned int c = 0; c < colsA; ++c) {
74 const std::string &title,
const bool &verbose)
77 std::cout <<
"-------------------------" << std::endl;
78 std::cout <<
"Test: " << title << std::endl;
79 std::cout << std::endl;
81 unsigned int gtRows = gtResult.
getRows(), resRows = result.
getRows();
82 unsigned int gtCols = gtResult.
getCols(), resCols = result.
getCols();
83 bool areEqual = (gtRows == resRows) && (gtCols == resCols);
86 std::cout <<
"Failed: dimensions mismatch (" << gtRows <<
" x " << gtCols <<
")";
87 std::cout <<
" vs (" << resRows <<
" x " << resCols <<
")" << std::endl;
92 areEqual = equal(gtResult, result);
94 if ((!areEqual) && verbose) {
95 std::cout <<
"Failed: L matrices differ." << std::endl;
96 std::cout <<
"Result =\n" << result << std::endl;
97 std::cout <<
"GT =\n" << gtResult << std::endl;
102 areEqual = equal(M, LLt);
104 if ((!areEqual) && verbose) {
105 std::cout <<
"Failed: LL^T differ from M." << std::endl;
106 std::cout <<
"LL^T =\n" << LLt << std::endl;
107 std::cout <<
"GT M =\n" << M << std::endl;
109 if (areEqual && verbose) {
110 std::cout <<
"Test " << title <<
" succeeded" << std::endl;
117 TEST_CASE(
"3 x 3 input",
"[cholesky]")
120 M[0][0] = 4; M[0][1] = 12; M[0][2] = -16;
121 M[1][0] = 12; M[1][1] = 37; M[1][2] = -43;
122 M[2][0] = -16; M[2][1] = -43; M[2][2] = 98;
126 gtL[1][0] = 6; gtL[1][1] = 1;
127 gtL[2][0] = -8; gtL[2][1] = 5; gtL[2][2] = 3;
129 #if defined(VISP_HAVE_LAPACK)
133 CHECK(testCholeskyDecomposition(M, gtL, L,
"Test Cholesky's decomposition using Lapack",
true));
137 #if defined(VISP_HAVE_EIGEN3)
141 CHECK(testCholeskyDecomposition(M, gtL, L,
"Test Cholesky's decomposition using Eigen3",
true));
147 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION != 0x030100)
151 CHECK(testCholeskyDecomposition(M, gtL, L,
"Test Cholesky's decomposition using OpenCV",
true));
156 TEST_CASE(
"4 x 4 input",
"[cholesky]")
159 M[0][0] = 4.16; M[0][1] = -3.12; M[0][2] = 0.56; M[0][3] = -0.10;
160 M[1][0] = -3.12; M[1][1] = 5.03; M[1][2] = -0.83; M[1][3] = 1.18;
161 M[2][0] = 0.56; M[2][1] = -0.83; M[2][2] = 0.76; M[2][3] = 0.34;
162 M[3][0] = -0.10; M[3][1] = 1.18; M[3][2] = 0.34; M[3][3] = 1.18;
166 gtL[1][0] = -1.5297; gtL[1][1] = 1.6401;
167 gtL[2][0] = 0.2746; gtL[2][1] = -0.2500; gtL[2][2] = 0.7887;
168 gtL[3][0] = -0.0490; gtL[3][1] = 0.6737; gtL[3][2] = 0.6617; gtL[3][3] = 0.5347;
170 #if defined(VISP_HAVE_LAPACK)
174 CHECK(testCholeskyDecomposition(M, gtL, L,
"Test Cholesky's decomposition using Lapack",
true));
178 #if defined(VISP_HAVE_EIGEN3)
182 CHECK(testCholeskyDecomposition(M, gtL, L,
"Test Cholesky's decomposition using Eigen3",
true));
188 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION != 0x030100)
192 CHECK(testCholeskyDecomposition(M, gtL, L,
"Test Cholesky's decomposition using OpenCV",
true));
197 int main(
int argc,
char *argv[])
199 Catch::Session session;
200 session.applyCommandLine(argc, argv);
201 int numFailed = session.run();
209 std::cout <<
"Test ignored: Catch2 is not available" << std::endl;
unsigned int getCols() const
unsigned int getRows() const
static bool equal(double x, double y, double threshold=0.001)
Implementation of a matrix and operations on matrices.
vpMatrix choleskyByOpenCV() const
Compute the Cholesky decomposition of a Hermitian positive-definite matrix using OpenCV library.
vpMatrix choleskyByEigen3() const
Compute the Cholesky decomposition of a Hermitian positive-definite matrix using Eigen3 library.
vpMatrix choleskyByLapack() const
Compute the Cholesky decomposition of a Hermitian positive-definite matrix using Lapack library.
vpMatrix transpose() const