38#include <visp3/core/vpConfig.h>
40#if defined(VISP_HAVE_CATCH2)
42#include <catch_amalgamated.hpp>
44#include <visp3/core/vpMatrix.h>
46#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x030000)
47#include <opencv2/core.hpp>
50#ifdef VISP_HAVE_EIGEN3
54#ifdef ENABLE_VISP_NAMESPACE
61bool runBenchmark =
false;
62bool runBenchmarkAll =
false;
64double getRandomValues(
double min,
double max) {
return (max - min) * (
static_cast<double>(rand()) /
static_cast<double>(RAND_MAX)) + min; }
66vpMatrix generateRandomMatrix(
unsigned int rows,
unsigned int cols,
double min = -1,
double max = 1)
70 for (
unsigned int i = 0;
i < M.getRows();
i++) {
71 for (
unsigned int j = 0;
j < M.getCols();
j++) {
72 M[
i][
j] = getRandomValues(min, max);
79vpColVector generateRandomVector(
unsigned int rows,
double min = -1,
double max = 1)
83 for (
unsigned int i = 0;
i <
v.getRows();
i++) {
84 v[
i] = getRandomValues(min, max);
105 unsigned int BcolNum = B.
getCols();
106 unsigned int BrowNum = B.
getRows();
107 unsigned int i,
j, k;
109 double *rowptri = A[
i];
111 for (j = 0;
j < BcolNum;
j++) {
113 for (k = 0; k < BrowNum; k++) {
114 s += rowptri[k] * B[k][
j];
129 for (
unsigned int i = 0;
i < A.
getCols();
i++) {
131 for (
unsigned int j = 0;
j <
i;
j++) {
132 double *ptr = A.
data;
134 for (
unsigned int k = 0; k < A.
getRows(); k++) {
135 s += (*(ptr +
i)) * (*(ptr + j));
141 double *ptr = A.
data;
143 for (
unsigned int k = 0; k < A.
getRows(); k++) {
144 s += (*(ptr +
i)) * (*(ptr + i));
160 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
161 for (
unsigned int j = i;
j < A.
getRows();
j++) {
167 for (
unsigned int k = 0; k < A.
getCols(); k++)
168 ssum += *(pi++) * *(pj++);
190 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
192 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
193 w[
i] += A[
i][
j] * vj;
206 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
207 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
219TEST_CASE(
"Benchmark matrix-matrix multiplication",
"[benchmark]")
221 if (runBenchmark || runBenchmarkAll) {
222 std::vector<std::pair<int, int> > sizes = { {3, 3}, {6, 6}, {8, 8}, {10, 10}, {20, 20}, {6, 200},
223 {200, 6}, {207, 119}, {83, 201}, {600, 400}, {400, 600} };
225 for (
auto sz : sizes) {
226 vpMatrix A = generateRandomMatrix(sz.first, sz.second);
227 vpMatrix B = generateRandomMatrix(sz.second, sz.first);
229 std::ostringstream oss;
232 BENCHMARK(oss.str().c_str())
234 C_true = dgemm_regular(A, B);
240 BENCHMARK(oss.str().c_str())
245 REQUIRE(equalMatrix(C, C_true));
247 if (runBenchmarkAll) {
248#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x030000)
249 cv::Mat matA(sz.first, sz.second, CV_64FC1);
250 cv::Mat matB(sz.second, sz.first, CV_64FC1);
252 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
253 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
254 matA.at<
double>(
i,
j) = A[i][j];
255 matB.at<
double>(
j,
i) = B[j][i];
260 oss <<
"(" << matA.rows <<
"x" << matA.cols <<
")x(" << matB.rows <<
"x" << matB.cols <<
") - OpenCV";
261 BENCHMARK(oss.str().c_str())
263 cv::Mat matC = matA * matB;
268#ifdef VISP_HAVE_EIGEN3
269 Eigen::MatrixXd eigenA(sz.first, sz.second);
270 Eigen::MatrixXd eigenB(sz.second, sz.first);
272 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
273 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
274 eigenA(i, j) = A[
i][
j];
275 eigenB(j, i) = B[
j][
i];
280 oss <<
"(" << eigenA.rows() <<
"x" << eigenA.cols() <<
")x(" << eigenB.rows() <<
"x" << eigenB.cols()
282 BENCHMARK(oss.str().c_str())
284 Eigen::MatrixXd eigenC = eigenA * eigenB;
293 const unsigned int rows = 47, cols = 63;
294 vpMatrix A = generateRandomMatrix(rows, cols);
295 vpMatrix B = generateRandomMatrix(cols, rows);
297 vpMatrix C_true = dgemm_regular(A, B);
299 REQUIRE(equalMatrix(C, C_true));
303TEST_CASE(
"Benchmark matrix-rotation matrix multiplication",
"[benchmark]")
305 if (runBenchmark || runBenchmarkAll) {
306 std::vector<std::pair<int, int> > sizes = { {3, 3} };
308 for (
auto sz : sizes) {
309 vpMatrix A = generateRandomMatrix(sz.first, sz.second);
313 std::ostringstream oss;
316 BENCHMARK(oss.str().c_str())
318 AB_true = dgemm_regular(A,
static_cast<vpMatrix>(B));
324 BENCHMARK(oss.str().c_str())
329 REQUIRE(equalMatrix(AB, AB_true));
331 if (runBenchmarkAll) {
332#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x030000)
333 cv::Mat matA(sz.first, sz.second, CV_64FC1);
334 cv::Mat matB(3, 3, CV_64FC1);
336 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
337 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
338 matA.at<
double>(
i,
j) = A[i][j];
341 for (
unsigned int i = 0;
i < B.
getRows();
i++) {
342 for (
unsigned int j = 0;
j < B.
getCols();
j++) {
343 matB.at<
double>(
j,
i) = B[j][i];
348 oss <<
"(" << matA.rows <<
"x" << matA.cols <<
")x(" << matB.rows <<
"x" << matB.cols <<
") - OpenCV";
349 BENCHMARK(oss.str().c_str())
351 cv::Mat matC = matA * matB;
356#ifdef VISP_HAVE_EIGEN3
357 Eigen::MatrixXd eigenA(sz.first, sz.second);
358 Eigen::MatrixXd eigenB(3, 3);
360 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
361 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
362 eigenA(i, j) = A[
i][
j];
365 for (
unsigned int i = 0;
i < B.
getRows();
i++) {
366 for (
unsigned int j = 0;
j < B.
getCols();
j++) {
367 eigenB(j, i) = B[
j][
i];
372 oss <<
"(" << eigenA.rows() <<
"x" << eigenA.cols() <<
")x(" << eigenB.rows() <<
"x" << eigenB.cols()
374 BENCHMARK(oss.str().c_str())
376 Eigen::MatrixXd eigenC = eigenA * eigenB;
385 const unsigned int rows = 3, cols = 3;
386 vpMatrix A = generateRandomMatrix(rows, cols);
392 REQUIRE(equalMatrix(AB, AB_true));
396TEST_CASE(
"Benchmark rotation matrix-matrix multiplication",
"[benchmark]")
398 if (runBenchmark || runBenchmarkAll) {
399 std::vector<std::pair<int, int> > sizes = { {3, 3} };
401 for (
auto sz : sizes) {
404 vpMatrix B = generateRandomMatrix(sz.first, sz.second);
406 std::ostringstream oss;
409 BENCHMARK(oss.str().c_str())
411 AB_true = dgemm_regular(
static_cast<vpMatrix>(A), B);
417 BENCHMARK(oss.str().c_str())
422 REQUIRE(equalMatrix(AB, AB_true));
424 if (runBenchmarkAll) {
425#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x030000)
426 cv::Mat matA(3, 3, CV_64FC1);
427 cv::Mat matB(sz.first, sz.second, CV_64FC1);
429 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
430 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
431 matA.at<
double>(
i,
j) = A[i][j];
434 for (
unsigned int i = 0;
i < B.
getRows();
i++) {
435 for (
unsigned int j = 0;
j < B.
getCols();
j++) {
436 matB.at<
double>(
j,
i) = B[j][i];
441 oss <<
"(" << matA.rows <<
"x" << matA.cols <<
")x(" << matB.rows <<
"x" << matB.cols <<
") - OpenCV";
442 BENCHMARK(oss.str().c_str())
444 cv::Mat matC = matA * matB;
449#ifdef VISP_HAVE_EIGEN3
450 Eigen::MatrixXd eigenA(3, 3);
451 Eigen::MatrixXd eigenB(sz.first, sz.second);
453 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
454 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
455 eigenA(i, j) = A[
i][
j];
458 for (
unsigned int i = 0;
i < B.
getRows();
i++) {
459 for (
unsigned int j = 0;
j < B.
getCols();
j++) {
460 eigenB(j, i) = B[
j][
i];
465 oss <<
"(" << eigenA.rows() <<
"x" << eigenA.cols() <<
")x(" << eigenB.rows() <<
"x" << eigenB.cols()
467 BENCHMARK(oss.str().c_str())
469 Eigen::MatrixXd eigenC = eigenA * eigenB;
478 const unsigned int rows = 3, cols = 3;
481 vpMatrix B = generateRandomMatrix(rows, cols);
485 REQUIRE(equalMatrix(AB, AB_true));
489TEST_CASE(
"Benchmark matrix-homogeneous matrix multiplication",
"[benchmark]")
491 if (runBenchmark || runBenchmarkAll) {
492 std::vector<std::pair<int, int> > sizes = { {4, 4} };
494 for (
auto sz : sizes) {
495 vpMatrix A = generateRandomMatrix(sz.first, sz.second);
500 std::ostringstream oss;
503 BENCHMARK(oss.str().c_str())
505 AB_true = dgemm_regular(A,
static_cast<vpMatrix>(B));
511 BENCHMARK(oss.str().c_str())
516 REQUIRE(equalMatrix(AB, AB_true));
518 if (runBenchmarkAll) {
519#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x030000)
520 cv::Mat matA(sz.first, sz.second, CV_64FC1);
521 cv::Mat matB(4, 4, CV_64FC1);
523 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
524 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
525 matA.at<
double>(
i,
j) = A[i][j];
528 for (
unsigned int i = 0;
i < B.
getRows();
i++) {
529 for (
unsigned int j = 0;
j < B.
getCols();
j++) {
530 matB.at<
double>(
j,
i) = B[j][i];
535 oss <<
"(" << matA.rows <<
"x" << matA.cols <<
")x(" << matB.rows <<
"x" << matB.cols <<
") - OpenCV";
536 BENCHMARK(oss.str().c_str())
538 cv::Mat matC = matA * matB;
543#ifdef VISP_HAVE_EIGEN3
544 Eigen::MatrixXd eigenA(sz.first, sz.second);
545 Eigen::MatrixXd eigenB(4, 4);
547 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
548 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
549 eigenA(i, j) = A[
i][
j];
552 for (
unsigned int i = 0;
i < B.
getRows();
i++) {
553 for (
unsigned int j = 0;
j < B.
getCols();
j++) {
554 eigenB(j, i) = B[
j][
i];
559 oss <<
"(" << eigenA.rows() <<
"x" << eigenA.cols() <<
")x(" << eigenB.rows() <<
"x" << eigenB.cols()
561 BENCHMARK(oss.str().c_str())
563 Eigen::MatrixXd eigenC = eigenA * eigenB;
572 const unsigned int rows = 4, cols = 4;
573 vpMatrix A = generateRandomMatrix(rows, cols);
581 REQUIRE(equalMatrix(AB, AB_true));
585TEST_CASE(
"Benchmark matrix-vector multiplication",
"[benchmark]")
587 if (runBenchmark || runBenchmarkAll) {
588 std::vector<std::pair<int, int> > sizes = { {3, 3}, {6, 6}, {8, 8}, {10, 10}, {20, 20}, {6, 200},
589 {200, 6}, {207, 119}, {83, 201}, {600, 400}, {400, 600} };
591 for (
auto sz : sizes) {
592 vpMatrix A = generateRandomMatrix(sz.first, sz.second);
595 std::ostringstream oss;
598 BENCHMARK(oss.str().c_str())
600 C_true = dgemv_regular(A,
static_cast<vpColVector>(B));
606 BENCHMARK(oss.str().c_str())
611 REQUIRE(equalMatrix(
static_cast<vpMatrix>(C),
static_cast<vpMatrix>(C_true)));
613 if (runBenchmarkAll) {
614#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x030000)
615 cv::Mat matA(sz.first, sz.second, CV_64FC1);
616 cv::Mat matB(sz.second, 1, CV_64FC1);
618 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
619 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
620 matA.at<
double>(
i,
j) = A[i][j];
622 matB.at<
double>(
j, 0) = B[j];
628 oss <<
"(" << matA.rows <<
"x" << matA.cols <<
")x(" << matB.rows <<
"x" << matB.cols <<
") - OpenCV";
629 BENCHMARK(oss.str().c_str())
631 cv::Mat matC = matA * matB;
636#ifdef VISP_HAVE_EIGEN3
637 Eigen::MatrixXd eigenA(sz.first, sz.second);
638 Eigen::MatrixXd eigenB(sz.second, 1);
640 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
641 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
642 eigenA(i, j) = A[
i][
j];
650 oss <<
"(" << eigenA.rows() <<
"x" << eigenA.cols() <<
")x(" << eigenB.rows() <<
"x" << eigenB.cols()
652 BENCHMARK(oss.str().c_str())
654 Eigen::MatrixXd eigenC = eigenA * eigenB;
663 const unsigned int rows = 47, cols = 63;
664 vpMatrix A = generateRandomMatrix(rows, cols);
669 REQUIRE(equalMatrix(
static_cast<vpMatrix>(C),
static_cast<vpMatrix>(C_true)));
673TEST_CASE(
"Benchmark AtA",
"[benchmark]")
675 if (runBenchmark || runBenchmarkAll) {
676 std::vector<std::pair<int, int> > sizes = { {3, 3}, {6, 6}, {8, 8}, {10, 10}, {20, 20}, {6, 200},
677 {200, 6}, {207, 119}, {83, 201}, {600, 400}, {400, 600} };
679 for (
auto sz : sizes) {
680 vpMatrix A = generateRandomMatrix(sz.first, sz.second);
682 std::ostringstream oss;
683 oss <<
"(" << A.
getRows() <<
"x" << A.
getCols() <<
") - Naive code";
685 BENCHMARK(oss.str().c_str())
687 AtA_true = AtA_regular(A);
693 BENCHMARK(oss.str().c_str())
698 REQUIRE(equalMatrix(AtA, AtA_true));
700 if (runBenchmarkAll) {
701#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x030000)
702 cv::Mat matA(sz.first, sz.second, CV_64FC1);
704 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
705 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
706 matA.at<
double>(
i,
j) = A[i][j];
711 oss <<
"(" << matA.rows <<
"x" << matA.cols <<
") - OpenCV";
712 BENCHMARK(oss.str().c_str())
714 cv::Mat matAtA = matA.t() * matA;
719#ifdef VISP_HAVE_EIGEN3
720 Eigen::MatrixXd eigenA(sz.first, sz.second);
722 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
723 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
724 eigenA(i, j) = A[
i][
j];
729 oss <<
"(" << eigenA.rows() <<
"x" << eigenA.cols() <<
") - Eigen";
730 BENCHMARK(oss.str().c_str())
732 Eigen::MatrixXd eigenAtA = eigenA.transpose() * eigenA;
741 const unsigned int rows = 47, cols = 63;
742 vpMatrix A = generateRandomMatrix(rows, cols);
746 REQUIRE(equalMatrix(AtA, AtA_true));
750TEST_CASE(
"Benchmark AAt",
"[benchmark]")
752 if (runBenchmark || runBenchmarkAll) {
753 std::vector<std::pair<int, int> > sizes = {
754 {3, 3}, {6, 6}, {8, 8}, {10, 10},
755 {20, 20}, {6, 200}, {200, 6} };
757 for (
auto sz : sizes) {
758 vpMatrix A = generateRandomMatrix(sz.first, sz.second);
760 std::ostringstream oss;
761 oss <<
"(" << A.
getRows() <<
"x" << A.
getCols() <<
") - Naive code";
763 BENCHMARK(oss.str().c_str())
765 AAt_true = AAt_regular(A);
771 BENCHMARK(oss.str().c_str())
776 REQUIRE(equalMatrix(AAt, AAt_true));
778 if (runBenchmarkAll) {
779#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x030000)
780 cv::Mat matA(sz.first, sz.second, CV_64FC1);
782 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
783 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
784 matA.at<
double>(
i,
j) = A[i][j];
789 oss <<
"(" << matA.rows <<
"x" << matA.cols <<
") - OpenCV";
790 BENCHMARK(oss.str().c_str())
792 cv::Mat matAAt = matA * matA.t();
797#ifdef VISP_HAVE_EIGEN3
798 Eigen::MatrixXd eigenA(sz.first, sz.second);
800 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
801 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
802 eigenA(i, j) = A[
i][
j];
807 oss <<
"(" << eigenA.rows() <<
"x" << eigenA.cols() <<
") - Eigen";
808 BENCHMARK(oss.str().c_str())
810 Eigen::MatrixXd eigenAAt = eigenA * eigenA.transpose();
819 const unsigned int rows = 47, cols = 63;
820 vpMatrix A = generateRandomMatrix(rows, cols);
824 REQUIRE(equalMatrix(AAt, AAt_true));
828TEST_CASE(
"Benchmark matrix-velocity twist multiplication",
"[benchmark]")
830 if (runBenchmark || runBenchmarkAll) {
831 std::vector<std::pair<int, int> > sizes = { {6, 6}, {20, 6}, {207, 6}, {600, 6}, {1201, 6} };
833 for (
auto sz : sizes) {
834 vpMatrix A = generateRandomMatrix(sz.first, sz.second);
837 std::ostringstream oss;
838 oss <<
"(" << A.
getRows() <<
"x" << A.
getCols() <<
")x(6x6) - Naive code";
840 BENCHMARK(oss.str().c_str())
842 AV_true = dgemm_regular(A,
static_cast<vpMatrix>(V));
847 oss <<
"(" << A.
getRows() <<
"x" << A.
getCols() <<
")x(6x6) - ViSP";
848 BENCHMARK(oss.str().c_str())
853 REQUIRE(equalMatrix(AV, AV_true));
855 if (runBenchmarkAll) {
856#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x030000)
857 cv::Mat matA(sz.first, sz.second, CV_64FC1);
858 cv::Mat matV(6, 6, CV_64FC1);
860 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
861 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
862 matA.at<
double>(
i,
j) = A[i][j];
865 for (
unsigned int i = 0;
i < V.getRows();
i++) {
866 for (
unsigned int j = 0;
j < V.getCols();
j++) {
867 matV.at<
double>(
i,
j) = V[i][j];
872 oss <<
"(" << matA.rows <<
"x" << matA.cols <<
")x(6x6) - OpenCV";
873 BENCHMARK(oss.str().c_str())
875 cv::Mat matAV = matA * matV;
880#ifdef VISP_HAVE_EIGEN3
881 Eigen::MatrixXd eigenA(sz.first, sz.second);
882 Eigen::MatrixXd eigenV(6, 6);
884 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
885 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
886 eigenA(i, j) = A[
i][
j];
889 for (
unsigned int i = 0;
i < V.getRows();
i++) {
890 for (
unsigned int j = 0;
j < V.getCols();
j++) {
891 eigenV(i, j) = V[
i][
j];
896 oss <<
"(" << eigenA.rows() <<
"x" << eigenA.cols() <<
")x(6x6) - Eigen";
897 BENCHMARK(oss.str().c_str())
899 Eigen::MatrixXd eigenAV = eigenA * eigenV;
908 const unsigned int rows = 47, cols = 6;
909 vpMatrix A = generateRandomMatrix(rows, cols);
914 REQUIRE(equalMatrix(AV, AV_true));
918TEST_CASE(
"Benchmark matrix-force twist multiplication",
"[benchmark]")
920 if (runBenchmark || runBenchmarkAll) {
921 std::vector<std::pair<int, int> > sizes = { {6, 6}, {20, 6}, {207, 6}, {600, 6}, {1201, 6} };
923 for (
auto sz : sizes) {
924 vpMatrix A = generateRandomMatrix(sz.first, sz.second);
927 std::ostringstream oss;
928 oss <<
"(" << A.
getRows() <<
"x" << A.
getCols() <<
")x(6x6) - Naive code";
930 BENCHMARK(oss.str().c_str())
932 AV_true = dgemm_regular(A,
static_cast<vpMatrix>(V));
937 oss <<
"(" << A.
getRows() <<
"x" << A.
getCols() <<
")x(6x6) - ViSP";
938 BENCHMARK(oss.str().c_str())
943 REQUIRE(equalMatrix(AV, AV_true));
945 if (runBenchmarkAll) {
946#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x030000)
947 cv::Mat matA(sz.first, sz.second, CV_64FC1);
948 cv::Mat matV(6, 6, CV_64FC1);
950 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
951 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
952 matA.at<
double>(
i,
j) = A[i][j];
955 for (
unsigned int i = 0;
i < V.getRows();
i++) {
956 for (
unsigned int j = 0;
j < V.getCols();
j++) {
957 matV.at<
double>(
i,
j) = V[i][j];
962 oss <<
"(" << matA.rows <<
"x" << matA.cols <<
")x(6x6) - OpenCV";
963 BENCHMARK(oss.str().c_str())
965 cv::Mat matAV = matA * matV;
970#ifdef VISP_HAVE_EIGEN3
971 Eigen::MatrixXd eigenA(sz.first, sz.second);
972 Eigen::MatrixXd eigenV(6, 6);
974 for (
unsigned int i = 0;
i < A.
getRows();
i++) {
975 for (
unsigned int j = 0;
j < A.
getCols();
j++) {
976 eigenA(i, j) = A[
i][
j];
979 for (
unsigned int i = 0;
i < V.getRows();
i++) {
980 for (
unsigned int j = 0;
j < V.getCols();
j++) {
981 eigenV(i, j) = V[
i][
j];
986 oss <<
"(" << eigenA.rows() <<
"x" << eigenA.cols() <<
")x(6x6) - Eigen";
987 BENCHMARK(oss.str().c_str())
989 Eigen::MatrixXd eigenAV = eigenA * eigenV;
998 const unsigned int rows = 47, cols = 6;
999 vpMatrix A = generateRandomMatrix(rows, cols);
1004 REQUIRE(equalMatrix(AV, AV_true));
1008int main(
int argc,
char *argv[])
1015 Catch::Session session;
1018 std::cout <<
"Default matrix/vector min size to enable Blas/Lapack optimization: " << lapackMinSize << std::endl;
1020 auto cli = session.cli()
1021 | Catch::Clara::Opt(runBenchmark)[
"--benchmark"](
"run benchmark comparing naive code with ViSP implementation")
1022 | Catch::Clara::Opt(runBenchmarkAll)[
"--benchmark-all"](
"run benchmark comparing naive code with ViSP, OpenCV, Eigen implementation")
1023 | Catch::Clara::Opt(lapackMinSize,
"min size")[
"--lapack-min-size"](
"matrix/vector min size to enable blas/lapack usage");
1026 session.applyCommandLine(argc, argv);
1032 int numFailed = session.run();
1039int main() {
return EXIT_SUCCESS; }
unsigned int getCols() const
Type * data
Address of the first element of the data array.
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
unsigned int getRows() const
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
Implementation of an homogeneous matrix and operations on such kind of matrices.
static bool equal(double x, double y, double threshold=0.001)
static double deg(double rad)
Implementation of a matrix and operations on matrices.
static void setLapackMatrixMinSize(unsigned int min_size)
static unsigned int getLapackMatrixMinSize()
static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as axis-angle minimal representation.
Class that consider the case of a translation vector.