feat(utils/checks): runtime is finite check
Probably this should be removed...
This commit is contained in:
@@ -2,35 +2,10 @@
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "mfem/linalg/vector.hpp"
|
|
||||||
#include "mfem/linalg/densemat.hpp"
|
|
||||||
|
|
||||||
#include "serif/utils/misc/concepts/numeric.hpp"
|
#include "serif/utils/misc/concepts/numeric.hpp"
|
||||||
|
|
||||||
namespace serif::utils::checks {
|
namespace serif::utils::checks {
|
||||||
// If we have a new backend / new vector and matrix type in the future we can add new overloads
|
|
||||||
inline bool is_finite(const mfem::Vector& vector) {
|
|
||||||
for (int i = 0; i < vector.Size(); ++i) {
|
|
||||||
if (!std::isfinite(vector(i))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool is_finite(const mfem::DenseMatrix& matrix) {
|
|
||||||
for (int i = 0; i < matrix.Height(); ++i) {
|
|
||||||
for (int j = 0; j < matrix.Width(); ++j) {
|
|
||||||
if (!std::isfinite(matrix(i, j))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Scalar>
|
template <typename Scalar>
|
||||||
requires requires (Scalar x) {{std::isfinite(x)} -> std::convertible_to<bool>; }
|
requires requires (Scalar x) {{std::isfinite(x)} -> std::convertible_to<bool>; }
|
||||||
bool is_finite(const Scalar scalar) {
|
bool is_finite(const Scalar scalar) {
|
||||||
|
|||||||
Reference in New Issue
Block a user