21 #include <gtest/gtest.h> 30 const double dat_A[] = {4, 5, 8, -2, 1, 3};
31 const double dat_B[] = {2, 6, 9, 8};
32 const double dat_Cok[] = {53, 64, -2, 32, 29, 30};
34 #define CHECK_AND_RET_ERROR(_COND_, _MSG_) EXPECT_FALSE(_COND_) << _MSG_; 36 TEST(Matrices, A_times_B_dyn)
44 EXPECT_NEAR(0, fabs(err.sum()), 1e-5) <<
"A: " << A <<
"B: " << B
45 <<
"A*B: " << C << endl;
48 TEST(Matrices, A_times_B_fix)
58 EXPECT_NEAR(0, fabs(Err.sum()), 1e-5) <<
"A: " << A <<
"B: " << B
59 <<
"A*B: " << C << endl;
62 TEST(Matrices, SerializeCMatrixD)
84 GTEST_FAIL() <<
"Exception not launched when it was expected!";
91 TEST(Matrices, EigenVal2x2dyn)
93 const double dat_C1[] = {14.6271, 5.8133, 5.8133, 16.8805};
96 Eigen::MatrixXd C1_V, C1_D;
97 C1.eigenVectors(C1_V, C1_D);
100 EXPECT_NEAR((C1_RR - C1).array().abs().
sum(), 0, 1e-4);
105 const double dat_C1[] = {8, 6, 1, 6, 9, 4, 1, 4, 10};
108 Eigen::MatrixXd C1_V, C1_D;
109 C1.eigenVectors(C1_V, C1_D);
112 EXPECT_NEAR((C1_RR - C1).array().abs().
sum(), 0, 1e-4);
117 const double dat_C1[] = {14.6271, 5.8133, 5.8133, 16.8805};
120 Eigen::Matrix2d C1_V, C1_D;
121 C1.eigenVectors(C1_V, C1_D);
124 EXPECT_NEAR((C1_RR - C1).array().abs().
sum(), 0, 1e-4);
129 const double dat_C1[] = {8, 6, 1, 6, 9, 4, 1, 4, 10};
133 C1.eigenVectors(C1_V, C1_D);
136 EXPECT_NEAR((C1_RR - C1).array().abs().
sum(), 0, 1e-4);
139 #if 0 // JL: Disabled since it fails in some PPA build servers. Reported to 143 TEST(Matrices,EigenVal4x4_sym_vs_generic)
145 const double dat_C1[] = {
146 13.737245,10.248641,-5.839599,11.108320,
147 10.248641,14.966139,-5.259922,11.662222,
148 -5.839599,-5.259922,9.608822,-4.342505,
149 11.108320,11.662222,-4.342505,12.121940 };
155 C1.eigenVectorsVec(eigvecs_gen,eigvals_gen);
156 C1.eigenVectorsSymmetricVec(eigvecs_sym,eigvals_sym);
158 eigvals_symM.setZero();eigvals_symM.diagonal() = eigvals_sym;
159 eigvals_genM.setZero();eigvals_genM.diagonal() = eigvals_gen;
161 EXPECT_NEAR( (C1-eigvecs_gen*eigvals_genM*(~eigvecs_gen)).array().abs().
sum(),0,1e-5)
163 <<
"eigvecs_gen*eigvals_gen*(~eigvecs_gen):\n" << eigvecs_gen*eigvals_genM*(~eigvecs_gen) << endl
164 <<
"C1:\n" << C1 << endl
165 <<
"eigvals_sym:\n" << eigvals_sym << endl
166 <<
"eigvals_gen:\n" << eigvals_gen << endl
167 <<
"eigvals_symM:\n" << eigvals_symM << endl
168 <<
"eigvals_genM:\n" << eigvals_genM << endl
169 <<
"eigvecs_gen:\n" << eigvecs_gen << endl
170 <<
"eigvecs_sym:\n" << eigvecs_sym << endl<< endl;
172 EXPECT_NEAR( (C1-eigvecs_sym*eigvals_symM*(~eigvecs_sym)).array().abs().
sum(),0,1e-5)
174 <<
"eigvecs_sym*eigvals_sym*(~eigvecs_sym):\n" << eigvecs_sym*eigvals_symM*(~eigvecs_sym) << endl
175 <<
"C1:\n" << C1 << endl;
177 EXPECT_NEAR( (eigvals_gen-eigvals_sym).array().abs().
sum(),0,1e-5)
179 <<
"eigvals_gen:\n" << eigvals_gen<< endl
180 <<
"eigvals_sym:\n" << eigvals_sym << endl;
A namespace of pseudo-random numbers genrators of diferent distributions.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
This class is a "CSerializable" wrapper for "CMatrixTemplateNumeric<double>".
uint64_t Seek(uint64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning) override
Introduces a pure virtual method for moving to a specified position in the streamed resource...
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
This file implements miscelaneous matrix and matrix/vector operations, and internal functions in mrpt...
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
This CStream derived class allow using a memory buffer as a CStream.
CMatrixTemplateNumeric< double > CMatrixDouble
Declares a matrix of double numbers (non serializable).
CONTAINER::Scalar sum(const CONTAINER &v)
Computes the sum of all the elements.
TEST(Matrices, A_times_B_dyn)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
This file implements matrix/vector text and binary serialization.