linear_dependent prints when not linearly dependent, like assert_equal. Added linear_independent to check the opposite.
parent
4e0b4021df
commit
739764ca8e
|
@ -175,17 +175,49 @@ bool assert_equal(const std::list<Matrix>& As, const std::list<Matrix>& Bs, doub
|
|||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
bool linear_dependent(const Matrix& A, const Matrix& B, double tol) {
|
||||
static bool is_linear_dependent(const Matrix& A, const Matrix& B, double tol) {
|
||||
// This local static function is used by linear_independent and
|
||||
// linear_dependent just below.
|
||||
size_t n1 = A.size2(), m1 = A.size1();
|
||||
size_t n2 = B.size2(), m2 = B.size1();
|
||||
|
||||
if(m1!=m2 || n1!=n2) return false;
|
||||
bool dependent = true;
|
||||
if(m1!=m2 || n1!=n2) dependent = false;
|
||||
|
||||
for(size_t i=0; i<m1; i++) {
|
||||
if (!gtsam::linear_dependent(row_(A,i), row_(B,i), tol))
|
||||
return false;
|
||||
for(size_t i=0; dependent && i<m1; i++) {
|
||||
if (!gtsam::linear_dependent(row_(A,i), row_(B,i), tol))
|
||||
dependent = false;
|
||||
}
|
||||
|
||||
return dependent;
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
bool linear_independent(const Matrix& A, const Matrix& B, double tol) {
|
||||
if(!is_linear_dependent(A, B, tol))
|
||||
return true;
|
||||
else {
|
||||
cout << "not linearly dependent:" << endl;
|
||||
print(A,"A = ");
|
||||
print(B,"B = ");
|
||||
if(A.size1()!=B.size1() || A.size2()!=B.size2())
|
||||
cout << A.size1() << "x" << A.size2() << " != " << B.size1() << "x" << B.size2() << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
bool linear_dependent(const Matrix& A, const Matrix& B, double tol) {
|
||||
if(is_linear_dependent(A, B, tol))
|
||||
return true;
|
||||
else {
|
||||
cout << "not linearly dependent:" << endl;
|
||||
print(A,"A = ");
|
||||
print(B,"B = ");
|
||||
if(A.size1()!=B.size1() || A.size2()!=B.size2())
|
||||
cout << A.size1() << "x" << A.size2() << " != " << B.size1() << "x" << B.size2() << endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
|
|
|
@ -99,7 +99,12 @@ bool assert_equal(const Matrix& A, const Matrix& B, double tol = 1e-9);
|
|||
bool assert_equal(const std::list<Matrix>& As, const std::list<Matrix>& Bs, double tol = 1e-9);
|
||||
|
||||
/**
|
||||
* check whether the rows of two matrices are linear indepdent
|
||||
* check whether the rows of two matrices are linear independent
|
||||
*/
|
||||
bool linear_independent(const Matrix& A, const Matrix& B, double tol = 1e-9);
|
||||
|
||||
/**
|
||||
* check whether the rows of two matrices are linear dependent
|
||||
*/
|
||||
bool linear_dependent(const Matrix& A, const Matrix& B, double tol = 1e-9);
|
||||
|
||||
|
|
|
@ -882,7 +882,7 @@ TEST( matrix, linear_dependent3 )
|
|||
{
|
||||
Matrix A = Matrix_(2, 3, 0.0, 2.0, 3.0, 4.0, 5.0, 6.0);
|
||||
Matrix B = Matrix_(2, 3, 0.0, -2.0, -3.0, 8.1, 10.0, 12.0);
|
||||
CHECK(!linear_dependent(A, B));
|
||||
CHECK(linear_independent(A, B));
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
|
|
Loading…
Reference in New Issue