chkder.h
Go to the documentation of this file.
1 #define chkder_log10e 0.43429448190325182765
2 #define chkder_factor 100.
3 
5 
6 namespace Eigen {
7 
8 namespace internal {
9 
10 template<typename Scalar>
11 void chkder(
13  const Matrix< Scalar, Dynamic, 1 > &fvec,
16  const Matrix< Scalar, Dynamic, 1 > &fvecp,
17  int mode,
19  )
20 {
21  using std::sqrt;
22  using std::abs;
23  using std::log;
24 
25  typedef DenseIndex Index;
26 
27  const Scalar eps = sqrt(NumTraits<Scalar>::epsilon());
28  const Scalar epsf = chkder_factor * NumTraits<Scalar>::epsilon();
29  const Scalar epslog = chkder_log10e * log(eps);
30  Scalar temp;
31 
32  const Index m = fvec.size(), n = x.size();
33 
34  if (mode != 2) {
35  /* mode = 1. */
36  xp.resize(n);
37  for (Index j = 0; j < n; ++j) {
38  temp = eps * abs(x[j]);
39  if (temp == 0.)
40  temp = eps;
41  xp[j] = x[j] + temp;
42  }
43  }
44  else {
45  /* mode = 2. */
46  err.setZero(m);
47  for (Index j = 0; j < n; ++j) {
48  temp = abs(x[j]);
49  if (temp == 0.)
50  temp = 1.;
51  err += temp * fjac.col(j);
52  }
53  for (Index i = 0; i < m; ++i) {
54  temp = 1.;
55  if (fvec[i] != 0. && fvecp[i] != 0. && abs(fvecp[i] - fvec[i]) >= epsf * abs(fvec[i]))
56  temp = eps * abs((fvecp[i] - fvec[i]) / eps - err[i]) / (abs(fvec[i]) + abs(fvecp[i]));
57  err[i] = 1.;
58  if (temp > NumTraits<Scalar>::epsilon() && temp < eps)
59  err[i] = (chkder_log10e * log(temp) - epslog) / epslog;
60  if (temp >= eps)
61  err[i] = 0.;
62  }
63  }
64 }
65 
66 } // end namespace internal
67 
68 } // end namespace Eigen
Matrix3f m
int n
int i
#define chkder_log10e
Definition: chkder.h:1
#define chkder_factor
Definition: chkder.h:2
Derived & setZero(Index rows, Index cols)
constexpr void resize(Index rows, Index cols)
void chkder(const Matrix< Scalar, Dynamic, 1 > &x, const Matrix< Scalar, Dynamic, 1 > &fvec, const Matrix< Scalar, Dynamic, Dynamic > &fjac, Matrix< Scalar, Dynamic, 1 > &xp, const Matrix< Scalar, Dynamic, 1 > &fvecp, int mode, Matrix< Scalar, Dynamic, 1 > &err)
Definition: chkder.h:11
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
Eigen::AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Eigen::internal::remove_all_t< DerType >, typename Eigen::internal::traits< Eigen::internal::remove_all_t< DerType >>::Scalar, product) > log(const Eigen::AutoDiffScalar< DerType > &x)
Eigen::AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Eigen::internal::remove_all_t< DerType >, typename Eigen::internal::traits< Eigen::internal::remove_all_t< DerType >>::Scalar, product) > sqrt(const Eigen::AutoDiffScalar< DerType > &x)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_log_op< typename Derived::Scalar >, const Derived > log(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)
adouble abs(const adouble &x)
Definition: AdolcForward:74
std::ptrdiff_t j