39 #include <visp3/core/vpConfig.h>
41 #ifdef VISP_HAVE_CATCH2
44 #include <visp3/core/vpMatrix.h>
46 #define CATCH_CONFIG_RUNNER
49 #ifdef ENABLE_VISP_NAMESPACE
57 bool areEqual = (rowsA == rowsB) && (colsA == colsB);
63 for (
unsigned int r = 0; r < rowsA; ++r) {
64 for (
unsigned int c = 0; c < colsA; ++c) {
75 const std::string &title,
const bool &verbose)
78 std::cout <<
"-------------------------" << std::endl;
79 std::cout <<
"Test: " << title << std::endl;
80 std::cout << std::endl;
82 unsigned int gtRows = gtResult.
getRows(), resRows = result.
getRows();
83 unsigned int gtCols = gtResult.
getCols(), resCols = result.
getCols();
84 bool areEqual = (gtRows == resRows) && (gtCols == resCols);
87 std::cout <<
"Failed: dimensions mismatch (" << gtRows <<
" x " << gtCols <<
")";
88 std::cout <<
" vs (" << resRows <<
" x " << resCols <<
")" << std::endl;
93 areEqual = equal(gtResult, result);
95 if ((!areEqual) && verbose) {
96 std::cout <<
"Failed: L matrices differ." << std::endl;
97 std::cout <<
"Result =\n" << result << std::endl;
98 std::cout <<
"GT =\n" << gtResult << std::endl;
103 areEqual = equal(M, LLt);
105 if ((!areEqual) && verbose) {
106 std::cout <<
"Failed: LL^T differ from M." << std::endl;
107 std::cout <<
"LL^T =\n" << LLt << std::endl;
108 std::cout <<
"GT M =\n" << M << std::endl;
110 if (areEqual && verbose) {
111 std::cout <<
"Test " << title <<
" succeeded" << std::endl;
118 TEST_CASE(
"3 x 3 input",
"[cholesky]")
121 M[0][0] = 4; M[0][1] = 12; M[0][2] = -16;
122 M[1][0] = 12; M[1][1] = 37; M[1][2] = -43;
123 M[2][0] = -16; M[2][1] = -43; M[2][2] = 98;
127 gtL[1][0] = 6; gtL[1][1] = 1;
128 gtL[2][0] = -8; gtL[2][1] = 5; gtL[2][2] = 3;
130 #if defined(VISP_HAVE_LAPACK)
134 CHECK(testCholeskyDecomposition(M, gtL, L,
"Test 1 Cholesky's decomposition using Lapack",
true));
138 #if defined(VISP_HAVE_EIGEN3)
142 CHECK(testCholeskyDecomposition(M, gtL, L,
"Test Cholesky's decomposition using Eigen3",
true));
146 #if defined(VISP_HAVE_OPENCV)
150 CHECK(testCholeskyDecomposition(M, gtL, L,
"Test Cholesky's decomposition using OpenCV",
true));
155 TEST_CASE(
"4 x 4 input",
"[cholesky]")
158 M[0][0] = 4.16; M[0][1] = -3.12; M[0][2] = 0.56; M[0][3] = -0.10;
159 M[1][0] = -3.12; M[1][1] = 5.03; M[1][2] = -0.83; M[1][3] = 1.18;
160 M[2][0] = 0.56; M[2][1] = -0.83; M[2][2] = 0.76; M[2][3] = 0.34;
161 M[3][0] = -0.10; M[3][1] = 1.18; M[3][2] = 0.34; M[3][3] = 1.18;
165 gtL[1][0] = -1.5297; gtL[1][1] = 1.6401;
166 gtL[2][0] = 0.2746; gtL[2][1] = -0.2500; gtL[2][2] = 0.7887;
167 gtL[3][0] = -0.0490; gtL[3][1] = 0.6737; gtL[3][2] = 0.6617; gtL[3][3] = 0.5347;
169 #if defined(VISP_HAVE_LAPACK)
173 CHECK(testCholeskyDecomposition(M, gtL, L,
"Test 1 Cholesky's decomposition using Lapack",
true));
177 #if defined(VISP_HAVE_EIGEN3)
181 CHECK(testCholeskyDecomposition(M, gtL, L,
"Test Cholesky's decomposition using Eigen3",
true));
185 #if defined(VISP_HAVE_OPENCV)
189 CHECK(testCholeskyDecomposition(M, gtL, L,
"Test Cholesky's decomposition using OpenCV",
true));
194 int main(
int argc,
char *argv[])
196 Catch::Session session;
199 session.applyCommandLine(argc, argv);
201 int numFailed = session.run();
213 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