14 #include <gtest/gtest.h> 21 #include <Eigen/Dense> 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, DynMat_size)
37 EXPECT_EQ(
A.rows(), 3);
38 EXPECT_EQ(
A.cols(), 2);
39 EXPECT_EQ(
A.size(), 6U);
42 TEST(Matrices, A_times_B_dyn)
50 EXPECT_NEAR(0, fabs(err.
sum()), 1e-5)
51 <<
"A: " <<
A <<
"B: " << B <<
"A*B: " << C << endl;
54 TEST(Matrices, A_times_B_fix)
64 EXPECT_NEAR(0, fabs(Err.
asEigen().array().sum()), 1e-5);
67 TEST(Matrices, SerializeCMatrixD)
90 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};
103 std::vector<double> C1_Ds;
111 EXPECT_NEAR((C1_RR - C1).sum_abs(), 0, 1e-4);
118 const double dat_C[] = {14.6271, 0, 5.8133, 16.8805};
122 std::vector<double> eig_vals;
125 EXPECT_EQ(eig_vals.size(), 2UL);
126 EXPECT_NEAR(eig_vals[0], 9.83232131811656, 1e-4);
127 EXPECT_NEAR(eig_vals[1], 21.67527868188344, 1e-4);
133 const double dat_C1[] = {8, 6, 1, 6, 9, 4, 1, 4, 10};
137 std::vector<double> C1_Ds;
145 EXPECT_NEAR((C1_RR - C1).sum_abs(), 0, 1e-4);
150 const double dat_C1[] = {14.6271, 5.8133, 5.8133, 16.8805};
154 std::vector<double> C1_Ds;
162 EXPECT_NEAR((C1_RR - C1).sum_abs(), 0, 1e-4);
167 const double dat_C1[] = {8, 6, 1, 6, 9, 4, 1, 4, 10};
171 std::vector<double> C1_Ds;
179 EXPECT_NEAR((C1_RR - C1).sum_abs(), 0, 1e-4);
A namespace of pseudo-random numbers generators of diferent distributions.
bool eig(Derived &eVecs, std::vector< Scalar > &eVals, bool sorted=true) const
Computes the eigenvectors and eigenvalues for a square, general matrix.
A compile-time fixed-size numeric matrix container.
This class is a "CSerializable" wrapper for "CMatrixDynamic<double>".
bool eig_symmetric(Derived &eVecs, std::vector< Scalar > &eVals, bool sorted=true) const
Read: eig()
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.
CMatrixFixed< double, 3, 3 > CMatrixDouble33
This base provides a set of functions for maths stuff.
This CStream derived class allow using a memory buffer as a CStream.
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...
CMatrixFixed< double, 2, 2 > CMatrixDouble22
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Scalar sum() const
Sum of all elements in matrix/vector.
This file implements matrix/vector text and binary serialization.
EIGEN_MAP asEigen()
Get as an Eigen-compatible Eigen::Map object.
TEST(Matrices, DynMat_size)
EIGEN_MAP asEigen()
Get as an Eigen-compatible Eigen::Map object.
void setDiagonal(const std::size_t N, const Scalar value)
Resize to NxN, set all entries to zero, except the main diagonal which is set to value ...
CMatrixDynamic< double > CMatrixDouble
Declares a matrix of double numbers (non serializable).