fdjac1.h
Go to the documentation of this file.
1 // IWYU pragma: private
3 
4 namespace Eigen {
5 
6 namespace internal {
7 
8 template <typename FunctorType, typename Scalar>
11  using std::abs;
12  using std::sqrt;
13 
14  typedef DenseIndex Index;
15 
16  /* Local variables */
17  Scalar h;
18  Index j, k;
19  Scalar eps, temp;
20  Index msum;
21  int iflag;
22  Index start, length;
23 
24  /* Function Body */
25  const Scalar epsmch = NumTraits<Scalar>::epsilon();
26  const Index n = x.size();
27  eigen_assert(fvec.size() == n);
30 
31  eps = sqrt((std::max)(epsfcn, epsmch));
32  msum = ml + mu + 1;
33  if (msum >= n) {
34  /* computation of dense approximate jacobian. */
35  for (j = 0; j < n; ++j) {
36  temp = x[j];
37  h = eps * abs(temp);
38  if (h == 0.) h = eps;
39  x[j] = temp + h;
40  iflag = Functor(x, wa1);
41  if (iflag < 0) return iflag;
42  x[j] = temp;
43  fjac.col(j) = (wa1 - fvec) / h;
44  }
45 
46  } else {
47  /* computation of banded approximate jacobian. */
48  for (k = 0; k < msum; ++k) {
49  for (j = k; (msum < 0) ? (j > n) : (j < n); j += msum) {
50  wa2[j] = x[j];
51  h = eps * abs(wa2[j]);
52  if (h == 0.) h = eps;
53  x[j] = wa2[j] + h;
54  }
55  iflag = Functor(x, wa1);
56  if (iflag < 0) return iflag;
57  for (j = k; (msum < 0) ? (j > n) : (j < n); j += msum) {
58  x[j] = wa2[j];
59  h = eps * abs(wa2[j]);
60  if (h == 0.) h = eps;
61  fjac.col(j).setZero();
62  start = std::max<Index>(0, j - mu);
63  length = (std::min)(n - 1, j + ml) - start + 1;
64  fjac.col(j).segment(start, length) = (wa1.segment(start, length) - fvec.segment(start, length)) / h;
65  }
66  }
67  }
68  return 0;
69 }
70 
71 } // end namespace internal
72 
73 } // end namespace Eigen
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
#define eigen_assert(x)
Definition: Macros.h:910
SCALAR Scalar
Definition: bench_gemm.cpp:45
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:569
#define min(a, b)
Definition: datatypes.h:22
#define max(a, b)
Definition: datatypes.h:23
char char char int int * k
Definition: level2_impl.h:374
double eps
Definition: crbond_bessel.cc:24
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:9
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
Definition: Meta.h:75
std::complex< double > mu
Definition: time_harmonic_fourier_decomposed_linear_elasticity/cylinder/cylinder.cc:52
Definition: Eigen_Colamd.h:49
void start(const unsigned &i)
(Re-)start i-th timer
Definition: oomph_utilities.cc:243
double epsilon
Definition: osc_ring_sarah_asymptotics.h:43
list x
Definition: plotDoE.py:28
Definition: NonLinearOptimization.cpp:97
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2