WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
all_finite.hpp
Go to the documentation of this file.
1// Copyright (c) Sleipnir contributors
2
3#pragma once
4
5#include <cmath>
6
7#include <Eigen/SparseCore>
8
9/// Returns true if elements of sparse matrix are all finite.
10///
11/// @param mat Sparse matrix.
12/// @return True if elements of sparse matrix are all finite.
13template <typename Derived>
14bool all_finite(const Eigen::SparseCompressedBase<Derived>& mat) {
15 using std::isfinite;
16
17 for (int k = 0; k < mat.outerSize(); ++k) {
18 for (typename Derived::InnerIterator it{mat, k}; it; ++it) {
19 if (!isfinite(it.value())) {
20 return false;
21 }
22 }
23 }
24
25 return true;
26}
bool all_finite(const Eigen::SparseCompressedBase< Derived > &mat)
Returns true if elements of sparse matrix are all finite.
Definition all_finite.hpp:14