Eigen-Contrib  5.0.1
 
Loading...
Searching...
No Matches
AutoDiffScalar.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9// SPDX-License-Identifier: MPL-2.0
10
11#ifndef EIGEN_AUTODIFF_SCALAR_H
12#define EIGEN_AUTODIFF_SCALAR_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18
19namespace internal {
20
21template <typename DerivativeType, bool Enable>
22struct auto_diff_special_op;
23
24template <typename DerivativeType, typename OtherDerivativeType, typename EnableIf = void>
25struct maybe_coherent_pad_helper {
26 static constexpr int SizeAtCompileTime =
27 max_size_prefer_dynamic(DerivativeType::SizeAtCompileTime, OtherDerivativeType::SizeAtCompileTime);
28 using type = CoherentPadOp<DerivativeType, SizeAtCompileTime>;
29 static type pad(const DerivativeType& x, const OtherDerivativeType& y) {
30 // CoherentPadOp uses variable_if_dynamic<SizeAtCompileTime>. In this case, `SizeAtCompileTime` might
31 // be Dynamic, so we need to take the runtime maximum of x, y.
32 return CoherentPadOp<DerivativeType, SizeAtCompileTime>(x, numext::maxi(x.size(), y.size()));
33 }
34};
35
36// Both are fixed-sized and equal, don't need to pad.
37// Both are fixed-size and this is larger than other, don't need to pad.
38template <typename DerivativeType, typename OtherDerivativeType>
39struct maybe_coherent_pad_helper<
40 DerivativeType, OtherDerivativeType,
41 std::enable_if_t<enum_ge_not_dynamic(DerivativeType::SizeAtCompileTime, OtherDerivativeType::SizeAtCompileTime)>> {
42 using type = const DerivativeType&;
43 static const DerivativeType& pad(const DerivativeType& x, const OtherDerivativeType& /*y*/) { return x; }
44};
45
46template <typename DerivativeType, typename OtherDerivativeType>
47typename maybe_coherent_pad_helper<DerivativeType, OtherDerivativeType>::type MaybeCoherentPad(
48 const DerivativeType& x, const OtherDerivativeType& y) {
49 return maybe_coherent_pad_helper<DerivativeType, OtherDerivativeType>::pad(x, y);
50}
51
52template <typename Op, typename LhsDerivativeType, typename RhsDerivativeType>
53auto MakeCoherentCwiseBinaryOp(const LhsDerivativeType& x, const RhsDerivativeType& y, Op op = Op()) {
54 const auto& lhs = MaybeCoherentPad(x, y);
55 const auto& rhs = MaybeCoherentPad(y, x);
56 return CwiseBinaryOp<Op, remove_all_t<decltype(lhs)>, remove_all_t<decltype(rhs)>>(lhs, rhs, op);
57}
58
59} // namespace internal
60
61template <typename DerivativeType>
62class AutoDiffScalar;
63
64template <typename NewDerType>
65inline AutoDiffScalar<NewDerType> MakeAutoDiffScalar(const typename NewDerType::Scalar& value, const NewDerType& der) {
66 return AutoDiffScalar<NewDerType>(value, der);
67}
68
94
95template <typename DerivativeType>
97 : public internal::auto_diff_special_op<
98 DerivativeType, !std::is_same<typename internal::traits<internal::remove_all_t<DerivativeType>>::Scalar,
99 typename NumTraits<typename internal::traits<
100 internal::remove_all_t<DerivativeType>>::Scalar>::Real>::value> {
101 public:
102 typedef internal::auto_diff_special_op<
103 DerivativeType,
104 !std::is_same<
105 typename internal::traits<internal::remove_all_t<DerivativeType>>::Scalar,
107 Base;
108 typedef internal::remove_all_t<DerivativeType> DerType;
109 typedef typename internal::traits<DerType>::Scalar Scalar;
110 typedef typename NumTraits<Scalar>::Real Real;
111
112 using Base::operator+;
113 using Base::operator*;
114
117
120 AutoDiffScalar(const Scalar& value, int nbDer, int derNumber) : m_value(value), m_derivatives(DerType::Zero(nbDer)) {
121 m_derivatives.coeffRef(derNumber) = Scalar(1);
122 }
123
126 /*explicit*/ AutoDiffScalar(const Real& value) : m_value(value) {
127 if (m_derivatives.size() > 0) m_derivatives.setZero();
128 }
129
131 AutoDiffScalar(const Scalar& value, const DerType& der) : m_value(value), m_derivatives(der) {}
132
133#ifndef EIGEN_PARSED_BY_DOXYGEN
134 template <typename OtherDerType,
135 std::enable_if_t<
136 std::is_same<Scalar, typename internal::traits<internal::remove_all_t<OtherDerType>>::Scalar>::value &&
137 std::is_convertible<OtherDerType, DerType>::value,
138 int> = 0>
139#else
140 template <typename OtherDerType>
141#endif
143 : m_value(other.value()), m_derivatives(other.derivatives()) {
144 }
145
146#ifndef EIGEN_PARSED_BY_DOXYGEN
147 template <typename OtherDerType>
148 EIGEN_DEPRECATED_WITH_REASON("Omit the implementation-only second argument.")
150 const AutoDiffScalar<OtherDerType>& other,
151 std::enable_if_t<
152 std::is_same<Scalar, typename internal::traits<internal::remove_all_t<OtherDerType>>::Scalar>::value &&
153 std::is_convertible<OtherDerType, DerType>::value,
154 void*>)
155 : AutoDiffScalar(other) {}
156#endif
157
158 friend std::ostream& operator<<(std::ostream& s, const AutoDiffScalar& a) { return s << a.value(); }
159
160 AutoDiffScalar(const AutoDiffScalar& other) : m_value(other.value()), m_derivatives(other.derivatives()) {}
161
162 template <typename OtherDerType>
163 inline AutoDiffScalar& operator=(const AutoDiffScalar<OtherDerType>& other) {
164 m_value = other.value();
165 m_derivatives = other.derivatives();
166 return *this;
167 }
168
169 inline AutoDiffScalar& operator=(const AutoDiffScalar& other) {
170 m_value = other.value();
171 m_derivatives = other.derivatives();
172 return *this;
173 }
174
175 inline AutoDiffScalar& operator=(const Scalar& other) {
176 m_value = other;
177 if (m_derivatives.size() > 0) m_derivatives.setZero();
178 return *this;
179 }
180
181 // inline operator const Scalar& () const { return m_value; }
182 // inline operator Scalar& () { return m_value; }
183
184 inline const Scalar& value() const { return m_value; }
185 inline Scalar& value() { return m_value; }
186
187 inline const DerType& derivatives() const { return m_derivatives; }
188 inline DerType& derivatives() { return m_derivatives; }
189
190 inline bool operator<(const Scalar& other) const { return m_value < other; }
191 inline bool operator<=(const Scalar& other) const { return m_value <= other; }
192 inline bool operator>(const Scalar& other) const { return m_value > other; }
193 inline bool operator>=(const Scalar& other) const { return m_value >= other; }
194 inline bool operator==(const Scalar& other) const { return m_value == other; }
195 inline bool operator!=(const Scalar& other) const { return m_value != other; }
196
197 friend inline bool operator<(const Scalar& a, const AutoDiffScalar& b) { return a < b.value(); }
198 friend inline bool operator<=(const Scalar& a, const AutoDiffScalar& b) { return a <= b.value(); }
199 friend inline bool operator>(const Scalar& a, const AutoDiffScalar& b) { return a > b.value(); }
200 friend inline bool operator>=(const Scalar& a, const AutoDiffScalar& b) { return a >= b.value(); }
201 friend inline bool operator==(const Scalar& a, const AutoDiffScalar& b) { return a == b.value(); }
202 friend inline bool operator!=(const Scalar& a, const AutoDiffScalar& b) { return a != b.value(); }
203
204 template <typename OtherDerType>
205 inline bool operator<(const AutoDiffScalar<OtherDerType>& b) const {
206 return m_value < b.value();
207 }
208 template <typename OtherDerType>
209 inline bool operator<=(const AutoDiffScalar<OtherDerType>& b) const {
210 return m_value <= b.value();
211 }
212 template <typename OtherDerType>
213 inline bool operator>(const AutoDiffScalar<OtherDerType>& b) const {
214 return m_value > b.value();
215 }
216 template <typename OtherDerType>
217 inline bool operator>=(const AutoDiffScalar<OtherDerType>& b) const {
218 return m_value >= b.value();
219 }
220 template <typename OtherDerType>
221 inline bool operator==(const AutoDiffScalar<OtherDerType>& b) const {
222 return m_value == b.value();
223 }
224 template <typename OtherDerType>
225 inline bool operator!=(const AutoDiffScalar<OtherDerType>& b) const {
226 return m_value != b.value();
227 }
228
229 inline AutoDiffScalar<DerType&> operator+(const Scalar& other) const {
230 return AutoDiffScalar<DerType&>(m_value + other, m_derivatives);
231 }
232
233 friend inline AutoDiffScalar<DerType&> operator+(const Scalar& a, const AutoDiffScalar& b) {
234 return AutoDiffScalar<DerType&>(a + b.value(), b.derivatives());
235 }
236
237 inline AutoDiffScalar& operator+=(const Scalar& other) {
238 value() += other;
239 return *this;
240 }
241
242 template <typename OtherDerType>
243 inline auto operator+(const AutoDiffScalar<OtherDerType>& other) const {
244 return MakeAutoDiffScalar(
245 m_value + other.value(),
246 internal::MakeCoherentCwiseBinaryOp<internal::scalar_sum_op<Scalar>>(m_derivatives, other.derivatives()));
247 }
248
249 template <typename OtherDerType>
250 inline AutoDiffScalar& operator+=(const AutoDiffScalar<OtherDerType>& other) {
251 (*this) = (*this) + other;
252 return *this;
253 }
254
255 inline AutoDiffScalar<DerType&> operator-(const Scalar& b) const {
256 return AutoDiffScalar<DerType&>(m_value - b, m_derivatives);
257 }
258
259 friend inline AutoDiffScalar<CwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const DerType>> operator-(
260 const Scalar& a, const AutoDiffScalar& b) {
261 return AutoDiffScalar<CwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const DerType>>(a - b.value(),
262 -b.derivatives());
263 }
264
265 inline AutoDiffScalar& operator-=(const Scalar& other) {
266 value() -= other;
267 return *this;
268 }
269
270 template <typename OtherDerType>
271 inline auto operator-(const AutoDiffScalar<OtherDerType>& other) const {
272 return MakeAutoDiffScalar(m_value - other.value(),
273 internal::MakeCoherentCwiseBinaryOp<internal::scalar_difference_op<Scalar>>(
274 m_derivatives, other.derivatives()));
275 }
276
277 template <typename OtherDerType>
278 inline AutoDiffScalar& operator-=(const AutoDiffScalar<OtherDerType>& other) {
279 *this = *this - other;
280 return *this;
281 }
282
283 inline AutoDiffScalar<CwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const DerType>> operator-() const {
284 return AutoDiffScalar<CwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const DerType>>(-m_value, -m_derivatives);
285 }
286
287 inline auto operator*(const Scalar& other) const {
288 return MakeAutoDiffScalar(m_value * other, m_derivatives * other);
289 }
290
291 friend inline auto operator*(const Scalar& other, const AutoDiffScalar& a) {
292 return MakeAutoDiffScalar(a.value() * other, a.derivatives() * other);
293 }
294
295 inline auto operator/(const Scalar& other) const {
296 return MakeAutoDiffScalar(m_value / other, (m_derivatives * (Scalar(1) / other)));
297 }
298
299 friend inline auto operator/(const Scalar& other, const AutoDiffScalar& a) {
300 return MakeAutoDiffScalar(other / a.value(), a.derivatives() * (Scalar(-other) / (a.value() * a.value())));
301 }
302
303 template <typename OtherDerType>
304 inline auto operator/(const AutoDiffScalar<OtherDerType>& other) const {
305 return MakeAutoDiffScalar(m_value / other.value(),
306 internal::MakeCoherentCwiseBinaryOp<internal::scalar_difference_op<Scalar>>(
307 m_derivatives * other.value(), (other.derivatives() * m_value)) *
308 (Scalar(1) / (other.value() * other.value())));
309 }
310
311 template <typename OtherDerType>
312 inline auto operator*(const AutoDiffScalar<OtherDerType>& other) const {
313 return MakeAutoDiffScalar(m_value * other.value(),
314 internal::MakeCoherentCwiseBinaryOp<internal::scalar_sum_op<Scalar>>(
315 m_derivatives * other.value(), other.derivatives() * m_value));
316 }
317
318 inline AutoDiffScalar& operator*=(const Scalar& other) {
319 *this = *this * other;
320 return *this;
321 }
322
323 template <typename OtherDerType>
324 inline AutoDiffScalar& operator*=(const AutoDiffScalar<OtherDerType>& other) {
325 *this = *this * other;
326 return *this;
327 }
328
329 inline AutoDiffScalar& operator/=(const Scalar& other) {
330 *this = *this / other;
331 return *this;
332 }
333
334 template <typename OtherDerType>
335 inline AutoDiffScalar& operator/=(const AutoDiffScalar<OtherDerType>& other) {
336 *this = *this / other;
337 return *this;
338 }
339
340 protected:
341 Scalar m_value;
342 DerType m_derivatives;
343};
344
345namespace internal {
346
347template <typename DerivativeType>
348struct auto_diff_special_op<DerivativeType, true> {
349 typedef remove_all_t<DerivativeType> DerType;
350 typedef typename traits<DerType>::Scalar Scalar;
351 typedef typename NumTraits<Scalar>::Real Real;
352
353 const AutoDiffScalar<DerivativeType>& derived() const {
354 return *static_cast<const AutoDiffScalar<DerivativeType>*>(this);
355 }
356 AutoDiffScalar<DerivativeType>& derived() { return *static_cast<AutoDiffScalar<DerivativeType>*>(this); }
357
358 inline AutoDiffScalar<DerType&> operator+(const Real& other) const {
359 return AutoDiffScalar<DerType&>(derived().value() + other, derived().derivatives());
360 }
361
362 friend inline AutoDiffScalar<DerType&> operator+(const Real& a, const AutoDiffScalar<DerivativeType>& b) {
363 return AutoDiffScalar<DerType&>(a + b.value(), b.derivatives());
364 }
365
366 inline AutoDiffScalar<DerivativeType>& operator+=(const Real& other) {
367 derived().value() += other;
368 return derived();
369 }
370
371 inline AutoDiffScalar<typename CwiseUnaryOp<bind2nd_op<scalar_product_op<Scalar, Real>>, DerType>::Type> operator*(
372 const Real& other) const {
373 return AutoDiffScalar<typename CwiseUnaryOp<bind2nd_op<scalar_product_op<Scalar, Real>>, DerType>::Type>(
374 derived().value() * other, derived().derivatives() * other);
375 }
376
377 friend inline AutoDiffScalar<typename CwiseUnaryOp<bind1st_op<scalar_product_op<Real, Scalar>>, DerType>::Type>
378 operator*(const Real& other, const AutoDiffScalar<DerivativeType>& a) {
379 return AutoDiffScalar<typename CwiseUnaryOp<bind1st_op<scalar_product_op<Real, Scalar>>, DerType>::Type>(
380 a.value() * other, a.derivatives() * other);
381 }
382
383 inline AutoDiffScalar<DerivativeType>& operator*=(const Scalar& other) {
384 *this = *this * other;
385 return derived();
386 }
387};
388
389template <typename DerivativeType>
390struct auto_diff_special_op<DerivativeType, false> {
391 void operator*() const;
392 void operator-() const;
393 void operator+() const;
394};
395
396} // end namespace internal
397
398template <typename DerType, typename BinOp>
399struct ScalarBinaryOpTraits<AutoDiffScalar<DerType>, typename DerType::Scalar, BinOp> {
400 typedef AutoDiffScalar<DerType> ReturnType;
401};
402
403template <typename DerType, typename BinOp>
404struct ScalarBinaryOpTraits<typename DerType::Scalar, AutoDiffScalar<DerType>, BinOp> {
405 typedef AutoDiffScalar<DerType> ReturnType;
406};
407
408#define EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(FUNC, CODE) \
409 template <typename DerType> \
410 inline auto FUNC(const Eigen::AutoDiffScalar<DerType>& x) { \
411 using namespace Eigen; \
412 typedef typename Eigen::internal::traits<Eigen::internal::remove_all_t<DerType>>::Scalar Scalar; \
413 EIGEN_UNUSED_VARIABLE(sizeof(Scalar)); \
414 CODE; \
415 }
416
417template <typename DerType>
418struct CleanedUpDerType {
419 typedef AutoDiffScalar<typename Eigen::internal::remove_all_t<DerType>::PlainObject> type;
420};
421
422template <typename DerType>
423inline const AutoDiffScalar<DerType>& conj(const AutoDiffScalar<DerType>& x) {
424 return x;
425}
426template <typename DerType>
427inline const AutoDiffScalar<DerType>& real(const AutoDiffScalar<DerType>& x) {
428 return x;
429}
430template <typename DerType>
431inline typename DerType::Scalar imag(const AutoDiffScalar<DerType>&) {
432 return 0.;
433}
434template <typename DerType>
435inline bool(isnan)(const AutoDiffScalar<DerType>& x) {
436 return (numext::isnan)(x.value());
437}
438template <typename DerType>
439inline bool(isinf)(const AutoDiffScalar<DerType>& x) {
440 return (numext::isinf)(x.value());
441}
442template <typename DerType>
443inline bool(isfinite)(const AutoDiffScalar<DerType>& x) {
444 return (numext::isfinite)(x.value());
445}
446template <typename DerType, typename T>
447inline typename CleanedUpDerType<DerType>::type(min)(const AutoDiffScalar<DerType>& x, const T& y) {
448 typedef typename CleanedUpDerType<DerType>::type ADS;
449 return (x <= y ? ADS(x) : ADS(y));
450}
451template <typename DerType, typename T>
452inline typename CleanedUpDerType<DerType>::type(max)(const AutoDiffScalar<DerType>& x, const T& y) {
453 typedef typename CleanedUpDerType<DerType>::type ADS;
454 return (x >= y ? ADS(x) : ADS(y));
455}
456template <typename DerType, typename T>
457inline typename CleanedUpDerType<DerType>::type(min)(const T& x, const AutoDiffScalar<DerType>& y) {
458 typedef typename CleanedUpDerType<DerType>::type ADS;
459 return (x < y ? ADS(x) : ADS(y));
460}
461template <typename DerType, typename T>
462inline typename CleanedUpDerType<DerType>::type(max)(const T& x, const AutoDiffScalar<DerType>& y) {
463 typedef typename CleanedUpDerType<DerType>::type ADS;
464 return (x > y ? ADS(x) : ADS(y));
465}
466template <typename DerType>
467inline
468 typename CleanedUpDerType<DerType>::type(min)(const AutoDiffScalar<DerType>& x, const AutoDiffScalar<DerType>& y) {
469 // Match std::min / max(ADS, ADS): on tie, return the first argument.
470 return (x.value() <= y.value() ? x : y);
471}
472template <typename DerType>
473inline
474 typename CleanedUpDerType<DerType>::type(max)(const AutoDiffScalar<DerType>& x, const AutoDiffScalar<DerType>& y) {
475 return (x.value() >= y.value() ? x : y);
476}
477
478EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(abs, using std::abs;
479 return Eigen::MakeAutoDiffScalar(abs(x.value()),
480 x.derivatives() * (x.value() < 0 ? -1 : 1));)
481
482EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(abs2, using numext::abs2;
483 return Eigen::MakeAutoDiffScalar(abs2(x.value()),
484 x.derivatives() * (Scalar(2) * x.value()));)
485
486EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(sqrt, using std::sqrt; Scalar sqrtx = sqrt(x.value());
487 return Eigen::MakeAutoDiffScalar(sqrtx, x.derivatives() * (Scalar(0.5) / sqrtx));)
488
489EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(cos, using std::cos; using std::sin;
490 return Eigen::MakeAutoDiffScalar(cos(x.value()),
491 x.derivatives() * (-sin(x.value())));)
492
493EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(sin, using std::sin; using std::cos;
494 return Eigen::MakeAutoDiffScalar(sin(x.value()), x.derivatives() * cos(x.value()));)
495
496EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(exp, using std::exp; Scalar expx = exp(x.value());
497 return Eigen::MakeAutoDiffScalar(expx, x.derivatives() * expx);)
498
499EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(log, using std::log;
500 return Eigen::MakeAutoDiffScalar(log(x.value()),
501 x.derivatives() * (Scalar(1) / x.value()));)
502
503template <typename DerType>
504inline auto pow(const Eigen::AutoDiffScalar<DerType>& x,
505 const typename internal::traits<internal::remove_all_t<DerType>>::Scalar& y) {
506 using namespace Eigen;
507 using std::pow;
508 return Eigen::MakeAutoDiffScalar(pow(x.value(), y), x.derivatives() * (y * pow(x.value(), y - 1)));
509}
510
511template <typename DerTypeA, typename DerTypeB>
514 using std::atan2;
515 typedef typename internal::traits<internal::remove_all_t<DerTypeA>>::Scalar Scalar;
517 PlainADS ret;
518 ret.value() = atan2(a.value(), b.value());
519
520 Scalar squared_hypot = a.value() * a.value() + b.value() * b.value();
521
522 // if (squared_hypot==0) the derivation is undefined and the following results in a NaN:
523 ret.derivatives() = (a.derivatives() * b.value() - a.value() * b.derivatives()) / squared_hypot;
524
525 return ret;
526}
527
528EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(tan, using std::tan; using std::cos; return Eigen::MakeAutoDiffScalar(
529 tan(x.value()), x.derivatives() * (Scalar(1) / numext::abs2(cos(x.value()))));)
530
531EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(asin, using std::sqrt; using std::asin; return Eigen::MakeAutoDiffScalar(
532 asin(x.value()),
533 x.derivatives() * (Scalar(1) / sqrt(1 - numext::abs2(x.value()))));)
534
535EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(acos, using std::sqrt; using std::acos; return Eigen::MakeAutoDiffScalar(
536 acos(x.value()),
537 x.derivatives() * (Scalar(-1) / sqrt(1 - numext::abs2(x.value()))));)
538
539EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(
540 tanh, using std::cosh; using std::tanh;
541 return Eigen::MakeAutoDiffScalar(tanh(x.value()), x.derivatives() * (Scalar(1) / numext::abs2(cosh(x.value()))));)
542
543EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(sinh, using std::sinh; using std::cosh;
544 return Eigen::MakeAutoDiffScalar(sinh(x.value()),
545 x.derivatives() * cosh(x.value()));)
546
547EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(cosh, using std::sinh; using std::cosh;
548 return Eigen::MakeAutoDiffScalar(cosh(x.value()),
549 x.derivatives() * sinh(x.value()));)
550
551#undef EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY
552
553template <typename DerType>
555 : NumTraits<typename NumTraits<typename internal::remove_all_t<DerType>::Scalar>::Real> {
556 typedef internal::remove_all_t<DerType> DerTypeCleaned;
558 DerTypeCleaned::RowsAtCompileTime, DerTypeCleaned::ColsAtCompileTime, 0,
559 DerTypeCleaned::MaxRowsAtCompileTime, DerTypeCleaned::MaxColsAtCompileTime>>
560 Real;
561 typedef AutoDiffScalar<DerType> NonInteger;
562 typedef AutoDiffScalar<DerType> Nested;
564 enum { RequireInitialization = 1 };
565};
566
567namespace internal {
568template <typename DerivativeType>
569struct is_identically_zero_impl<AutoDiffScalar<DerivativeType>> {
570 static inline bool run(const AutoDiffScalar<DerivativeType>& s) {
571 const DerivativeType& derivatives = s.derivatives();
572 for (int i = 0; i < derivatives.size(); ++i) {
573 if (!numext::is_exactly_zero(derivatives[i])) {
574 return false;
575 }
576 }
577 return numext::is_exactly_zero(s.value());
578 }
579};
580} // namespace internal
581} // namespace Eigen
582
583namespace std {
584
585template <typename T>
586class numeric_limits<Eigen::AutoDiffScalar<T>> : public numeric_limits<typename T::Scalar> {};
587
588template <typename T>
589class numeric_limits<Eigen::AutoDiffScalar<T&>> : public numeric_limits<typename T::Scalar> {};
590
591} // namespace std
592
593#endif // EIGEN_AUTODIFF_SCALAR_H
A scalar type replacement with automatic differentiation capability.
Definition AutoDiffScalar.h:100
AutoDiffScalar()
Definition AutoDiffScalar.h:116
AutoDiffScalar(const Scalar &value, int nbDer, int derNumber)
Definition AutoDiffScalar.h:120
AutoDiffScalar(const Real &value)
Definition AutoDiffScalar.h:126
AutoDiffScalar(const Scalar &value, const DerType &der)
Definition AutoDiffScalar.h:131
Namespace containing all symbols from the Eigen library.