10 #ifndef EIGEN_AUTODIFF_SCALAR_H
11 #define EIGEN_AUTODIFF_SCALAR_H
19 template<
typename A,
typename B>
20 struct make_coherent_impl {
21 static void run(A&, B&) {}
25 template<
typename A,
typename B>
28 make_coherent_impl<A,B>::run(
a.const_cast_derived(),
b.const_cast_derived());
31 template<
typename DerivativeType,
bool Enable>
struct auto_diff_special_op;
35 template<
typename DerivativeType>
class AutoDiffScalar;
37 template<
typename NewDerType>
68 template<
typename DerivativeType>
70 :
public internal::auto_diff_special_op
71 <DerivativeType, !internal::is_same<typename internal::traits<internal::remove_all_t<DerivativeType>>::Scalar,
72 typename NumTraits<typename internal::traits<internal::remove_all_t<DerivativeType>>::Scalar>::Real>::value>
75 typedef internal::auto_diff_special_op
76 <DerivativeType, !internal::is_same<typename internal::traits<internal::remove_all_t<DerivativeType>>
::Scalar,
79 typedef typename internal::traits<DerType>::Scalar
Scalar;
82 using Base::operator+;
83 using Base::operator*;
110 template<
typename OtherDerType>
112 #ifndef EIGEN_PARSED_BY_DOXYGEN
115 && internal::is_convertible<OtherDerType,DerType>::value ,
void*> = 0
123 return s <<
a.value();
130 template<
typename OtherDerType>
209 template<
typename OtherDerType>
219 template<
typename OtherDerType>
223 (*this) = (*this) + other;
236 (
a -
b.value(), -
b.derivatives());
245 template<
typename OtherDerType>
255 template<
typename OtherDerType>
259 *
this = *
this - other;
327 template<
typename OtherDerType>
329 CwiseBinaryOp<internal::scalar_difference_op<Scalar> EIGEN_COMMA
341 template<
typename OtherDerType>
355 *
this = *
this * other;
359 template<
typename OtherDerType>
362 *
this = *
this * other;
368 *
this = *
this / other;
372 template<
typename OtherDerType>
375 *
this = *
this / other;
387 template<
typename DerivativeType>
388 struct auto_diff_special_op<DerivativeType, true>
422 derived().value() += other;
431 derived().value() * other,
432 derived().derivatives() * other);
440 a.derivatives() * other);
445 *
this = *
this * other;
450 template<
typename DerivativeType>
451 struct auto_diff_special_op<DerivativeType, false>
458 template<
typename BinOp,
typename A,
typename B,
typename RefType>
465 template<
typename UnaryOp,
typename A,
typename RefType>
472 template<
typename UnaryOp,
typename A,
typename RefType>
476 template<
typename A_Scalar,
int A_Rows,
int A_Cols,
int A_Options,
int A_MaxRows,
int A_MaxCols,
typename B>
477 struct make_coherent_impl<
Matrix<A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols>,
B> {
479 static void run(A& a, B&
b) {
485 else if (B::SizeAtCompileTime==
Dynamic &&
a.size()!=0 &&
b.size()==0)
492 template<
typename A,
typename B_Scalar,
int B_Rows,
int B_Cols,
int B_Options,
int B_MaxRows,
int B_MaxCols>
493 struct make_coherent_impl<
A, Matrix<B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols> > {
494 typedef Matrix<B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols>
B;
495 static void run(A& a, B&
b) {
501 else if (A::SizeAtCompileTime==
Dynamic &&
b.size()!=0 &&
a.size()==0)
508 template<
typename A_Scalar,
int A_Rows,
int A_Cols,
int A_Options,
int A_MaxRows,
int A_MaxCols,
509 typename B_Scalar,
int B_Rows,
int B_Cols,
int B_Options,
int B_MaxRows,
int B_MaxCols>
510 struct make_coherent_impl<Matrix<A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols>,
511 Matrix<B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols> > {
512 typedef Matrix<A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols>
A;
513 typedef Matrix<B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols>
B;
514 static void run(A& a, B&
b) {
530 template<
typename DerType,
typename BinOp>
536 template<
typename DerType,
typename BinOp>
559 #define EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(FUNC,CODE) \
560 template<typename DerType> \
561 inline Eigen::AutoDiffScalar< \
562 EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Eigen::internal::remove_all_t<DerType>, typename Eigen::internal::traits<Eigen::internal::remove_all_t<DerType>>::Scalar, product) > \
563 FUNC(const Eigen::AutoDiffScalar<DerType>& x) { \
564 using namespace Eigen; \
565 typedef typename Eigen::internal::traits<Eigen::internal::remove_all_t<DerType>>::Scalar Scalar; \
566 EIGEN_UNUSED_VARIABLE(sizeof(Scalar)); \
570 template<
typename DerType>
575 template<
typename DerType>
577 template<
typename DerType>
579 template<
typename DerType>
581 template<
typename DerType,
typename T>
584 return (
x <=
y ? ADS(
x) : ADS(
y));
586 template<
typename DerType,
typename T>
589 return (
x >=
y ? ADS(
x) : ADS(
y));
591 template<
typename DerType,
typename T>
594 return (
x <
y ? ADS(
x) : ADS(
y));
596 template<
typename DerType,
typename T>
599 return (
x >
y ? ADS(
x) : ADS(
y));
601 template<
typename DerType>
605 template<
typename DerType>
621 Scalar sqrtx =
sqrt(
x.value());
636 Scalar expx =
exp(
x.value());
643 template<typename DerType>
648 using namespace Eigen;
654 template<
typename DerTypeA,
typename DerTypeB>
659 typedef typename internal::traits<internal::remove_all_t<DerTypeA>>::Scalar Scalar;
664 Scalar squared_hypot =
a.
value() *
a.
value() +
b.value() *
b.value();
667 ret.derivatives() = (
a.derivatives() *
b.value() -
a.
value() *
b.derivatives()) / squared_hypot;
709 0, DerTypeCleaned::MaxRowsAtCompileTime, DerTypeCleaned::MaxColsAtCompileTime> >
Real;
714 RequireInitialization = 1
719 template<
typename DerivativeType>
723 const DerivativeType& derivatives = s.
derivatives();
724 for(
int i=0;
i<derivatives.size(); ++
i)
739 template <
typename T>
743 template <
typename T>
#define EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(FUNC, CODE)
SparseMatrix< double > A(n, n)
#define EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(EXPR, SCALAR, OPNAME)
A scalar type replacement with automatic differentiation capability.
AutoDiffScalar & operator-=(const Scalar &other)
internal::remove_all_t< DerivativeType > DerType
bool operator>(const Scalar &other) const
AutoDiffScalar< CwiseBinaryOp< internal::scalar_sum_op< Scalar >, const DerType, const internal::remove_all_t< OtherDerType > > > operator+(const AutoDiffScalar< OtherDerType > &other) const
friend AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType, Scalar, product) > operator*(const Scalar &other, const AutoDiffScalar &a)
friend AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType, Scalar, product) > operator/(const Scalar &other, const AutoDiffScalar &a)
internal::traits< DerType >::Scalar Scalar
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(internal::remove_all_t< OtherDerType >, Scalar, product) >, Scalar, product) > operator/(const AutoDiffScalar< OtherDerType > &other) const
AutoDiffScalar< DerType & > operator-(const Scalar &b) const
const Scalar & value() const
AutoDiffScalar & operator=(const AutoDiffScalar &other)
AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType, Scalar, product) > operator*(const Scalar &other) const
NumTraits< Scalar >::Real Real
friend AutoDiffScalar< CwiseUnaryOp< internal::scalar_opposite_op< Scalar >, const DerType > > operator-(const Scalar &a, const AutoDiffScalar &b)
AutoDiffScalar & operator*=(const AutoDiffScalar< OtherDerType > &other)
bool operator==(const AutoDiffScalar< OtherDerType > &b) const
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
AutoDiffScalar< CwiseBinaryOp< internal::scalar_sum_op< Scalar >, const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType, Scalar, product), const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(internal::remove_all_t< OtherDerType >, Scalar, product) > > operator*(const AutoDiffScalar< OtherDerType > &other) const
friend AutoDiffScalar< DerType & > operator+(const Scalar &a, const AutoDiffScalar &b)
bool operator!=(const AutoDiffScalar< OtherDerType > &b) const
bool operator<(const Scalar &other) const
AutoDiffScalar & operator/=(const AutoDiffScalar< OtherDerType > &other)
AutoDiffScalar(const AutoDiffScalar &other)
AutoDiffScalar & operator*=(const Scalar &other)
AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType, Scalar, product) > operator/(const Scalar &other) const
AutoDiffScalar & operator+=(const AutoDiffScalar< OtherDerType > &other)
bool operator<=(const Scalar &other) const
friend std::ostream & operator<<(std::ostream &s, const AutoDiffScalar &a)
AutoDiffScalar< CwiseBinaryOp< internal::scalar_difference_op< Scalar >, const DerType, const internal::remove_all_t< OtherDerType > > > operator-(const AutoDiffScalar< OtherDerType > &other) const
bool operator<=(const AutoDiffScalar< OtherDerType > &b) const
AutoDiffScalar(const AutoDiffScalar< OtherDerType > &other)
bool operator>=(const Scalar &other) const
AutoDiffScalar(const Scalar &value, int nbDer, int derNumber)
friend bool operator==(const Scalar &a, const AutoDiffScalar &b)
AutoDiffScalar & operator=(const Scalar &other)
bool operator==(const Scalar &other) const
AutoDiffScalar< DerType & > operator+(const Scalar &other) const
friend bool operator!=(const Scalar &a, const AutoDiffScalar &b)
bool operator!=(const Scalar &other) const
AutoDiffScalar & operator-=(const AutoDiffScalar< OtherDerType > &other)
friend bool operator<=(const Scalar &a, const AutoDiffScalar &b)
AutoDiffScalar(const Real &value)
const DerType & derivatives() const
AutoDiffScalar(const Scalar &value, const DerType &der)
AutoDiffScalar & operator/=(const Scalar &other)
AutoDiffScalar & operator=(const AutoDiffScalar< OtherDerType > &other)
AutoDiffScalar & operator+=(const Scalar &other)
friend bool operator>=(const Scalar &a, const AutoDiffScalar &b)
AutoDiffScalar< CwiseUnaryOp< internal::scalar_opposite_op< Scalar >, const DerType > > operator-() const
bool operator>=(const AutoDiffScalar< OtherDerType > &b) const
const LhsNested_ & lhs() const
const RhsNested_ & rhs() const
internal::remove_all_t< XprTypeNested > & nestedExpression()
CoeffReturnType value() const
bfloat16 & operator*=(bfloat16 &a, const bfloat16 &b)
bfloat16 & operator+=(bfloat16 &a, const bfloat16 &b)
EIGEN_ALWAYS_INLINE TensorUInt128< uint64_t, uint64_t > operator-(const TensorUInt128< HL, LL > &lhs, const TensorUInt128< HR, LR > &rhs)
void make_coherent_expression(CwiseBinaryOp< BinOp, A, B > xpr, const RefType &ref)
EIGEN_ALWAYS_INLINE TensorUInt128< uint64_t, uint64_t > operator+(const TensorUInt128< HL, LL > &lhs, const TensorUInt128< HR, LR > &rhs)
static TensorUInt128< uint64_t, uint64_t > operator*(const TensorUInt128< HL, LL > &lhs, const TensorUInt128< HR, LR > &rhs)
typename remove_all< T >::type remove_all_t
void make_coherent(const A &a, const B &b)
bool is_exactly_zero(const X &x)
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_tanh_op< typename Derived::Scalar >, const Derived > tanh(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_imag_op< typename Derived::Scalar >, const Derived > imag(const Eigen::ArrayBase< Derived > &x)
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) > sinh(const Eigen::AutoDiffScalar< DerType > &x)
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) > log(const Eigen::AutoDiffScalar< DerType > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_cosh_op< typename Derived::Scalar >, const Derived > cosh(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_tan_op< typename Derived::Scalar >, const Derived > tan(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_acos_op< typename Derived::Scalar >, const Derived > acos(const Eigen::ArrayBase< Derived > &x)
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) > cos(const Eigen::AutoDiffScalar< DerType > &x)
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) > tan(const Eigen::AutoDiffScalar< DerType > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs2_op< typename Derived::Scalar >, const Derived > abs2(const Eigen::ArrayBase< Derived > &x)
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)
CleanedUpDerType< DerType >::type() min(const AutoDiffScalar< DerType > &x, const T &y)
CleanedUpDerType< DerType >::type() max(const AutoDiffScalar< DerType > &x, const T &y)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_asin_op< typename Derived::Scalar >, const Derived > asin(const Eigen::ArrayBase< Derived > &x)
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) > acos(const Eigen::AutoDiffScalar< DerType > &x)
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) > exp(const Eigen::AutoDiffScalar< DerType > &x)
Eigen::AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(internal::remove_all_t< DerType >, typename internal::traits< internal::remove_all_t< DerType >>::Scalar, product) > pow(const Eigen::AutoDiffScalar< DerType > &x, const typename internal::traits< internal::remove_all_t< DerType >>::Scalar &y)
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) > asin(const Eigen::AutoDiffScalar< DerType > &x)
AutoDiffScalar< Matrix< typename internal::traits< internal::remove_all_t< DerTypeA > >::Scalar, Dynamic, 1 > > atan2(const AutoDiffScalar< DerTypeA > &a, const AutoDiffScalar< DerTypeB > &b)
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) > abs(const Eigen::AutoDiffScalar< DerType > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_conjugate_op< typename Derived::Scalar >, const Derived > conj(const Eigen::ArrayBase< Derived > &x)
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) > sin(const Eigen::AutoDiffScalar< DerType > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_real_op< typename Derived::Scalar >, const Derived > real(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_cos_op< typename Derived::Scalar >, const Derived > cos(const Eigen::ArrayBase< Derived > &x)
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) > tanh(const Eigen::AutoDiffScalar< DerType > &x)
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_exp_op< typename Derived::Scalar >, const Derived > exp(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sin_op< typename Derived::Scalar >, const Derived > sin(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_log_op< typename Derived::Scalar >, const Derived > log(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sinh_op< typename Derived::Scalar >, const Derived > sinh(const Eigen::ArrayBase< Derived > &x)
AutoDiffScalar< NewDerType > MakeAutoDiffScalar(const typename NewDerType::Scalar &value, const NewDerType &der)
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) > cosh(const Eigen::AutoDiffScalar< DerType > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)
AutoDiffScalar< typename Eigen::internal::remove_all_t< DerType >::PlainObject > type
AutoDiffScalar< DerType > NonInteger
NumTraits< typename DerTypeCleaned::Scalar >::Literal Literal
internal::remove_all_t< DerType > DerTypeCleaned
AutoDiffScalar< DerType > Nested
AutoDiffScalar< Matrix< typename NumTraits< typename DerTypeCleaned::Scalar >::Real, DerTypeCleaned::RowsAtCompileTime, DerTypeCleaned::ColsAtCompileTime, 0, DerTypeCleaned::MaxRowsAtCompileTime, DerTypeCleaned::MaxColsAtCompileTime > > Real
AutoDiffScalar< DerType > ReturnType
AutoDiffScalar< DerType > ReturnType