fdjac1.h
Go to the documentation of this file.
2 
3 namespace Eigen {
4 
5 namespace internal {
6 
7 template<typename FunctorType, typename Scalar>
9  const FunctorType &Functor,
13  DenseIndex ml, DenseIndex mu,
14  Scalar epsfcn)
15 {
16  using std::sqrt;
17  using std::abs;
18 
19  typedef DenseIndex Index;
20 
21  /* Local variables */
22  Scalar h;
23  Index j, k;
24  Scalar eps, temp;
25  Index msum;
26  int iflag;
27  Index start, length;
28 
29  /* Function Body */
30  const Scalar epsmch = NumTraits<Scalar>::epsilon();
31  const Index n = x.size();
32  eigen_assert(fvec.size()==n);
35 
36  eps = sqrt((std::max)(epsfcn,epsmch));
37  msum = ml + mu + 1;
38  if (msum >= n) {
39  /* computation of dense approximate jacobian. */
40  for (j = 0; j < n; ++j) {
41  temp = x[j];
42  h = eps * abs(temp);
43  if (h == 0.)
44  h = eps;
45  x[j] = temp + h;
46  iflag = Functor(x, wa1);
47  if (iflag < 0)
48  return iflag;
49  x[j] = temp;
50  fjac.col(j) = (wa1-fvec)/h;
51  }
52 
53  }else {
54  /* computation of banded approximate jacobian. */
55  for (k = 0; k < msum; ++k) {
56  for (j = k; (msum<0) ? (j>n): (j<n); j += msum) {
57  wa2[j] = x[j];
58  h = eps * abs(wa2[j]);
59  if (h == 0.) h = eps;
60  x[j] = wa2[j] + h;
61  }
62  iflag = Functor(x, wa1);
63  if (iflag < 0)
64  return iflag;
65  for (j = k; (msum<0) ? (j>n): (j<n); j += msum) {
66  x[j] = wa2[j];
67  h = eps * abs(wa2[j]);
68  if (h == 0.) h = eps;
69  fjac.col(j).setZero();
70  start = std::max<Index>(0,j-mu);
71  length = (std::min)(n-1, j+ml) - start + 1;
72  fjac.col(j).segment(start, length) = ( wa1.segment(start, length)-fvec.segment(start, length))/h;
73  }
74  }
75  }
76  return 0;
77 }
78 
79 } // end namespace internal
80 
81 } // end namespace Eigen
int n
#define eigen_assert(x)
Derived & setZero(Index rows, Index cols)
DenseIndex fdjac1(const FunctorType &Functor, Matrix< Scalar, Dynamic, 1 > &x, Matrix< Scalar, Dynamic, 1 > &fvec, Matrix< Scalar, Dynamic, Dynamic > &fjac, DenseIndex ml, DenseIndex mu, Scalar epsfcn)
Definition: fdjac1.h:8
: 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) > sqrt(const Eigen::AutoDiffScalar< DerType > &x)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
CleanedUpDerType< DerType >::type() min(const AutoDiffScalar< DerType > &x, const T &y)
CleanedUpDerType< DerType >::type() max(const AutoDiffScalar< DerType > &x, const T &y)
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_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