10 #ifndef EIGEN_AUTODIFF_SCALAR_H
11 #define EIGEN_AUTODIFF_SCALAR_H
20 template <
typename DerivativeType,
bool Enable>
23 template <
typename DerivativeType,
typename OtherDerivativeType,
typename EnableIf =
void>
28 static type pad(
const DerivativeType&
x,
const OtherDerivativeType&
y) {
37 template <
typename DerivativeType,
typename OtherDerivativeType>
39 DerivativeType, OtherDerivativeType,
40 std::enable_if_t<enum_ge_not_dynamic(DerivativeType::SizeAtCompileTime, OtherDerivativeType::SizeAtCompileTime)>> {
41 using type =
const DerivativeType&;
42 static const DerivativeType&
pad(
const DerivativeType&
x,
const OtherDerivativeType& ) {
return x; }
45 template <
typename DerivativeType,
typename OtherDerivativeType>
47 const DerivativeType&
x,
const OtherDerivativeType&
y) {
51 template <
typename Op,
typename LhsDerivativeType,
typename RhsDerivativeType>
60 template <
typename DerivativeType>
63 template <
typename NewDerType>
94 template <
typename DerivativeType>
97 DerivativeType, !internal::is_same<typename internal::traits<internal::remove_all_t<DerivativeType>>::Scalar,
98 typename NumTraits<typename internal::traits<
99 internal::remove_all_t<DerivativeType>>::Scalar>::Real>::value> {
111 using Base::operator+;
112 using Base::operator*;
132 template <
typename OtherDerType>
135 #ifndef EIGEN_PARSED_BY_DOXYGEN
150 template <
typename OtherDerType>
192 template <
typename OtherDerType>
196 template <
typename OtherDerType>
200 template <
typename OtherDerType>
204 template <
typename OtherDerType>
208 template <
typename OtherDerType>
212 template <
typename OtherDerType>
240 template <
typename OtherDerType>
247 template <
typename OtherDerType>
249 (*this) = (*this) + other;
268 template <
typename OtherDerType>
275 template <
typename OtherDerType>
277 *
this = *
this - other;
333 template <
typename OtherDerType>
341 template <
typename OtherDerType>
349 *
this = *
this * other;
353 template <
typename OtherDerType>
355 *
this = *
this * other;
360 *
this = *
this / other;
364 template <
typename OtherDerType>
366 *
this = *
this / other;
377 template <
typename DerivativeType>
410 derived().value() += other;
415 const Real& other)
const {
417 derived().value() * other, derived().derivatives() * other);
423 a.value() * other,
a.derivatives() * other);
427 *
this = *
this * other;
432 template <
typename DerivativeType>
441 template <
typename DerType,
typename BinOp>
446 template <
typename DerType,
typename BinOp>
467 #define EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(FUNC, CODE) \
468 template <typename DerType> \
469 inline auto FUNC(const Eigen::AutoDiffScalar<DerType>& x) { \
470 using namespace Eigen; \
471 typedef typename Eigen::internal::traits<Eigen::internal::remove_all_t<DerType>>::Scalar Scalar; \
472 EIGEN_UNUSED_VARIABLE(sizeof(Scalar)); \
476 template <
typename DerType>
481 template <
typename DerType>
485 template <
typename DerType>
489 template <
typename DerType>
493 template <
typename DerType,
typename T>
496 return (
x <=
y ? ADS(
x) : ADS(
y));
498 template <
typename DerType,
typename T>
501 return (
x >=
y ? ADS(
x) : ADS(
y));
503 template <
typename DerType,
typename T>
506 return (
x <
y ? ADS(
x) : ADS(
y));
508 template <
typename DerType,
typename T>
511 return (
x >
y ? ADS(
x) : ADS(
y));
513 template <
typename DerType>
516 return (
x.value() <
y.value() ?
x :
y);
518 template <
typename DerType>
521 return (
x.value() >=
y.value() ?
x :
y);
526 x.derivatives() * (
x.value() < 0 ? -1 : 1));)
530 x.derivatives() * (
Scalar(2) *
x.value()));)
537 x.derivatives() * (-
sin(
x.value())));)
547 x.derivatives() * (
Scalar(1) /
x.value()));)
549 template <typename DerType>
552 using namespace Eigen;
557 template <
typename DerTypeA,
typename DerTypeB>
566 Scalar squared_hypot =
a.value() *
a.value() +
b.value() *
b.value();
569 ret.derivatives() = (
a.derivatives() *
b.value() -
a.value() *
b.derivatives()) / squared_hypot;
591 x.derivatives() *
cosh(
x.value()));)
595 x.derivatives() *
sinh(
x.value()));)
599 template <typename DerType>
604 DerTypeCleaned::RowsAtCompileTime, DerTypeCleaned::ColsAtCompileTime, 0,
605 DerTypeCleaned::MaxRowsAtCompileTime, DerTypeCleaned::MaxColsAtCompileTime>>
610 enum { RequireInitialization = 1 };
614 template <
typename DerivativeType>
617 const DerivativeType& derivatives =
s.derivatives();
618 for (
int i = 0;
i < derivatives.size(); ++
i) {
631 template <
typename T>
634 template <
typename T>
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
AnnoyingScalar cos(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:136
AnnoyingScalar atan2(const AnnoyingScalar &y, const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:139
AnnoyingScalar acos(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:138
AnnoyingScalar sin(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:137
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Scalar * b
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
A scalar type replacement with automatic differentiation capability.
Definition: AutoDiffScalar.h:99
auto operator/(const AutoDiffScalar< OtherDerType > &other) const
Definition: AutoDiffScalar.h:334
AutoDiffScalar & operator-=(const Scalar &other)
Definition: AutoDiffScalar.h:263
AutoDiffScalar()
Definition: AutoDiffScalar.h:115
internal::remove_all_t< DerivativeType > DerType
Definition: AutoDiffScalar.h:107
bool operator>(const Scalar &other) const
Definition: AutoDiffScalar.h:180
auto operator*(const AutoDiffScalar< OtherDerType > &other) const
Definition: AutoDiffScalar.h:342
auto operator-(const AutoDiffScalar< OtherDerType > &other) const
Definition: AutoDiffScalar.h:269
internal::traits< DerType >::Scalar Scalar
Definition: AutoDiffScalar.h:108
AutoDiffScalar< DerType & > operator-(const Scalar &b) const
Definition: AutoDiffScalar.h:253
const Scalar & value() const
Definition: AutoDiffScalar.h:172
AutoDiffScalar & operator=(const AutoDiffScalar &other)
Definition: AutoDiffScalar.h:157
NumTraits< Scalar >::Real Real
Definition: AutoDiffScalar.h:109
friend AutoDiffScalar< CwiseUnaryOp< internal::scalar_opposite_op< Scalar >, const DerType > > operator-(const Scalar &a, const AutoDiffScalar &b)
Definition: AutoDiffScalar.h:257
Scalar m_value
Definition: AutoDiffScalar.h:371
AutoDiffScalar & operator*=(const AutoDiffScalar< OtherDerType > &other)
Definition: AutoDiffScalar.h:354
Scalar & value()
Definition: AutoDiffScalar.h:173
bool operator==(const AutoDiffScalar< OtherDerType > &b) const
Definition: AutoDiffScalar.h:209
auto operator+(const AutoDiffScalar< OtherDerType > &other) const
Definition: AutoDiffScalar.h:241
DerType & derivatives()
Definition: AutoDiffScalar.h:176
auto operator/(const Scalar &other) const
Definition: AutoDiffScalar.h:309
bool operator>(const AutoDiffScalar< OtherDerType > &b) const
Definition: AutoDiffScalar.h:201
friend AutoDiffScalar< DerType & > operator+(const Scalar &a, const AutoDiffScalar &b)
Definition: AutoDiffScalar.h:221
bool operator!=(const AutoDiffScalar< OtherDerType > &b) const
Definition: AutoDiffScalar.h:213
AutoDiffScalar(const AutoDiffScalar< OtherDerType > &other, std::enable_if_t< internal::is_same< Scalar, typename internal::traits< internal::remove_all_t< OtherDerType >>::Scalar >::value &&internal::is_convertible< OtherDerType, DerType >::value, void * >=0)
Definition: AutoDiffScalar.h:133
friend bool operator<(const Scalar &a, const AutoDiffScalar &b)
Definition: AutoDiffScalar.h:185
bool operator<(const Scalar &other) const
Definition: AutoDiffScalar.h:178
DerType m_derivatives
Definition: AutoDiffScalar.h:372
AutoDiffScalar & operator/=(const AutoDiffScalar< OtherDerType > &other)
Definition: AutoDiffScalar.h:365
auto operator*(const Scalar &other) const
Definition: AutoDiffScalar.h:285
bool operator<(const AutoDiffScalar< OtherDerType > &b) const
Definition: AutoDiffScalar.h:193
friend auto operator/(const Scalar &other, const AutoDiffScalar &a)
Definition: AutoDiffScalar.h:313
AutoDiffScalar(const AutoDiffScalar &other)
Definition: AutoDiffScalar.h:148
AutoDiffScalar & operator*=(const Scalar &other)
Definition: AutoDiffScalar.h:348
friend auto operator*(const Scalar &other, const AutoDiffScalar &a)
Definition: AutoDiffScalar.h:289
AutoDiffScalar & operator+=(const AutoDiffScalar< OtherDerType > &other)
Definition: AutoDiffScalar.h:248
bool operator<=(const Scalar &other) const
Definition: AutoDiffScalar.h:179
friend std::ostream & operator<<(std::ostream &s, const AutoDiffScalar &a)
Definition: AutoDiffScalar.h:146
bool operator<=(const AutoDiffScalar< OtherDerType > &b) const
Definition: AutoDiffScalar.h:197
friend bool operator>(const Scalar &a, const AutoDiffScalar &b)
Definition: AutoDiffScalar.h:187
bool operator>=(const Scalar &other) const
Definition: AutoDiffScalar.h:181
AutoDiffScalar(const Scalar &value, int nbDer, int derNumber)
Definition: AutoDiffScalar.h:119
friend bool operator==(const Scalar &a, const AutoDiffScalar &b)
Definition: AutoDiffScalar.h:189
AutoDiffScalar & operator=(const Scalar &other)
Definition: AutoDiffScalar.h:163
internal::auto_diff_special_op< DerivativeType, !internal::is_same< typename internal::traits< internal::remove_all_t< DerivativeType > >::Scalar, typename NumTraits< typename internal::traits< internal::remove_all_t< DerivativeType > >::Scalar >::Real >::value > Base
Definition: AutoDiffScalar.h:106
bool operator==(const Scalar &other) const
Definition: AutoDiffScalar.h:182
AutoDiffScalar< DerType & > operator+(const Scalar &other) const
Definition: AutoDiffScalar.h:217
friend bool operator!=(const Scalar &a, const AutoDiffScalar &b)
Definition: AutoDiffScalar.h:190
bool operator!=(const Scalar &other) const
Definition: AutoDiffScalar.h:183
AutoDiffScalar & operator-=(const AutoDiffScalar< OtherDerType > &other)
Definition: AutoDiffScalar.h:276
friend bool operator<=(const Scalar &a, const AutoDiffScalar &b)
Definition: AutoDiffScalar.h:186
AutoDiffScalar(const Real &value)
Definition: AutoDiffScalar.h:125
const DerType & derivatives() const
Definition: AutoDiffScalar.h:175
AutoDiffScalar(const Scalar &value, const DerType &der)
Definition: AutoDiffScalar.h:130
AutoDiffScalar & operator/=(const Scalar &other)
Definition: AutoDiffScalar.h:359
AutoDiffScalar & operator=(const AutoDiffScalar< OtherDerType > &other)
Definition: AutoDiffScalar.h:151
AutoDiffScalar & operator+=(const Scalar &other)
Definition: AutoDiffScalar.h:235
friend bool operator>=(const Scalar &a, const AutoDiffScalar &b)
Definition: AutoDiffScalar.h:188
AutoDiffScalar< CwiseUnaryOp< internal::scalar_opposite_op< Scalar >, const DerType > > operator-() const
Definition: AutoDiffScalar.h:281
bool operator>=(const AutoDiffScalar< OtherDerType > &b) const
Definition: AutoDiffScalar.h:205
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:79
Scalar * y
Definition: level1_cplx_impl.h:128
RealScalar s
Definition: level1_cplx_impl.h:130
Eigen::DenseIndex ret
Definition: level1_cplx_impl.h:43
const Scalar * a
Definition: level2_cplx_impl.h:32
char char * op
Definition: level2_impl.h:374
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 tanh(const bfloat16 &a)
Definition: BFloat16.h:639
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 cosh(const bfloat16 &a)
Definition: BFloat16.h:638
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 asin(const bfloat16 &a)
Definition: BFloat16.h:634
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 exp(const bfloat16 &a)
Definition: BFloat16.h:615
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 pow(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:625
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log(const bfloat16 &a)
Definition: BFloat16.h:618
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 sinh(const bfloat16 &a)
Definition: BFloat16.h:637
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 tan(const bfloat16 &a)
Definition: BFloat16.h:633
const Scalar & y
Definition: RandomImpl.h:36
auto MakeCoherentCwiseBinaryOp(const LhsDerivativeType &x, const RhsDerivativeType &y, Op op=Op())
Definition: AutoDiffScalar.h:52
typename remove_all< T >::type remove_all_t
Definition: Meta.h:142
maybe_coherent_pad_helper< DerivativeType, OtherDerivativeType >::type MaybeCoherentPad(const DerivativeType &x, const OtherDerivativeType &y)
Definition: AutoDiffScalar.h:46
constexpr int max_size_prefer_dynamic(A a, B b)
Definition: Meta.h:695
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
Definition: MathFunctions.h:926
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool is_exactly_zero(const X &x)
Definition: Meta.h:592
EIGEN_DEVICE_FUNC bool abs2(bool x)
Definition: MathFunctions.h:1102
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
AutoDiffScalar< Matrix< typename internal::traits< internal::remove_all_t< DerTypeA > >::Scalar, Dynamic, 1 > > atan2(const AutoDiffScalar< DerTypeA > &a, const AutoDiffScalar< DerTypeB > &b)
Definition: AutoDiffScalar.h:558
squared absolute value
Definition: GlobalFunctions.h:87
const AutoDiffScalar< DerType > & real(const AutoDiffScalar< DerType > &x)
Definition: AutoDiffScalar.h:486
DerType::Scalar imag(const AutoDiffScalar< DerType > &)
Definition: AutoDiffScalar.h:490
CleanedUpDerType< DerType >::type() min(const AutoDiffScalar< DerType > &x, const T &y)
Definition: AutoDiffScalar.h:494
CleanedUpDerType< DerType >::type() max(const AutoDiffScalar< DerType > &x, const T &y)
Definition: AutoDiffScalar.h:499
Scalar expx
Definition: AutoDiffScalar.h:542
const AutoDiffScalar< DerType > & conj(const AutoDiffScalar< DerType > &x)
Definition: AutoDiffScalar.h:482
const int Dynamic
Definition: Constants.h:25
EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(abs, using std::abs;return Eigen::MakeAutoDiffScalar(abs(x.value()), x.derivatives() *(x.value()< 0 ? -1 :1));) EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(abs2
AutoDiffScalar< NewDerType > MakeAutoDiffScalar(const typename NewDerType::Scalar &value, const NewDerType &der)
Definition: AutoDiffScalar.h:64
Definition: Eigen_Colamd.h:49
double Zero
Definition: pseudosolid_node_update_elements.cc:35
list x
Definition: plotDoE.py:28
Type
Type of JSON value.
Definition: rapidjson.h:513
Definition: AutoDiffScalar.h:477
AutoDiffScalar< typename Eigen::internal::remove_all_t< DerType >::PlainObject > type
Definition: AutoDiffScalar.h:478
T Real
Definition: NumTraits.h:183
AutoDiffScalar< DerType > NonInteger
Definition: AutoDiffScalar.h:607
NumTraits< typename DerTypeCleaned::Scalar >::Literal Literal
Definition: AutoDiffScalar.h:609
internal::remove_all_t< DerType > DerTypeCleaned
Definition: AutoDiffScalar.h:602
AutoDiffScalar< Matrix< typename NumTraits< typename DerTypeCleaned::Scalar >::Real, DerTypeCleaned::RowsAtCompileTime, DerTypeCleaned::ColsAtCompileTime, 0, DerTypeCleaned::MaxRowsAtCompileTime, DerTypeCleaned::MaxColsAtCompileTime > > Real
Definition: AutoDiffScalar.h:606
AutoDiffScalar< DerType > Nested
Definition: AutoDiffScalar.h:608
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217
AutoDiffScalar< DerType > ReturnType
Definition: AutoDiffScalar.h:443
AutoDiffScalar< DerType > ReturnType
Definition: AutoDiffScalar.h:448
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
Definition: XprHelper.h:1043
Definition: CoherentPadOp.h:41
friend AutoDiffScalar< typename CwiseUnaryOp< bind1st_op< scalar_product_op< Real, Scalar > >, DerType >::Type > operator*(const Real &other, const AutoDiffScalar< DerivativeType > &a)
Definition: AutoDiffScalar.h:421
friend AutoDiffScalar< DerType & > operator+(const Real &a, const AutoDiffScalar< DerivativeType > &b)
Definition: AutoDiffScalar.h:405
AutoDiffScalar< DerType & > operator+(const Real &other) const
Definition: AutoDiffScalar.h:401
const AutoDiffScalar< DerivativeType > & derived() const
Definition: AutoDiffScalar.h:396
remove_all_t< DerivativeType > DerType
Definition: AutoDiffScalar.h:382
NumTraits< Scalar >::Real Real
Definition: AutoDiffScalar.h:384
AutoDiffScalar< DerivativeType > & operator*=(const Scalar &other)
Definition: AutoDiffScalar.h:426
AutoDiffScalar< DerivativeType > & derived()
Definition: AutoDiffScalar.h:399
AutoDiffScalar< typename CwiseUnaryOp< bind2nd_op< scalar_product_op< Scalar, Real > >, DerType >::Type > operator*(const Real &other) const
Definition: AutoDiffScalar.h:414
AutoDiffScalar< DerivativeType > & operator+=(const Real &other)
Definition: AutoDiffScalar.h:409
traits< DerType >::Scalar Scalar
Definition: AutoDiffScalar.h:383
Definition: AutoDiffScalar.h:21
static bool run(const AutoDiffScalar< DerivativeType > &s)
Definition: AutoDiffScalar.h:616
const DerivativeType & type
Definition: AutoDiffScalar.h:41
static const DerivativeType & pad(const DerivativeType &x, const OtherDerivativeType &)
Definition: AutoDiffScalar.h:42
Definition: AutoDiffScalar.h:24
static type pad(const DerivativeType &x, const OtherDerivativeType &y)
Definition: AutoDiffScalar.h:28
static constexpr int SizeAtCompileTime
Definition: AutoDiffScalar.h:25
Template functor to compute the difference of two scalars.
Definition: BinaryFunctors.h:381
Template functor to compute the sum of two scalars.
Definition: BinaryFunctors.h:34
Definition: ForwardDeclarations.h:21