Cheetah Software  1.0
MathUtilities.h
Go to the documentation of this file.
1 
6 #ifndef PROJECT_MATHUTILITIES_H
7 #define PROJECT_MATHUTILITIES_H
8 
9 #include <eigen3/Eigen/Dense>
10 
14 template <typename T>
15 T square(T a) {
16  return a * a;
17 }
18 
22 template <typename T, typename T2>
23 bool almostEqual(const Eigen::MatrixBase<T>& a, const Eigen::MatrixBase<T>& b,
24  T2 tol) {
25  long x = T::RowsAtCompileTime;
26  long y = T::ColsAtCompileTime;
27 
28  if (T::RowsAtCompileTime == Eigen::Dynamic ||
29  T::ColsAtCompileTime == Eigen::Dynamic) {
30  assert(a.rows() == b.rows());
31  assert(a.cols() == b.cols());
32  x = a.rows();
33  y = a.cols();
34  }
35 
36  for (long i = 0; i < x; i++) {
37  for (long j = 0; j < y; j++) {
38  T2 error = std::abs(a(i, j) - b(i, j));
39  if (error >= tol) return false;
40  }
41  }
42  return true;
43 }
44 
45 #endif // PROJECT_MATHUTILITIES_H
T square(T a)
Definition: MathUtilities.h:15
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23