MRPT  2.0.0
CMatrixDynamic_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <gtest/gtest.h>
13 #include <Eigen/Dense>
14 
15 TEST(CMatrixDynamic, GetSetEigen)
16 {
17  {
19  auto em = M.asEigen();
20  em.setIdentity();
21  for (int i = 0; i < 3; i++) EXPECT_EQ(M(i, i), 1.0);
22  }
23  {
25  auto em = M.asEigen();
26  for (int i = 0; i < 3; i++)
27  for (int j = 0; j < 3; j++)
28  {
29  const auto n = ((i + 1) * 3) + (j * 1001);
30  em(i, j) = n;
31  EXPECT_NEAR(M(i, j), em(i, j), 1e-9)
32  << "(i,j)=(" << i << "," << j << ")\n";
33  }
34  }
35 }
36 TEST(CMatrixDynamic, asString)
37 {
39  M.setIdentity();
40  EXPECT_EQ(std::string("1 0\n0 1"), M.asString());
41 }
42 
43 TEST(CMatrixDynamic, CtorFromArray)
44 {
45  const double dat_R[] = {1., 2., 3., 4., 5., 6., 7., 8., 9.};
46  const mrpt::math::CMatrixDouble R(3, 3, dat_R);
47  for (int r = 0; r < 3; r++)
48  {
49  for (int c = 0; c < 3; c++)
50  {
51  EXPECT_EQ(dat_R[c + r * 3], R(r, c))
52  << "(r,c)=(" << r << "," << c << ")\n";
53 
54  // Also test access via data():
55  EXPECT_EQ(R(r, c), R.data()[c + r * 3]);
56  EXPECT_EQ(&R(r, c), &R.data()[c + r * 3]);
57  }
58  }
59 }
60 
61 // Added to run with valgrind to error checking.
62 TEST(CMatrixDynamic, Resizes)
63 {
65  {
66  CMatrixDouble M(0, 0);
67  M.resize(0, 0);
68  M.resize(1, 1);
69  M.resize(10, 10);
70  M.resize(15, 10);
71  M.resize(15, 12);
72  M.resize(5, 12);
73  M.resize(3, 2);
74  }
75  {
76  CMatrixDouble M(40, 50);
77  M.resize(3, 3);
78  }
79 }
80 
81 TEST(CVectorDynamic, segment)
82 {
84  CVectorDouble v;
85  v.resize(10);
86  for (int i = 0; i < v.size(); i++) v[i] = i;
87 
88  for (int start = 0; start < 8; start++)
89  for (int len = 1; len < v.size() - start; len++)
90  {
91  const auto s = v.segmentCopy(start, len);
92  for (int i = 0; i < s.size(); i++) EXPECT_EQ(v[i + start], s[i]);
93  }
94 }
static CMatrixDynamic< T > Identity()
Definition: MatrixBase.h:64
CVectorDynamic< double > CVectorDouble
const float R
EXPECT_EQ(out.image_pair_was_used.size(), NUM_IMGS)
void resize(std::size_t N, bool zeroNewElements=false)
EXPECT_NEAR(out.cam_params.rightCameraPose.x, 0.1194, 0.005)
EIGEN_MAP asEigen()
Get as an Eigen-compatible Eigen::Map object.
TEST(CMatrixDynamic, GetSetEigen)
CMatrixDynamic< double > CMatrixDouble
Declares a matrix of double numbers (non serializable).



Page generated by Doxygen 1.8.14 for MRPT 2.0.0 Git: b38439d21 Tue Mar 31 19:58:06 2020 +0200 at miƩ abr 1 00:50:30 CEST 2020