Fixed equality checking with NaNs in Matrix
removed extraneous print statement in Vectorrelease/4.3a0
parent
01ee9246d7
commit
03985d16f6
|
@ -84,7 +84,7 @@ Matrix diag(const Vector& v) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
/** Check if two matrizes are the same */
|
/** Check if two matrices are the same */
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
bool equal_with_abs_tol(const Matrix& A, const Matrix& B, double tol) {
|
bool equal_with_abs_tol(const Matrix& A, const Matrix& B, double tol) {
|
||||||
|
|
||||||
|
@ -94,9 +94,12 @@ bool equal_with_abs_tol(const Matrix& A, const Matrix& B, double tol) {
|
||||||
if(m1!=m2 || n1!=n2) return false;
|
if(m1!=m2 || n1!=n2) return false;
|
||||||
|
|
||||||
for(size_t i=0; i<m1; i++)
|
for(size_t i=0; i<m1; i++)
|
||||||
for(size_t j=0; j<n1; j++)
|
for(size_t j=0; j<n1; j++) {
|
||||||
if(fabs(A(i,j) - B(i,j)) > tol)
|
if(isnan(A(i,j)) xor isnan(B(i,j)))
|
||||||
return false;
|
return false;
|
||||||
|
if(fabs(A(i,j) - B(i,j)) > tol)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,6 +172,23 @@ TEST( matrix, equal )
|
||||||
CHECK(A!=A3);
|
CHECK(A!=A3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
TEST( matrix, equal_nan )
|
||||||
|
{
|
||||||
|
Matrix A(4,4);
|
||||||
|
A(0,0) = -1; A(0,1) = 1; A(0,2)= 2; A(0,3)= 3;
|
||||||
|
A(1,0) = 1; A(1,1) =-3; A(1,2)= 1; A(1,3)= 3;
|
||||||
|
A(2,0) = 1; A(2,1) = 2; A(2,2)=-1; A(2,3)= 4;
|
||||||
|
A(3,0) = 2; A(3,1) = 1; A(3,2)= 2; A(3,3)=-2;
|
||||||
|
|
||||||
|
Matrix A2(A);
|
||||||
|
|
||||||
|
Matrix A3(A);
|
||||||
|
A3(3,3)=0.0/0.0;
|
||||||
|
|
||||||
|
CHECK(A!=A3);
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
TEST( matrix, addition )
|
TEST( matrix, addition )
|
||||||
{
|
{
|
||||||
|
|
|
@ -209,8 +209,6 @@ TEST( TestVector, equals )
|
||||||
Vector v1 = Vector_(1, 0.0/0.0); //testing nan
|
Vector v1 = Vector_(1, 0.0/0.0); //testing nan
|
||||||
Vector v2 = Vector_(1, 1.0);
|
Vector v2 = Vector_(1, 1.0);
|
||||||
double tol = 1.;
|
double tol = 1.;
|
||||||
print(v1, "v1");
|
|
||||||
print(v2, "v2");
|
|
||||||
CHECK(!equal_with_abs_tol(v1, v2, tol));
|
CHECK(!equal_with_abs_tol(v1, v2, tol));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue