10 #ifndef EIGEN_AUTODIFF_SCALAR_H 11 #define EIGEN_AUTODIFF_SCALAR_H 17 template<
typename A,
typename B>
23 template<
typename A,
typename B>
35 template<
typename NewDerType>
66 template<
typename _DerType>
69 <_DerType, !internal::is_same<typename internal::traits<typename internal::remove_all<_DerType>::type>::Scalar,
70 typename NumTraits<typename internal::traits<typename internal::remove_all<_DerType>::type>::Scalar>::Real>::value>
80 using Base::operator+;
81 using Base::operator*;
89 : m_value(value), m_derivatives(DerType::Zero(nbDer))
91 m_derivatives.coeffRef(derNumber) = Scalar(1);
99 if(m_derivatives.size()>0)
100 m_derivatives.setZero();
105 : m_value(value), m_derivatives(der)
108 template<
typename OtherDerType>
110 #ifndef EIGEN_PARSED_BY_DOXYGEN
116 : m_value(other.value()), m_derivatives(other.derivatives())
121 return s << a.
value();
125 : m_value(other.value()), m_derivatives(other.derivatives())
128 template<
typename OtherDerType>
131 m_value = other.
value();
138 m_value = other.
value();
146 if(m_derivatives.size()>0)
147 m_derivatives.setZero();
154 inline const Scalar&
value()
const {
return m_value; }
155 inline Scalar&
value() {
return m_value; }
157 inline const DerType&
derivatives()
const {
return m_derivatives; }
160 inline bool operator< (
const Scalar& other)
const {
return m_value < other; }
161 inline bool operator<=(
const Scalar& other)
const {
return m_value <= other; }
162 inline bool operator> (
const Scalar& other)
const {
return m_value > other; }
163 inline bool operator>=(
const Scalar& other)
const {
return m_value >= other; }
164 inline bool operator==(
const Scalar& other)
const {
return m_value == other; }
165 inline bool operator!=(
const Scalar& other)
const {
return m_value != other; }
174 template<
typename OtherDerType>
inline bool operator< (const AutoDiffScalar<OtherDerType>&
b)
const {
return m_value <
b.value(); }
175 template<
typename OtherDerType>
inline bool operator<=(const AutoDiffScalar<OtherDerType>&
b)
const {
return m_value <=
b.value(); }
207 template<
typename OtherDerType>
213 m_value + other.
value(),
217 template<
typename OtherDerType>
221 (*this) = (*this) + other;
233 return AutoDiffScalar<CwiseUnaryOp<internal::scalar_opposite_op<Scalar>,
const DerType> >
243 template<
typename OtherDerType>
249 m_value - other.
value(),
253 template<
typename OtherDerType>
257 *
this = *
this - other;
261 inline const AutoDiffScalar<CwiseUnaryOp<internal::scalar_opposite_op<Scalar>,
const DerType> >
264 return AutoDiffScalar<CwiseUnaryOp<internal::scalar_opposite_op<Scalar>,
const DerType> >(
325 template<
typename OtherDerType>
334 m_value / other.
value(),
339 template<
typename OtherDerType>
347 m_value * other.
value(),
353 *
this = *
this * other;
357 template<
typename OtherDerType>
360 *
this = *
this * other;
366 *
this = *
this / other;
370 template<
typename OtherDerType>
373 *
this = *
this / other;
385 template<
typename _DerType>
420 derived().value() += other;
429 derived().value() * other,
430 derived().derivatives() * other);
436 return AutoDiffScalar<typename CwiseUnaryOp<bind1st_op<scalar_product_op<Real,Scalar> >, DerType>
::Type >(
443 *
this = *
this * other;
448 template<
typename _DerType>
456 template<
typename A_Scalar,
int A_Rows,
int A_Cols,
int A_Options,
int A_MaxRows,
int A_MaxCols,
typename B>
468 template<
typename A,
typename B_Scalar,
int B_Rows,
int B_Cols,
int B_Options,
int B_MaxRows,
int B_MaxCols>
480 template<
typename A_Scalar,
int A_Rows,
int A_Cols,
int A_Options,
int A_MaxRows,
int A_MaxCols,
481 typename B_Scalar,
int B_Rows,
int B_Cols,
int B_Options,
int B_MaxRows,
int B_MaxCols>
483 Matrix<B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols> > {
502 template<
typename DerType,
typename BinOp>
508 template<
typename DerType,
typename BinOp>
531 #define EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(FUNC,CODE) \ 532 template<typename DerType> \ 533 inline const Eigen::AutoDiffScalar< \ 534 EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(typename Eigen::internal::remove_all<DerType>::type, typename Eigen::internal::traits<typename Eigen::internal::remove_all<DerType>::type>::Scalar, product) > \ 535 FUNC(const Eigen::AutoDiffScalar<DerType>& x) { \ 536 using namespace Eigen; \ 537 EIGEN_UNUSED typedef typename Eigen::internal::traits<typename Eigen::internal::remove_all<DerType>::type>::Scalar Scalar; \ 541 template<
typename DerType>
543 template<
typename DerType>
545 template<
typename DerType>
547 template<
typename DerType,
typename T>
550 return (x <= y ? ADS(x) : ADS(y));
552 template<
typename DerType,
typename T>
555 return (x >= y ? ADS(x) : ADS(y));
557 template<
typename DerType,
typename T>
560 return (x < y ? ADS(x) : ADS(y));
562 template<
typename DerType,
typename T>
565 return (x > y ? ADS(x) : ADS(y));
567 template<
typename DerType>
571 template<
typename DerType>
609 template<typename DerType>
614 using namespace Eigen;
620 template<
typename DerTypeA,
typename DerTypeB>
675 0, DerTypeCleaned::MaxRowsAtCompileTime, DerTypeCleaned::MaxColsAtCompileTime> >
Real;
680 RequireInitialization = 1
687 template <
typename T>
689 :
public numeric_limits<typename T::Scalar> {};
693 #endif // EIGEN_AUTODIFF_SCALAR_H bool operator==(const Scalar &other) const
static void run(A &a, B &b)
AutoDiffScalar(const Scalar &value, int nbDer, int derNumber)
friend const AutoDiffScalar< CwiseUnaryOp< internal::scalar_opposite_op< Scalar >, const DerType > > operator-(const Scalar &a, const AutoDiffScalar &b)
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half pow(const half &a, const half &b)
AutoDiffScalar & operator*=(const AutoDiffScalar< OtherDerType > &other)
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
const AutoDiffScalar< DerType > & conj(const AutoDiffScalar< DerType > &x)
internal::remove_all< _DerType >::type DerType
internal::auto_diff_special_op< _DerType,!internal::is_same< typename internal::traits< typename internal::remove_all< _DerType >::type >::Scalar, typename NumTraits< typename internal::traits< typename internal::remove_all< _DerType >::type >::Scalar >::Real >::value > Base
AutoDiffScalar< DerType > ReturnType
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE TensorUInt128< uint64_t, uint64_t > operator-(const TensorUInt128< HL, LL > &lhs, const TensorUInt128< HR, LR > &rhs)
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
const AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType, Scalar, product) > operator*(const Scalar &other) const
friend const AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType, Scalar, product) > operator*(const Scalar &other, const AutoDiffScalar &a)
Matrix< A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols > A
A scalar type replacement with automatic differentation capability.
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
std::ostream & operator<<(std::ostream &s, const Packet16uc &v)
AutoDiffScalar & operator+=(const AutoDiffScalar< OtherDerType > &other)
void make_coherent(const A &a, const B &b)
EIGEN_DEVICE_FUNC const TanhReturnType tanh() const
EIGEN_DEVICE_FUNC const LogReturnType log() const
Eigen::internal::make_coherent_impl< Matrix< A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols >, Matrix< B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols > >::run static void run(A &a, B &b)
AutoDiffScalar(const AutoDiffScalar< OtherDerType > &other, typename internal::enable_if< internal::is_same< Scalar, typename internal::traits< typename internal::remove_all< OtherDerType >::type >::Scalar >::value &&internal::is_convertible< OtherDerType, DerType >::value, void * >::type=0)
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
EIGEN_DEVICE_FUNC const CoshReturnType cosh() const
DerType::Scalar imag(const AutoDiffScalar< DerType > &)
const AutoDiffScalar< typename CwiseUnaryOp< bind2nd_op< scalar_product_op< Scalar, Real > >, DerType >::Type > operator*(const Real &other) const
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const AbsReturnType abs() const
AutoDiffScalar< _DerType > & operator+=(const Real &other)
const AutoDiffScalar< DerType & > operator+(const Real &other) const
const AutoDiffScalar< CwiseBinaryOp< internal::scalar_difference_op< Scalar >, const DerType, const typename internal::remove_all< OtherDerType >::type > > operator-(const AutoDiffScalar< OtherDerType > &other) const
AutoDiffScalar & operator-=(const AutoDiffScalar< OtherDerType > &other)
friend bool operator!=(const Scalar &a, const AutoDiffScalar &b)
const AutoDiffScalar< DerType & > operator+(const Scalar &other) const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool operator<(const TensorUInt128< HL, LL > &lhs, const TensorUInt128< HR, LR > &rhs)
const AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(CwiseBinaryOp< internal::scalar_difference_op< Scalar > EIGEN_COMMA const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType, Scalar, product) EIGEN_COMMA const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(typename internal::remove_all< OtherDerType >::type, Scalar, product) >, Scalar, product) > operator/(const AutoDiffScalar< OtherDerType > &other) const
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half() max(const half &a, const half &b)
EIGEN_DEVICE_FUNC const CosReturnType cos() const
traits< DerType >::Scalar Scalar
friend const AutoDiffScalar< DerType & > operator+(const Real &a, const AutoDiffScalar< _DerType > &b)
Generic expression where a coefficient-wise binary operator is applied to two expressions.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
AutoDiffScalar & operator/=(const Scalar &other)
NumTraits< Scalar >::Real Real
AutoDiffScalar & operator=(const AutoDiffScalar &other)
const AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType, Scalar, product) > operator/(const Scalar &other) const
EIGEN_DEVICE_FUNC const SinhReturnType sinh() const
Eigen::internal::make_coherent_impl< Matrix< A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols >, Matrix< B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols > >::A Matrix< A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols > A
Eigen::internal::make_coherent_impl< Matrix< A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols >, Matrix< B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols > >::B Matrix< B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols > B
AutoDiffScalar< DerType > ReturnType
const AutoDiffScalar< DerType & > operator-(const Scalar &b) const
static void run(A &, B &)
remove_all< _DerType >::type DerType
bool operator<=(const Scalar &other) const
internal::traits< DerType >::Scalar Scalar
AutoDiffScalar(const Real &value)
AutoDiffScalar< _DerType > & operator*=(const Scalar &other)
bool operator!=(const AutoDiffScalar< OtherDerType > &b) const
EIGEN_DEVICE_FUNC const TanReturnType tan() const
friend bool operator<=(const Scalar &a, const AutoDiffScalar &b)
AutoDiffScalar< NewDerType > MakeAutoDiffScalar(const typename NewDerType::Scalar &value, const NewDerType &der)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorUInt128< uint64_t, uint64_t > operator*(const TensorUInt128< HL, LL > &lhs, const TensorUInt128< HR, LR > &rhs)
NumTraits< Scalar >::Real Real
AutoDiffScalar & operator=(const Scalar &other)
AutoDiffScalar< Matrix< typename NumTraits< typename DerTypeCleaned::Scalar >::Real, DerTypeCleaned::RowsAtCompileTime, DerTypeCleaned::ColsAtCompileTime, 0, DerTypeCleaned::MaxRowsAtCompileTime, DerTypeCleaned::MaxColsAtCompileTime > > Real
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Abs2ReturnType abs2() const
const AutoDiffScalar< _DerType > & derived() const
friend const AutoDiffScalar< DerType & > operator+(const Scalar &a, const AutoDiffScalar &b)
const AutoDiffScalar< CwiseUnaryOp< internal::scalar_opposite_op< Scalar >, const DerType > > operator-() const
EIGEN_DEVICE_FUNC const AcosReturnType acos() const
bool operator>=(const Scalar &other) const
friend const AutoDiffScalar< typename CwiseUnaryOp< bind1st_op< scalar_product_op< Real, Scalar > >, DerType >::Type > operator*(const Real &other, const AutoDiffScalar< _DerType > &a)
AutoDiffScalar & operator=(const AutoDiffScalar< OtherDerType > &other)
friend bool operator==(const Scalar &a, const AutoDiffScalar &b)
const DerType & derivatives() const
const AutoDiffScalar< CwiseBinaryOp< internal::scalar_sum_op< Scalar >, const DerType, const typename internal::remove_all< OtherDerType >::type > > operator+(const AutoDiffScalar< OtherDerType > &other) const
bool operator>=(const AutoDiffScalar< OtherDerType > &b) const
AutoDiffScalar< DerType > Nested
const AutoDiffScalar< Matrix< typename internal::traits< typename internal::remove_all< DerTypeA >::type >::Scalar, Dynamic, 1 > > atan2(const AutoDiffScalar< DerTypeA > &a, const AutoDiffScalar< DerTypeB > &b)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE TensorUInt128< uint64_t, uint64_t > operator+(const TensorUInt128< HL, LL > &lhs, const TensorUInt128< HR, LR > &rhs)
AutoDiffScalar & operator-=(const Scalar &other)
const Scalar & value() const
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
internal::remove_all< DerType >::type DerTypeCleaned
NumTraits< typename DerTypeCleaned::Scalar >::Literal Literal
bool operator==(const AutoDiffScalar< OtherDerType > &b) const
EIGEN_DEVICE_FUNC const SinReturnType sin() const
Matrix< B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols > B
AutoDiffScalar(const Scalar &value, const DerType &der)
static void run(A &a, B &b)
const AutoDiffScalar< CwiseBinaryOp< internal::scalar_sum_op< Scalar >, const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType, Scalar, product), const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(typename internal::remove_all< OtherDerType >::type, Scalar, product) > > operator*(const AutoDiffScalar< OtherDerType > &other) const
AutoDiffScalar & operator+=(const Scalar &other)
const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived, typename Derived::Scalar, pow) pow(const Eigen
AutoDiffScalar< _DerType > & derived()
The matrix class, also used for vectors and row-vectors.
AutoDiffScalar(const AutoDiffScalar &other)
bool operator!=(const Scalar &other) const
const AutoDiffScalar< DerType > & real(const AutoDiffScalar< DerType > &x)
AutoDiffScalar & operator/=(const AutoDiffScalar< OtherDerType > &other)
friend const AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType, Scalar, product) > operator/(const Scalar &other, const AutoDiffScalar &a)
EIGEN_DEVICE_FUNC const Scalar & b
friend bool operator>=(const Scalar &a, const AutoDiffScalar &b)
AutoDiffScalar & operator*=(const Scalar &other)
EIGEN_DEVICE_FUNC const AsinReturnType asin() const
AutoDiffScalar< DerType > NonInteger