21 #include <gtest/gtest.h> 31 const double dat_A[] = { 4, 5, 8, -2, 1, 3 };
32 const double dat_B[] = { 2, 6, 9, 8 };
33 const double dat_Cok[] = {53,64, -2,32, 29,30 };
36 #define CHECK_AND_RET_ERROR(_COND_,_MSG_) EXPECT_FALSE(_COND_) << _MSG_; 38 TEST(Matrices, A_times_B_dyn)
46 EXPECT_NEAR(0,fabs(err.sum()), 1e-5) <<
52 TEST(Matrices,A_times_B_fix)
62 EXPECT_NEAR(0,fabs(Err.sum()), 1e-5) <<
68 TEST(Matrices,SerializeCMatrixD)
89 GTEST_FAIL() <<
"Exception not launched when it was expected!";
97 TEST(Matrices,EigenVal2x2dyn)
99 const double dat_C1[] = { 14.6271, 5.8133, 5.8133, 16.8805 };
102 Eigen::MatrixXd C1_V,C1_D;
103 C1.eigenVectors(C1_V,C1_D);
106 EXPECT_NEAR( (C1_RR-C1).array().abs().
sum(),0,1e-4);
111 const double dat_C1[] = { 8,6,1, 6,9,4, 1,4,10 };
114 Eigen::MatrixXd C1_V,C1_D;
115 C1.eigenVectors(C1_V,C1_D);
118 EXPECT_NEAR( (C1_RR-C1).array().abs().
sum(),0,1e-4);
123 const double dat_C1[] = { 14.6271, 5.8133, 5.8133, 16.8805 };
126 Eigen::Matrix2d C1_V,C1_D;
127 C1.eigenVectors(C1_V,C1_D);
130 EXPECT_NEAR( (C1_RR-C1).array().abs().
sum(),0,1e-4);
135 const double dat_C1[] = { 8,6,1, 6,9,4, 1,4,10 };
139 C1.eigenVectors(C1_V,C1_D);
142 EXPECT_NEAR( (C1_RR-C1).array().abs().
sum(),0,1e-4);
145 #if 0 // JL: Disabled since it fails in some PPA build servers. Reported to Eigen list for possible fixes... 148 TEST(Matrices,EigenVal4x4_sym_vs_generic)
150 const double dat_C1[] = {
151 13.737245,10.248641,-5.839599,11.108320,
152 10.248641,14.966139,-5.259922,11.662222,
153 -5.839599,-5.259922,9.608822,-4.342505,
154 11.108320,11.662222,-4.342505,12.121940 };
160 C1.eigenVectorsVec(eigvecs_gen,eigvals_gen);
161 C1.eigenVectorsSymmetricVec(eigvecs_sym,eigvals_sym);
163 eigvals_symM.setZero();eigvals_symM.diagonal() = eigvals_sym;
164 eigvals_genM.setZero();eigvals_genM.diagonal() = eigvals_gen;
166 EXPECT_NEAR( (C1-eigvecs_gen*eigvals_genM*(~eigvecs_gen)).array().abs().
sum(),0,1e-5)
168 <<
"eigvecs_gen*eigvals_gen*(~eigvecs_gen):\n" << eigvecs_gen*eigvals_genM*(~eigvecs_gen) << endl
169 <<
"C1:\n" << C1 << endl
170 <<
"eigvals_sym:\n" << eigvals_sym << endl
171 <<
"eigvals_gen:\n" << eigvals_gen << endl
172 <<
"eigvals_symM:\n" << eigvals_symM << endl
173 <<
"eigvals_genM:\n" << eigvals_genM << endl
174 <<
"eigvecs_gen:\n" << eigvecs_gen << endl
175 <<
"eigvecs_sym:\n" << eigvecs_sym << endl<< endl;
177 EXPECT_NEAR( (C1-eigvecs_sym*eigvals_symM*(~eigvecs_sym)).array().abs().
sum(),0,1e-5)
179 <<
"eigvecs_sym*eigvals_sym*(~eigvecs_sym):\n" << eigvecs_sym*eigvals_symM*(~eigvecs_sym) << endl
180 <<
"C1:\n" << C1 << endl;
182 EXPECT_NEAR( (eigvals_gen-eigvals_sym).array().abs().
sum(),0,1e-5)
184 <<
"eigvals_gen:\n" << eigvals_gen<< endl
185 <<
"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>".
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.
uint64_t Seek(int64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning) MRPT_OVERRIDE
Introduces a pure virtual method for moving to a specified position in the streamed resource...