Skip to content

Commit ef9eb8b

Browse files
Fix for issue #35
1 parent 6c6a306 commit ef9eb8b

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

orocos_bfl/src/wrappers/matrix/matrix_BOOST.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ MySymmetricMatrix MySymmetricMatrix::inverse() const
380380
unsigned int r = this->rows();
381381
assert(r == this->columns());
382382
const BoostMatrix& A = (*this);
383-
BoostSymmetricMatrix Ai(r,r);
383+
BoostMatrix Ai(r,r);
384384
switch (r)
385385
{
386386
case 1:
@@ -399,7 +399,7 @@ MySymmetricMatrix MySymmetricMatrix::inverse() const
399399
}
400400
default:
401401
{
402-
BoostSymmetricMatrix LU(r,r);
402+
BoostMatrix LU(r,r);
403403
boost::numeric::ublas::permutation_matrix<> ndx(r);
404404
noalias(LU) = A;
405405
int res = lu_factorize(LU,ndx);
@@ -409,7 +409,8 @@ MySymmetricMatrix MySymmetricMatrix::inverse() const
409409
break;
410410
}
411411
}
412-
return Ai;
412+
413+
return MySymmetricMatrix(Ai);
413414
}
414415

415416
double MySymmetricMatrix::determinant() const
@@ -429,7 +430,7 @@ double MySymmetricMatrix::determinant() const
429430
}
430431
default:
431432
{
432-
BoostSymmetricMatrix LU(r,r);
433+
BoostMatrix LU(r,r);
433434
boost::numeric::ublas::permutation_matrix<> ndx(r);
434435
noalias(LU) = A;
435436
int res = lu_factorize(LU,ndx);

orocos_bfl/tests/matrixwrapper_test.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -554,15 +554,28 @@ MatrixwrapperTest::testMatrixwrapperValue()
554554

555555
// Issue #30
556556
SymmetricMatrix MI30(c);
557-
Rs(1,1) = 3; Rs(1,2) = 2; Rs(1,3) = 0;
558-
Rs(2,1) = 2; Rs(2,2) = 2; Rs(2,3) = 0;
559-
Rs(3,1) = 0; Rs(3,2) = 0; Rs(3,3) = 0.5;
557+
MI30(1,1) = 3; MI30(1,2) = 2; MI30(1,3) = 0;
558+
MI30(2,1) = 2; MI30(2,2) = 2; MI30(2,3) = 0;
559+
MI30(3,1) = 0; MI30(3,2) = 0; MI30(3,3) = 0.5;
560+
561+
560562

561563
// test determinant
562564
CPPUNIT_ASSERT_EQUAL(approxEqual(Rm.determinant(), 105, epsilon),true);
563565
CPPUNIT_ASSERT_EQUAL(approxEqual(Rs.determinant(), 45, epsilon),true);
564566
CPPUNIT_ASSERT_EQUAL(approxEqual(MI30.determinant(), 1, epsilon),true); // Issue #30
565567

568+
// test symmetric inverse
569+
SymmetricMatrix MI30_inv = MI30.inverse();
570+
571+
SymmetricMatrix MI30_inv_test(c);
572+
MI30_inv_test(1,1) = 1.; MI30_inv_test(1,2) = -1.; MI30_inv_test(1,3) = 0.;
573+
MI30_inv_test(2,1) = -1.; MI30_inv_test(2,2) = 1.5; MI30_inv_test(2,3) = 0.;
574+
MI30_inv_test(3,1) = 0.; MI30_inv_test(3,2) = 0.; MI30_inv_test(3,3) = 2.;
575+
576+
CPPUNIT_ASSERT_EQUAL(approxEqual(MI30_inv_test, MI30_inv, epsilon), true);
577+
578+
566579
// test cholesky
567580
SymmetricMatrix Ps(c);
568581
Ps(1,1) = 3; Ps(1,2) = 2; Ps(1,3) = 1;

0 commit comments

Comments
 (0)