21 #include <gtest/gtest.h> 28 const double dat_A[] = {4, 5, 8, -2, 1, 3};
29 const double dat_B[] = {2, 6, 9, 8};
30 const double dat_Cok[] = {53, 64, -2, 32, 29, 30};
32 #define CHECK_AND_RET_ERROR(_COND_, _MSG_) EXPECT_FALSE(_COND_) << _MSG_; 34 TEST(Matrices, A_times_B_dyn)
42 EXPECT_NEAR(0, fabs(err.sum()), 1e-5) <<
"A: " << A <<
"B: " << B
43 <<
"A*B: " << C << endl;
46 TEST(Matrices, A_times_B_fix)
56 EXPECT_NEAR(0, fabs(Err.sum()), 1e-5) <<
"A: " << A <<
"B: " << B
57 <<
"A*B: " << C << endl;
60 TEST(Matrices, SerializeCMatrixD)
83 GTEST_FAIL() <<
"Exception not launched when it was expected!";
90 TEST(Matrices, EigenVal2x2dyn)
92 const double dat_C1[] = {14.6271, 5.8133, 5.8133, 16.8805};
95 Eigen::MatrixXd C1_V, C1_D;
96 C1.eigenVectors(C1_V, C1_D);
99 EXPECT_NEAR((C1_RR - C1).array().abs().
sum(), 0, 1e-4);
104 const double dat_C1[] = {8, 6, 1, 6, 9, 4, 1, 4, 10};
107 Eigen::MatrixXd C1_V, C1_D;
108 C1.eigenVectors(C1_V, C1_D);
111 EXPECT_NEAR((C1_RR - C1).array().abs().
sum(), 0, 1e-4);
116 const double dat_C1[] = {14.6271, 5.8133, 5.8133, 16.8805};
119 Eigen::Matrix2d C1_V, C1_D;
120 C1.eigenVectors(C1_V, C1_D);
123 EXPECT_NEAR((C1_RR - C1).array().abs().
sum(), 0, 1e-4);
128 const double dat_C1[] = {8, 6, 1, 6, 9, 4, 1, 4, 10};
132 C1.eigenVectors(C1_V, C1_D);
135 EXPECT_NEAR((C1_RR - C1).array().abs().
sum(), 0, 1e-4);
138 #if 0 // JL: Disabled since it fails in some PPA build servers. Reported to 142 TEST(Matrices,EigenVal4x4_sym_vs_generic)
144 const double dat_C1[] = {
145 13.737245,10.248641,-5.839599,11.108320,
146 10.248641,14.966139,-5.259922,11.662222,
147 -5.839599,-5.259922,9.608822,-4.342505,
148 11.108320,11.662222,-4.342505,12.121940 };
154 C1.eigenVectorsVec(eigvecs_gen,eigvals_gen);
155 C1.eigenVectorsSymmetricVec(eigvecs_sym,eigvals_sym);
157 eigvals_symM.setZero();eigvals_symM.diagonal() = eigvals_sym;
158 eigvals_genM.setZero();eigvals_genM.diagonal() = eigvals_gen;
160 EXPECT_NEAR( (C1-eigvecs_gen*eigvals_genM*(~eigvecs_gen)).array().abs().
sum(),0,1e-5)
162 <<
"eigvecs_gen*eigvals_gen*(~eigvecs_gen):\n" << eigvecs_gen*eigvals_genM*(~eigvecs_gen) << endl
163 <<
"C1:\n" << C1 << endl
164 <<
"eigvals_sym:\n" << eigvals_sym << endl
165 <<
"eigvals_gen:\n" << eigvals_gen << endl
166 <<
"eigvals_symM:\n" << eigvals_symM << endl
167 <<
"eigvals_genM:\n" << eigvals_genM << endl
168 <<
"eigvecs_gen:\n" << eigvecs_gen << endl
169 <<
"eigvecs_sym:\n" << eigvecs_sym << endl<< endl;
171 EXPECT_NEAR( (C1-eigvecs_sym*eigvals_symM*(~eigvecs_sym)).array().abs().
sum(),0,1e-5)
173 <<
"eigvecs_sym*eigvals_sym*(~eigvecs_sym):\n" << eigvecs_sym*eigvals_symM*(~eigvecs_sym) << endl
174 <<
"C1:\n" << C1 << endl;
176 EXPECT_NEAR( (eigvals_gen-eigvals_sym).array().abs().
sum(),0,1e-5)
178 <<
"eigvals_gen:\n" << eigvals_gen<< endl
179 <<
"eigvals_sym:\n" << eigvals_sym << endl;
A namespace of pseudo-random numbers generators of diferent distributions.
This class is a "CSerializable" wrapper for "CMatrixTemplateNumeric<double>".
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT's CStream, std::istream, std::ostream, std::stringstream
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.
uint64_t Seek(int64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning) override
Introduces a pure virtual method for moving to a specified position in the streamed resource...
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.