13 #ifndef EIGEN_AUTODIFF_SCALAR_H_
14 #define EIGEN_AUTODIFF_SCALAR_H_
23 #include <Eigen/SparseCore>
29 template <
typename A,
typename B>
36 template <
typename A,
typename B>
42 template <
typename _DerType,
bool Enable>
47 template <
typename _DerType>
50 template <
typename NewDerType>
80 template <
typename _DerType>
82 :
public internal::auto_diff_special_op<_DerType, !internal::is_same<typename internal::traits<typename internal::remove_all<_DerType>::type>::Scalar,
83 typename NumTraits<typename internal::traits<typename internal::remove_all<_DerType>::type>::Scalar>::Real>::value>
86 typedef internal::auto_diff_special_op<_DerType, !internal::is_same<typename internal::traits<typename internal::remove_all<_DerType>::type>
::Scalar,
87 typename NumTraits<typename internal::traits<typename internal::remove_all<_DerType>::type>
::Scalar>
::Real>
::value>
89 typedef typename internal::remove_all<_DerType>::type
DerType;
90 typedef typename internal::traits<DerType>::Scalar
Scalar;
91 typedef typename NumTraits<Scalar>::Real
Real;
93 using Base::operator+;
94 using Base::operator*;
121 template <
typename OtherDerType>
123 #ifndef EIGEN_PARSED_BY_DOXYGEN
125 typename internal::enable_if<
126 internal::is_same<
Scalar,
typename internal::traits<
typename internal::remove_all<OtherDerType>::type>::
Scalar>::
value && internal::is_convertible<OtherDerType, DerType>::value,
void*>::type = 0
135 return s << a.value();
143 template <
typename OtherDerType>
185 template <
typename OtherDerType>
190 template <
typename OtherDerType>
195 template <
typename OtherDerType>
200 template <
typename OtherDerType>
205 template <
typename OtherDerType>
210 template <
typename OtherDerType>
242 template <
typename OtherDerType>
252 template <
typename OtherDerType>
256 (*this) = (*this) + other;
277 template <
typename OtherDerType>
287 template <
typename OtherDerType>
291 this = *
this - other;
359 template <
typename OtherDerType>
360 inline const AutoDiffScalar<EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(
361 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)>
370 template <
typename OtherDerType>
372 const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(
DerType,
Scalar, product),
373 const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(
typename internal::remove_all<OtherDerType>::type,
Scalar, product)>>
384 this = *
this * other;
388 template <
typename OtherDerType>
391 this = *
this * other;
397 this = *
this / other;
401 template <
typename OtherDerType>
404 this = *
this / other;
415 template <
typename _DerType>
420 typedef typename remove_all<_DerType>::type
DerType;
421 typedef typename traits<DerType>::Scalar
Scalar;
422 typedef typename NumTraits<Scalar>::Real
Real;
448 derived().value() += other;
456 derived().value() * other,
457 derived().derivatives() * other);
465 a.derivatives() * other);
470 this = *
this * other;
475 template <
typename _DerType>
483 template <
typename A_Scalar,
int A_Rows,
int A_Cols,
int A_Options,
int A_MaxRows,
int A_MaxCols,
typename B>
486 typedef Matrix<A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols>
A;
489 if ((A_Rows == Dynamic || A_Cols == Dynamic) && (a.size() == 0))
494 eigen_assert(a.size() == b.size() &&
"Eigen::AutoDiffScalar: derivatives are not compatible.");
498 template <
typename A,
typename B_Scalar,
int B_Rows,
int B_Cols,
int B_Options,
int B_MaxRows,
int B_MaxCols>
501 typedef Matrix<B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols>
B;
504 if ((B_Rows == Dynamic || B_Cols == Dynamic) && (b.size() == 0))
509 eigen_assert(a.size() == b.size() &&
"Eigen::AutoDiffScalar: derivatives are not compatible.");
513 template <
typename A_Scalar,
int A_Rows,
int A_Cols,
int A_Options,
int A_MaxRows,
int A_MaxCols,
514 typename B_Scalar,
int B_Rows,
int B_Cols,
int B_Options,
int B_MaxRows,
int B_MaxCols>
516 Matrix<B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols>>
518 typedef Matrix<A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols>
A;
519 typedef Matrix<B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols>
B;
522 if ((A_Rows == Dynamic || A_Cols == Dynamic) && (a.size() == 0))
527 else if ((B_Rows == Dynamic || B_Cols == Dynamic) && (b.size() == 0))
532 eigen_assert(a.size() == b.size() &&
"Eigen::AutoDiffScalar: derivatives are not compatible.");
536 template <
typename A_Scalar,
int A_Options,
typename A_Index,
typename B>
539 typedef SparseVector<A_Scalar, A_Options, A_Index>
A;
546 eigen_assert(a.size() == b.size() &&
"Eigen::AutoDiffScalar: derivatives are not compatible.");
550 template <
typename A,
typename B_Scalar,
int B_Options,
typename B_Index>
553 typedef SparseVector<B_Scalar, B_Options, B_Index>
B;
560 eigen_assert(a.size() == b.size() &&
"Eigen::AutoDiffScalar: derivatives are not compatible.");
564 template <
typename A_Scalar,
int A_Options,
typename A_Index,
565 typename B_Scalar,
int B_Options,
typename B_Index>
567 SparseVector<B_Scalar, B_Options, B_Index>>
569 typedef SparseVector<A_Scalar, A_Options, A_Index>
A;
570 typedef SparseVector<B_Scalar, B_Options, B_Index>
B;
577 else if (b.size() == 0)
581 eigen_assert(a.size() == b.size() &&
"Eigen::AutoDiffScalar: derivatives are not compatible.");
587 template <
typename DerType,
typename BinOp>
588 struct ScalarBinaryOpTraits<
AutoDiffScalar<DerType>, typename DerType::Scalar, BinOp>
593 template <
typename DerType,
typename BinOp>
594 struct ScalarBinaryOpTraits<typename DerType::Scalar,
AutoDiffScalar<DerType>, BinOp>
615 #define EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(FUNC, CODE) \
616 template <typename DerType> \
617 inline const Eigen::AutoDiffScalar< \
618 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)> \
619 FUNC(const Eigen::AutoDiffScalar<DerType>& x) \
621 using namespace Eigen; \
622 typedef typename Eigen::internal::traits<typename Eigen::internal::remove_all<DerType>::type>::Scalar Scalar; \
623 EIGEN_UNUSED_VARIABLE(sizeof(Scalar)); \
627 template <
typename DerType>
632 template <
typename DerType>
637 template <
typename DerType>
642 template <
typename DerType,
typename T>
643 inline AutoDiffScalar<typename Eigen::internal::remove_all<DerType>::type::PlainObject>(
min)(
const AutoDiffScalar<DerType>& x,
const T&
y)
646 return (
x <=
y ? ADS(
x) : ADS(
y));
648 template <
typename DerType,
typename T>
649 inline AutoDiffScalar<typename Eigen::internal::remove_all<DerType>::type::PlainObject>(max)(
const AutoDiffScalar<DerType>& x,
const T&
y)
651 typedef AutoDiffScalar<typename Eigen::internal::remove_all<DerType>::type::PlainObject> ADS;
652 return (x >=
y ? ADS(x) : ADS(
y));
654 template <
typename DerType,
typename T>
655 inline AutoDiffScalar<typename Eigen::internal::remove_all<DerType>::type::PlainObject>(
min)(
const T& x,
const AutoDiffScalar<DerType>&
y)
657 typedef AutoDiffScalar<typename Eigen::internal::remove_all<DerType>::type::PlainObject> ADS;
658 return (x <
y ? ADS(x) : ADS(
y));
660 template <
typename DerType,
typename T>
661 inline AutoDiffScalar<typename Eigen::internal::remove_all<DerType>::type::PlainObject>(max)(
const T& x,
const AutoDiffScalar<DerType>&
y)
663 typedef AutoDiffScalar<typename Eigen::internal::remove_all<DerType>::type::PlainObject> ADS;
664 return (x >
y ? ADS(x) : ADS(
y));
666 template <
typename DerType>
667 inline AutoDiffScalar<typename Eigen::internal::remove_all<DerType>::type::PlainObject>(
min)(
const AutoDiffScalar<DerType>& x,
const AutoDiffScalar<DerType>&
y)
669 return (
x.value() <
y.value() ?
x :
y);
671 template <
typename DerType>
672 inline AutoDiffScalar<typename Eigen::internal::remove_all<DerType>::type::PlainObject>(max)(
const AutoDiffScalar<DerType>& x,
const AutoDiffScalar<DerType>&
y)
674 return (
x.value() >=
y.value() ?
x :
y);
687 Scalar sqrtx = sqrt(
x.value());
709 template <typename DerType>
711 EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(
typename internal::remove_all<DerType>::type,
typename internal::traits<
typename internal::remove_all<DerType>::type>::Scalar, product)>
714 using namespace Eigen;
719 template <
typename DerTypeA,
typename DerTypeB>
724 typedef typename internal::traits<typename internal::remove_all<DerTypeA>::type>::Scalar Scalar;
729 Scalar squared_hypot = a.value() * a.value() + b.value() * b.value();
732 ret.derivatives() = (a.derivatives() * b.value() - a.value() * b.derivatives()) / squared_hypot;
737 template <
typename DerTypeA,
typename DerTypeB>
742 typedef typename internal::traits<typename internal::remove_all<DerTypeA>::type>::Scalar Scalar;
747 Scalar squared_hypot = a.value() * a.value() + b.value() * b.value();
750 ret.derivatives() = (a.derivatives() * b.value() - a.value() * b.derivatives()) / squared_hypot;
787 template <typename DerType>
789 : NumTraits<
typename NumTraits<
typename internal::remove_all<DerType>::type::Scalar>::
Real>
793 0, DerTypeCleaned::MaxRowsAtCompileTime, DerTypeCleaned::MaxColsAtCompileTime>>
797 typedef typename NumTraits<typename DerTypeCleaned::Scalar>::Literal
Literal;
800 RequireInitialization = 1
804 template <
typename DerType_>
806 : NumTraits<typename NumTraits<typename internal::remove_all<SparseVector<DerType_>>::type::Scalar>::Real>
808 typedef typename internal::remove_all<SparseVector<DerType_>>::type
DerTypeCleaned;
812 typedef typename NumTraits<typename DerTypeCleaned::Scalar>::Literal
Literal;
815 RequireInitialization = 1
822 template <
typename T>
824 :
public numeric_limits<typename T::Scalar>
828 template <
typename T>
830 :
public numeric_limits<typename T::Scalar>
835 #endif // EIGEN_AUTODIFF_SCALAR_H_