Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Commit

Permalink
matrix: add method to check all values are nan (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrivi authored and Julian Kent committed Aug 26, 2019
1 parent 84b3da2 commit cc084e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions matrix/Matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,17 @@ class Matrix
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>
Expand Down
2 changes: 2 additions & 0 deletions test/matrixAssignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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);
Expand Down

0 comments on commit cc084e0

Please sign in to comment.