23 #include <boost/tuple/tuple.hpp> 28 using namespace gtsam;
30 static double inf = std::numeric_limits<double>::infinity();
31 static const double tol = 1
e-9;
63 template<
typename Derived>
70 template<
typename Derived>
90 Matrix actual3 = (
Matrix(2,2) << 1, 2, submat1).finished();
93 Matrix actual4 = (
Matrix(2,2) << submat2, 3, 4).finished();
95 Matrix actual5 = testFcn1((
Matrix(2,2) << 1, 2, 3, 4).finished());
96 Matrix actual6 = testFcn2((
Matrix(2,2) << 1, 2, 3, 4).finished());
110 const double *
const a = &A(0, 0);
120 Matrix A = (
Matrix(2, 2) << -5.0, 3.0, 00.0, -5.0).finished();
121 Matrix B = (
Matrix(2, 3) << -0.5, 2.1, 1.1, 3.4, 2.6, 7.1).finished();
124 for (
int i = 0;
i < 2;
i++)
125 for (
int j = 0;
j < 2;
j++)
127 for (
int i = 0;
i < 2;
i++)
128 for (
int j = 0;
j < 3;
j++)
129 C(
i,
j + 2) = B(
i,
j);
137 Matrix A = (
Matrix(2, 2) << -5.0, 3.0, 00.0, -5.0).finished();
138 Matrix B = (
Matrix(2, 3) << -0.5, 2.1, 1.1, 3.4, 2.6, 7.1).finished();
139 vector<const Matrix*> matrices;
140 matrices.push_back(&A);
141 matrices.push_back(&B);
144 for (
int i = 0;
i < 2;
i++)
145 for (
int j = 0;
j < 2;
j++)
147 for (
int i = 0;
i < 2;
i++)
148 for (
int j = 0;
j < 3;
j++)
149 C(
i,
j + 2) = B(
i,
j);
158 A = Matrix::Identity(2,3);
159 B = Matrix::Identity(2,3);
160 vector<const Matrix*> matrices;
161 matrices.push_back(&A);
162 matrices.push_back(&B);
165 1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
166 0.0, 1.0, 0.0, 0.0, 1.0, 0.0).finished();
174 Matrix A = (
Matrix(2, 2) << -5.0, 3.0, 00.0, -5.0).finished();
175 Matrix B = (
Matrix(3, 2) << -0.5, 2.1, 1.1, 3.4, 2.6, 7.1).finished();
178 for (
int i = 0;
i < 2;
i++)
179 for (
int j = 0;
j < 2;
j++)
181 for (
int i = 0;
i < 3;
i++)
182 for (
int j = 0;
j < 2;
j++)
183 C(
i + 2,
j) = B(
i,
j);
187 std::vector<gtsam::Matrix> matrices;
188 matrices.push_back(A);
189 matrices.push_back(B);
197 Matrix A = (
Matrix(4, 7) << -1., 0., 1., 0., 0., 0., -0.2, 0., -1., 0., 1.,
198 0., 0., 0.3, 1., 0., 0., 0., -1., 0., 0.2, 0., 1., 0., 0., 0., -1.,
201 Vector exp1 = (
Vector(4) << -1., 0., 1., 0.).finished();
209 Vector exp3 = (
Vector(4) << -0.2, 0.3, 0.2, -0.1).finished();
216 Matrix A = (
Matrix(4, 7) << -1., 0., 1., 0., 0., 0., -0.2, 0., -1., 0., 1.,
217 0., 0., 0.3, 1., 0., 0., 0., -1., 0., 0.2, 0., 1., 0., 0., 0., -1.,
220 Vector exp1 = (
Vector(7) << -1., 0., 1., 0., 0., 0., -0.2).finished();
228 Vector exp3 = (
Vector(7) << 0., 1., 0., 0., 0., -1., -0.1).finished();
235 Matrix big = Matrix::Zero(5,6), small = (
Matrix(2, 3) << 1.0, 1.0, 1.0, 1.0, 1.0,
241 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0,
242 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0).finished();
250 std::vector<Matrix> Hs;
251 Hs.push_back(Matrix::Ones(3,3));
252 Hs.push_back(Matrix::Ones(4,4)*2);
253 Hs.push_back(Matrix::Ones(2,2)*3);
258 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
259 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
260 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
261 0.0, 0.0, 0.0, 2.0, 2.0, 2.0, 2.0, 0.0, 0.0,
262 0.0, 0.0, 0.0, 2.0, 2.0, 2.0, 2.0, 0.0, 0.0,
263 0.0, 0.0, 0.0, 2.0, 2.0, 2.0, 2.0, 0.0, 0.0,
264 0.0, 0.0, 0.0, 2.0, 2.0, 2.0, 2.0, 0.0, 0.0,
265 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 3.0,
266 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 3.0).finished();
275 -0.3, -8
e-2, 5.1, 9.0,
276 1.2, 3.4, 4.5, 6.7).finished();
278 string matrixAsString =
280 "-0.3 -8e-2 5.1 9.0\n\r" 281 "1.2 \t 3.4 4.5 6.7";
283 stringstream asStream(matrixAsString, ios::in);
384 Vector v = (
Vector(3) << 2., std::numeric_limits<double>::infinity(), 4.).finished();
408 double wx = 1, wy = 2, wz = 3;
412 expected << 0, -3, 2,
504 Matrix C = (
Matrix(2, 2) << -3.0, -1.0, 1.0, 3.0).finished();
513 Matrix C = (
Matrix(2, 2) << -3.0, -1.0, 1.0, 3.0).finished();
563 Matrix A = (
Matrix(2, 3) << 1.0, 2.0, 3.0, 4.0, 5.0, 6.0).finished();
603 1.0, 2.0, 3.0, 4.0).finished();
608 0.0, 0.0, 3.0, 4.0).finished();
626 1.0, 2.0, 3.0).finished();
632 0.0, 0.0, 0.0).finished();
647 0.0, 2.0, 3.0).finished();
667 Matrix Ainv = A.inverse();
685 Matrix lMg((
Matrix(3, 3) << 0.0, 1.0, -2.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0).finished());
689 0.0, 0.0, 1.0).finished(),
691 Matrix gMl((
Matrix(3, 3) << 0.0, -1.0, 1.0, 1.0, 0.0, 2.0, 0.0, 0.0, 1.0).finished());
695 0.0, 0.0, 1.0).finished(),
713 Matrix Ainv = A.inverse();
734 Matrix U22 = (
Matrix(2, 2) << 2., 3., 0., 4.).finished();
740 Matrix U33 = (
Matrix(3, 3) << 3., 5., 6., 0., 2., 3., 0., 0., 1.).finished();
759 Matrix expected1 = (
Matrix(4, 7) << 11.1803, 0, -2.2361, 0, -8.9443, 0, 2.236,
760 0, 11.1803, 0, -2.2361, 0, -8.9443, -1.565,
761 -0.618034, 0, 4.4721, 0, -4.4721, 0, 0,
762 0, -0.618034, 0, 4.4721, 0, -4.4721, 0.894).finished();
764 00,-5, 0, 5, 0, 0, 1.5,
765 10, 0, 0, 0,-10,0, 2,
766 00, 10,0, 0, 0, -10, -1 ).finished();
772 Matrix expected = (
Matrix(4, 7) << 11.1803, 0, -2.2361, 0, -8.9443, 0, 2.236, 0, 11.1803,
773 0, -2.2361, 0, -8.9443, -1.565, 0, 0, 4.4721, 0, -4.4721, 0, 0, 0,
774 0, 0, 4.4721, 0, -4.4721, 0.894).finished();
776 00,-5, 0, 5, 0, 0, 1.5,
777 10, 0, 0, 0,-10,0, 2,
778 00, 10,0, 0, 0, -10, -1).finished();
788 Matrix expected1((
Matrix(4, 7) << 11.1803, 0, -2.2361, 0, -8.9443, 0, 2.236,
789 0, 11.1803, 0, -2.2361, 0, -8.9443, -1.565,
790 -0.618034, 0, 4.4721, 0, -4.4721, 0, 0,
791 0, -0.618034, 0, 4.4721, 0, -4.4721, 0.894).finished());
793 00,-5, 0, 5, 0, 0, 1.5,
794 10, 0, 0, 0,-10,0, 2,
795 00, 10,0, 0, 0, -10, -1).finished());
801 Matrix expected((
Matrix(4, 7) << 11.1803, 0, -2.2361, 0, -8.9443, 0, 2.236, 0, 11.1803,
802 0, -2.2361, 0, -8.9443, -1.565, 0, 0, 4.4721, 0, -4.4721, 0, 0, 0,
803 0, 0, 4.4721, 0, -4.4721, 0.894).finished());
805 00,-5, 0, 5, 0, 0, 1.5,
806 10, 0, 0, 0,-10,0, 2,
807 00, 10,0, 0, 0, -10, -1).finished());
819 Matrix expected((
Matrix(4, 7) << 11.1803, 0, -2.2361, 0, -8.9443, 0, 2.236, 0, 11.1803,
820 0, -2.2361, 0, -8.9443, -1.565, 0, 0, 4.4721, 0, -4.4721, 0, 0, 0,
821 0, 0, 4.4721, 0, -4.4721, 0.894).finished());
823 00,-5, 0, 5, 0, 0, 1.5,
824 10, 0, 0, 0,-10,0, 2,
825 00, 10,0, 0, 0, -10, -1).finished());
826 Matrix actual = A.householderQr().matrixQR();
833 00,-5, 0, 5, 0, 0, 1.5,
834 10, 0, 0, 0,-10,0, 2,
835 00, 10,0, 0, 0, -10, -1).finished());
847 Matrix A = (
Matrix(6, 4) << -5, 0, 5, 0, 00, -5, 0, 5, 10, 0, 0, 0, 00, 10, 0, 0, 00,
848 0, 0, -10, 10, 0, -10, 0).finished();
851 Matrix expectedQ = (
Matrix(6, 6) << -0.3333, 0, 0.2981, 0, 0, -0.8944, 0000000, -0.4472, 0,
852 0.3651, -0.8165, 0, 00.6667, 0, 0.7454, 0, 0, 0, 0000000, 0.8944,
853 0, 0.1826, -0.4082, 0, 0000000, 0, 0, -0.9129, -0.4082, 0, 00.6667,
854 0, -0.5963, 0, 0, -0.4472).finished();
856 Matrix expectedR = (
Matrix(6, 4) << 15, 0, -8.3333, 0, 00, 11.1803, 0, -2.2361, 00, 0,
857 7.4536, 0, 00, 0, 0, 10.9545, 00, 0, 0, 0, 00, 0, 0, 0).finished();
860 boost::tie(Q, R) =
qr(A);
869 Matrix A = (
Matrix(4, 6) << -5, 0, 5, 0, 0, 0, 00, -5, 0, 5, 0, 0, 10, 0, 0, 0, -10,
870 0, 00, 10, 0, 0, 0, -10).finished();
890 const double*
a = &A(0, 0);
898 Matrix A = (
Matrix(4, 6) << -1., 0., 1., 0., 0., 0., 0., -1., 0., 1., 0., 0.,
899 1., 0., 0., 0., -1., 0., 0., 1., 0., 0., 0., -1.).finished();
904 Matrix expectedR = (
Matrix(4, 6) << 1., 0., -0.2, 0., -0.8, 0., 0., 1., 0.,
905 -0.2, 0., -0.8, 0., 0., 1., 0., -1., 0., 0., 0., 0., 1., 0., -1.).finished();
907 Vector newSigmas = (
Vector(4) << 0.0894427, 0.0894427, 0.223607, 0.223607).finished();
912 std::list<boost::tuple<Vector, double, double> > solution =
917 for (
const auto&
tuple : solution) {
920 boost::tie(r, di, sigma) =
tuple;
931 Matrix measurement_covariance = (
Matrix(3, 3) << 0.25, 0.0, 0.0, 0.0, 0.25,
932 0.0, 0.0, 0.0, 0.01).finished();
948 0.0785892, 0.0137923, -0.0142219, -0.0171880, 0.0028726,
949 0.0137923, 0.0908911, 0.0020775, -0.0101952, 0.0175868,
950 -0.0142219, 0.0020775, 0.0973051, 0.0054906, 0.0047064,
951 -0.0171880,-0.0101952, 0.0054906, 0.0892453, -0.0059468,
952 0.0028726, 0.0175868, 0.0047064, -0.0059468, 0.0816517).finished();
954 expected = (
Matrix(5, 5) <<
955 3.567126953241796, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000,
956 -0.590030436566913, 3.362022286742925, 0.000000000000000, 0.000000000000000, 0.000000000000000,
957 0.618207860252376, -0.168166020746503, 3.253086082942785, 0.000000000000000, 0.000000000000000,
958 0.683045380655496, 0.283773848115276, -0.099969232183396, 3.433537147891568, 0.000000000000000,
959 -0.006740136923185, -0.669325697387650, -0.169716689114923, 0.171493059476284, 3.583921085468937).finished();
969 0.0048741, -0.0030860, 0.0872727, 0.0183073, 0.0125325, -0.0037363,
970 0.0116969, 0.0183073, 0.0966217, 0.0103894, -0.0021113, 0.0081463,
971 0.0125325, 0.0103894, 0.0747324, 0.0036415, 0.0048741, -0.0037363,
972 -0.0021113, 0.0036415, 0.0909464).finished();
975 0.295668226226627, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000,
976 -0.010437374483502, 0.295235094820875, 0.000000000000000, 0.000000000000000, 0.000000000000000,
977 0.039560896175007, 0.063407813693827, 0.301721866387571, 0.000000000000000, 0.000000000000000,
978 0.027552165831157, 0.043423266737274, 0.021695600982708, 0.267613525371710, 0.000000000000000,
979 0.016485031422565, -0.012072546984405, -0.006621889326331, 0.014405837566082, 0.300462176944247).finished();
998 Matrix A = (
Matrix(2, 3) << 1.0, 2.0, 3.0, 4.0, 5.0, 6.0).finished();
999 Matrix B = (
Matrix(2, 3) << -1.0, -2.0, -3.0, 8.0, 10.0, 12.0).finished();
1006 Matrix A = (
Matrix(2, 3) << 0.0, 2.0, 3.0, 4.0, 5.0, 6.0).finished();
1007 Matrix B = (
Matrix(2, 3) << 0.0, -2.0, -3.0, 8.0, 10.0, 12.0).finished();
1014 Matrix A = (
Matrix(2, 3) << 0.0, 2.0, 3.0, 4.0, 5.0, 6.0).finished();
1015 Matrix B = (
Matrix(2, 3) << 0.0, -2.0, -3.0, 8.1, 10.0, 12.0).finished();
1023 Matrix U1 = Matrix::Identity(4, 3), S1 = v.asDiagonal(), V1 = I_3x3,
A = (U1 * S1)
1044 Matrix expectedU = (
Matrix(3, 2) << 0.,-1.,0.,0.,1.,0.).finished();
1046 Matrix expectedV = (
Matrix(2, 2) << 1.,0.,0.,1.).finished();
1048 svd(sampleA, U, s, V);
1067 Matrix expectedU = (
Matrix(2, 2) << -1.,0.,0.,-1.).finished();
1069 Matrix expectedV = (
Matrix(3, 2) << 0.,1.,0.,0.,-1.,0.).finished();
1071 svd(sampleAt, U, s, V);
1098 0.1270, 0.0975).finished();
1103 0.0970, -0.0689).finished();
1109 0.6723, 0.7403).finished();
1115 U.col(0) = -U.col(0);
1116 V.col(0) = -V.col(0);
1119 U.col(1) = -U.col(1);
1120 V.col(1) = -V.col(1);
1123 Matrix reconstructed = U * s.asDiagonal() *
trans(V);
1135 0.21, -0.42, -10.71, 0.18, -0.36, -9.18, -0.61, 1.22, 31.11,
1136 0.44, -0.66, -15.84, 0.34, -0.51, -12.24, -1.64, 2.46, 59.04,
1137 0.69, -8.28, -12.19, -0.48, 5.76, 8.48, -1.89, 22.68, 33.39,
1138 0.96, -8.4, -17.76, -0.6, 5.25, 11.1, -3.36, 29.4, 62.16,
1139 1.25, 0.3, 2.75, -3.5, -0.84, -7.7, 16.25, 3.9, 35.75,
1140 1.56, 0.42, 4.56, -3.38, -0.91, -9.88, 22.36, 6.02, 65.36,
1141 1.89, 2.24, 3.99, 3.24, 3.84, 6.84, 18.09, 21.44, 38.19,
1142 2.24, 2.48, 6.24, 3.08, 3.41, 8.58, 24.64, 27.28, 68.64
1147 boost::tie(rank,error,actual) =
DLT(A);
1148 Vector expected = (
Vector(9) << -0.0, 0.2357, 0.4714, -0.2357, 0.0, - 0.4714,-0.4714, 0.4714, 0.0).finished();
1167 double a = 2000,
b = 1997,
tol = 1
e-1;
void inplace_QR(Matrix &A)
#define EQUALITY(expected, actual)
boost::tuple< int, double, Vector > DLT(const Matrix &A, double rank_tol)
void zeroBelowDiagonal(MATRIX &A, size_t cols=0)
cout<< "Here is the matrix m:"<< endl<< m<< endl;JacobiSVD< MatrixXf > svd(m, ComputeThinU|ComputeThinV)
const mpreal exp2(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
Matrix< RealScalar, Dynamic, Dynamic > M
TEST(Matrix, constructor_data)
static int runAllTests(TestResult &result)
Matrix diag(const std::vector< Matrix > &Hs)
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
#define DOUBLES_EQUAL(expected, actual, threshold)
static const double sigma
BOOST_CONCEPT_ASSERT((boost::RandomAccessRangeConcept< ListOfOneContainer< int > >))
Rot2 R(Rot2::fromAngle(0.1))
Matrix< SCALARB, Dynamic, Dynamic > B
Base class for all dense matrices, vectors, and arrays.
Vector backSubstituteLower(const Matrix &L, const Vector &b, bool unit)
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
Matrix vector_scale(const Vector &v, const Matrix &A, bool inf_mask)
HouseholderQR< MatrixXf > qr(A)
Matrix RtR(const Matrix &A)
bool fpEqual(double a, double b, double tol, bool check_relative_also)
Matrix LLt(const Matrix &A)
void householder(const MatrixType &m)
#define EXPECT(condition)
void householder_(Matrix &A, size_t k, bool copy_vectors)
EIGEN_DONT_INLINE void prod(const Lhs &a, const Rhs &b, Res &c)
list< boost::tuple< Vector, double, double > > weighted_eliminate(Matrix &A, Vector &b, const Vector &sigmas)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static Matrix sampleA
Sample A matrix for SVD.
Matrix< Scalar, Dynamic, Dynamic > C
#define LONGS_EQUAL(expected, actual)
EIGEN_DONT_INLINE T sub(T a, T b)
bool linear_dependent(const Matrix &A, const Matrix &B, double tol)
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Matrix3 skewSymmetric(double wx, double wy, double wz)
Matrix inverse_square_root(const Matrix &A)
#define EXPECT_LONGS_EQUAL(expected, actual)
void insertSub(Eigen::MatrixBase< Derived1 > &fullMatrix, const Eigen::MatrixBase< Derived2 > &subMatrix, size_t i, size_t j)
Vector backSubstituteUpper(const Matrix &U, const Vector &b, bool unit)
Matrix stack(size_t nrMatrices,...)
bool linear_independent(const Matrix &A, const Matrix &B, double tol)
Matrix collect(const std::vector< const Matrix * > &matrices, size_t m, size_t n)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > Matrix
The matrix class, also used for vectors and row-vectors.
bool equal(const T &obj1, const T &obj2, double tol)
Matrix cholesky_inverse(const Matrix &A)
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
const MATRIX::ConstColXpr column(const MATRIX &A, size_t j)
Base class for all dense matrices, vectors, and expressions.
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
Eigen::RowVectorXd RowVector