aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/Eigen/src/AutoDiff
diff options
context:
space:
mode:
authorGravatar Philip Avery <philip.avery@gmail.com>2012-05-02 17:17:12 +0200
committerGravatar Philip Avery <philip.avery@gmail.com>2012-05-02 17:17:12 +0200
commitcb3b1bb73e7810033e09e8da6b39581b6083b455 (patch)
tree9c3f920fd2624dab47cda82db3259c2eca341398 /unsupported/Eigen/src/AutoDiff
parent8f47246475c8d3bf64fbdcbe1de55b93af1d6edd (diff)
AutoDiffScalar: fix bug with operator/, add missing functions
Diffstat (limited to 'unsupported/Eigen/src/AutoDiff')
-rw-r--r--unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h33
1 files changed, 31 insertions, 2 deletions
diff --git a/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h b/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h
index ee1f16b7e..d6c2a29de 100644
--- a/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h
+++ b/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h
@@ -101,7 +101,7 @@ class AutoDiffScalar
/** Conversion from a scalar constant to an active scalar.
* The derivatives are set to zero. */
- explicit AutoDiffScalar(const Real& value)
+ /*explicit*/ AutoDiffScalar(const Real& value)
: m_value(value)
{
if(m_derivatives.size()>0)
@@ -228,6 +228,12 @@ class AutoDiffScalar
(a - b.value(), -b.derivatives());
}
+ inline AutoDiffScalar& operator-=(const Scalar& other)
+ {
+ value() -= other;
+ return *this;
+ }
+
template<typename OtherDerType>
inline const AutoDiffScalar<CwiseBinaryOp<internal::scalar_difference_op<Scalar>, const DerType,const typename internal::remove_all<OtherDerType>::type> >
operator-(const AutoDiffScalar<OtherDerType>& other) const
@@ -299,7 +305,7 @@ class AutoDiffScalar
{
return AutoDiffScalar<CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, const DerType> >(
other / a.value(),
- a.derivatives() * (-Scalar(1)/other));
+ a.derivatives() * (Scalar(-other) / (a.value()*a.value())));
}
// inline const AutoDiffScalar<typename CwiseUnaryOp<internal::scalar_multiple_op<Real>, DerType>::Type >
@@ -362,6 +368,19 @@ class AutoDiffScalar
return *this;
}
+ inline AutoDiffScalar& operator/=(const Scalar& other)
+ {
+ *this = *this / other;
+ return *this;
+ }
+
+ template<typename OtherDerType>
+ inline AutoDiffScalar& operator/=(const AutoDiffScalar<OtherDerType>& other)
+ {
+ *this = *this / other;
+ return *this;
+ }
+
protected:
Scalar m_value;
DerType m_derivatives;
@@ -519,6 +538,16 @@ template<typename DerType>
inline const AutoDiffScalar<DerType>& real(const AutoDiffScalar<DerType>& x) { return x; }
template<typename DerType>
inline typename DerType::Scalar imag(const AutoDiffScalar<DerType>&) { return 0.; }
+template<typename DerType, typename T>
+inline AutoDiffScalar<DerType> min(const AutoDiffScalar<DerType>& x, const T& y) { return (x <= y ? x : y); }
+template<typename DerType, typename T>
+inline AutoDiffScalar<DerType> max(const AutoDiffScalar<DerType>& x, const T& y) { return (x >= y ? x : y); }
+template<typename DerType, typename T>
+inline AutoDiffScalar<DerType> min(const T& x, const AutoDiffScalar<DerType>& y) { return (x < y ? x : y); }
+template<typename DerType, typename T>
+inline AutoDiffScalar<DerType> max(const T& x, const AutoDiffScalar<DerType>& y) { return (x > y ? x : y); }
+
+#define sign(x) x >= 0 ? 1 : -1 // required for abs function below
EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(abs,
using std::abs;