Loading...
Searching...
No Matches
CoordinateResolution.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3// See LICENSE for details.
4#pragma once
5
6#include <Eigen/Core>
7#include <algorithm>
8#include <cmath>
9#include <limits>
10
11namespace gpr::optim {
12
16template <class Left, class Right>
18 const Eigen::MatrixBase<Left>& left,
19 const Eigen::MatrixBase<Right>& right) noexcept
20{
21 if (left.rows() != right.rows() || left.cols() != right.cols() ||
22 left.size() == 0 || !left.allFinite() || !right.allFinite())
23 return false;
24 constexpr double allowance = 8.0 * std::numeric_limits<double>::epsilon();
25 for (Eigen::Index row = 0; row < left.rows(); ++row) {
26 for (Eigen::Index column = 0; column < left.cols(); ++column) {
27 const double a = left(row, column);
28 const double b = right(row, column);
29 const double scale = std::max({1.0, std::abs(a), std::abs(b)});
30 if (std::abs(a - b) > allowance * scale) return false;
31 }
32 }
33 return true;
34}
35
36} // namespace gpr::optim
bool coordinatesCoincideAtRoundoff(const Eigen::MatrixBase< Left > &left, const Eigen::MatrixBase< Right > &right) noexcept