matrix: add method to check all values are nan (#82)

This commit is contained in:
Martina Rivizzigno
2019-08-26 19:27:58 +02:00
committed by Julian Kent
parent 84b3da227c
commit cc084e0791
2 changed files with 13 additions and 0 deletions
+11
View File
@@ -507,6 +507,17 @@ public:
return min_val;
}
bool isAllNan() const {
const Matrix<float, M, N> &self = *this;
bool result = true;
for (size_t i = 0; i < M; i++) {
for (size_t j = 0; j < N; j++) {
result = result && isnan(self(i, j));
}
}
return result;
}
};
template<typename Type, size_t M, size_t N>
+2
View File
@@ -30,6 +30,7 @@ int main()
for(int i=0; i<9; i++) {
TEST(isnan(m_nan.data()[i]));
}
TEST(m_nan.isAllNan());
float data2d[3][3] = {
{1, 2, 3},
@@ -40,6 +41,7 @@ int main()
for(int i=0; i<9; i++) {
TEST(fabs(data[i] - m2.data()[i]) < FLT_EPSILON);
}
TEST(!m2.isAllNan());
float data_times_2[9] = {2, 4, 6, 8, 10, 12, 14, 16, 18};
Matrix3f m3(data_times_2);