libqe 0.2.6-dev.9001
QE C++ library
Loading...
Searching...
No Matches
validate.hpp
Go to the documentation of this file.
1
8#ifndef LIBQE_VALIDATE_HPP
9#define LIBQE_VALIDATE_HPP
10
11#include <armadillo>
12#include <cstddef>
13#include <stdexcept>
14#include <string>
15
16namespace qe {
17
25inline void require_finite(const arma::mat& m, const char* param) {
26 if (!m.is_finite())
27 throw std::invalid_argument(
28 std::string(param) + " contains NaN or Inf — "
29 "filter or impute rows with non-finite values before calling");
30}
31
42inline void require_dims(std::size_t n, int rows, int cols) {
43 if (rows < 0 || cols < 0 ||
44 static_cast<std::size_t>(rows) * static_cast<std::size_t>(cols) != n)
45 throw std::invalid_argument("matrix dimensions do not match the data length");
46}
47
48} // namespace qe
49
50#endif // LIBQE_VALIDATE_HPP
Definition adjacency.hpp:16
void require_dims(std::size_t n, int rows, int cols)
Throw unless rows × cols describes exactly n elements.
Definition validate.hpp:42
void require_finite(const arma::mat &m, const char *param)
Throw if m contains NaN or Inf.
Definition validate.hpp:25