1c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// This file is part of Eigen, a lightweight C++ template library
2c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// for linear algebra.
3c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//
4c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
5c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//
6c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// This Source Code Form is subject to the terms of the Mozilla
7c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// Public License v. 2.0. If a copy of the MPL was not distributed
8c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
10c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath#ifndef EIGEN_AUTODIFF_VECTOR_H
11c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath#define EIGEN_AUTODIFF_VECTOR_H
12c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
13c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathnamespace Eigen {
14c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
15c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath/* \class AutoDiffScalar
16c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \brief A scalar type replacement with automatic differentation capability
17c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
18c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \param DerType the vector type used to store/represent the derivatives (e.g. Vector3f)
19c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
20c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * This class represents a scalar value while tracking its respective derivatives.
21c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
22c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * It supports the following list of global math function:
23c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *  - std::abs, std::sqrt, std::pow, std::exp, std::log, std::sin, std::cos,
24c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *  - internal::abs, internal::sqrt, internal::pow, internal::exp, internal::log, internal::sin, internal::cos,
25c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *  - internal::conj, internal::real, internal::imag, internal::abs2.
26c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
27c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * AutoDiffScalar can be used as the scalar type of an Eigen::Matrix object. However,
28c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * in that case, the expression template mechanism only occurs at the top Matrix level,
29c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * while derivatives are computed right away.
30c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
31c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  */
32c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename ValueType, typename JacobianType>
33c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathclass AutoDiffVector
34c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
35c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  public:
36c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    //typedef typename internal::traits<ValueType>::Scalar Scalar;
37c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    typedef typename internal::traits<ValueType>::Scalar BaseScalar;
38c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    typedef AutoDiffScalar<Matrix<BaseScalar,JacobianType::RowsAtCompileTime,1> > ActiveScalar;
39c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    typedef ActiveScalar Scalar;
40c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    typedef AutoDiffScalar<typename JacobianType::ColXpr> CoeffType;
41c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    typedef typename JacobianType::Index Index;
42c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
43c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline AutoDiffVector() {}
44c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
45c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline AutoDiffVector(const ValueType& values)
46c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      : m_values(values)
47c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
48c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      m_jacobian.setZero();
49c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
50c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
51c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
52c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    CoeffType operator[] (Index i) { return CoeffType(m_values[i], m_jacobian.col(i)); }
53c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    const CoeffType operator[] (Index i) const { return CoeffType(m_values[i], m_jacobian.col(i)); }
54c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
55c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    CoeffType operator() (Index i) { return CoeffType(m_values[i], m_jacobian.col(i)); }
56c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    const CoeffType operator() (Index i) const { return CoeffType(m_values[i], m_jacobian.col(i)); }
57c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
58c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    CoeffType coeffRef(Index i) { return CoeffType(m_values[i], m_jacobian.col(i)); }
59c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    const CoeffType coeffRef(Index i) const { return CoeffType(m_values[i], m_jacobian.col(i)); }
60c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
61c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    Index size() const { return m_values.size(); }
62c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
63c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    // FIXME here we could return an expression of the sum
64c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    Scalar sum() const { /*std::cerr << "sum \n\n";*/ /*std::cerr << m_jacobian.rowwise().sum() << "\n\n";*/ return Scalar(m_values.sum(), m_jacobian.rowwise().sum()); }
65c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
66c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
67c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline AutoDiffVector(const ValueType& values, const JacobianType& jac)
68c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      : m_values(values), m_jacobian(jac)
69c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {}
70c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
71c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    template<typename OtherValueType, typename OtherJacobianType>
72c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline AutoDiffVector(const AutoDiffVector<OtherValueType, OtherJacobianType>& other)
73c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      : m_values(other.values()), m_jacobian(other.jacobian())
74c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {}
75c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
76c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline AutoDiffVector(const AutoDiffVector& other)
77c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      : m_values(other.values()), m_jacobian(other.jacobian())
78c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {}
79c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
80c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    template<typename OtherValueType, typename OtherJacobianType>
81c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline AutoDiffVector& operator=(const AutoDiffVector<OtherValueType, OtherJacobianType>& other)
82c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
83c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      m_values = other.values();
84c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      m_jacobian = other.jacobian();
85c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return *this;
86c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
87c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
88c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline AutoDiffVector& operator=(const AutoDiffVector& other)
89c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
90c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      m_values = other.values();
91c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      m_jacobian = other.jacobian();
92c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return *this;
93c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
94c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
95c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline const ValueType& values() const { return m_values; }
96c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline ValueType& values() { return m_values; }
97c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
98c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline const JacobianType& jacobian() const { return m_jacobian; }
99c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline JacobianType& jacobian() { return m_jacobian; }
100c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
101c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    template<typename OtherValueType,typename OtherJacobianType>
102c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline const AutoDiffVector<
103c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      typename MakeCwiseBinaryOp<internal::scalar_sum_op<BaseScalar>,ValueType,OtherValueType>::Type,
104c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      typename MakeCwiseBinaryOp<internal::scalar_sum_op<BaseScalar>,JacobianType,OtherJacobianType>::Type >
105c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    operator+(const AutoDiffVector<OtherValueType,OtherJacobianType>& other) const
106c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
107c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return AutoDiffVector<
108c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      typename MakeCwiseBinaryOp<internal::scalar_sum_op<BaseScalar>,ValueType,OtherValueType>::Type,
109c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      typename MakeCwiseBinaryOp<internal::scalar_sum_op<BaseScalar>,JacobianType,OtherJacobianType>::Type >(
110c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath        m_values + other.values(),
111c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath        m_jacobian + other.jacobian());
112c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
113c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
114c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    template<typename OtherValueType, typename OtherJacobianType>
115c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline AutoDiffVector&
116c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    operator+=(const AutoDiffVector<OtherValueType,OtherJacobianType>& other)
117c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
118c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      m_values += other.values();
119c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      m_jacobian += other.jacobian();
120c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return *this;
121c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
122c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
123c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    template<typename OtherValueType,typename OtherJacobianType>
124c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline const AutoDiffVector<
125c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      typename MakeCwiseBinaryOp<internal::scalar_difference_op<Scalar>,ValueType,OtherValueType>::Type,
126c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      typename MakeCwiseBinaryOp<internal::scalar_difference_op<Scalar>,JacobianType,OtherJacobianType>::Type >
127c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    operator-(const AutoDiffVector<OtherValueType,OtherJacobianType>& other) const
128c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
129c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return AutoDiffVector<
130c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath        typename MakeCwiseBinaryOp<internal::scalar_difference_op<Scalar>,ValueType,OtherValueType>::Type,
131c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath        typename MakeCwiseBinaryOp<internal::scalar_difference_op<Scalar>,JacobianType,OtherJacobianType>::Type >(
132c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath          m_values - other.values(),
133c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath          m_jacobian - other.jacobian());
134c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
135c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
136c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    template<typename OtherValueType, typename OtherJacobianType>
137c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline AutoDiffVector&
138c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    operator-=(const AutoDiffVector<OtherValueType,OtherJacobianType>& other)
139c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
140c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      m_values -= other.values();
141c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      m_jacobian -= other.jacobian();
142c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return *this;
143c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
144c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
145c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline const AutoDiffVector<
146c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      typename MakeCwiseUnaryOp<internal::scalar_opposite_op<Scalar>, ValueType>::Type,
147c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      typename MakeCwiseUnaryOp<internal::scalar_opposite_op<Scalar>, JacobianType>::Type >
148c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    operator-() const
149c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
150c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return AutoDiffVector<
151c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath        typename MakeCwiseUnaryOp<internal::scalar_opposite_op<Scalar>, ValueType>::Type,
152c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath        typename MakeCwiseUnaryOp<internal::scalar_opposite_op<Scalar>, JacobianType>::Type >(
153c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath          -m_values,
154c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath          -m_jacobian);
155c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
156c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
157c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline const AutoDiffVector<
158c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, ValueType>::Type,
159c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, JacobianType>::Type>
160c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    operator*(const BaseScalar& other) const
161c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
162c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return AutoDiffVector<
163c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath        typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, ValueType>::Type,
164c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath        typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, JacobianType>::Type >(
165c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath          m_values * other,
166c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath          m_jacobian * other);
167c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
168c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
169c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    friend inline const AutoDiffVector<
170c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, ValueType>::Type,
171c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, JacobianType>::Type >
172c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    operator*(const Scalar& other, const AutoDiffVector& v)
173c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
174c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return AutoDiffVector<
175c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath        typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, ValueType>::Type,
176c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath        typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, JacobianType>::Type >(
177c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath          v.values() * other,
178c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath          v.jacobian() * other);
179c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
180c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
181c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//     template<typename OtherValueType,typename OtherJacobianType>
182c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//     inline const AutoDiffVector<
183c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//       CwiseBinaryOp<internal::scalar_multiple_op<Scalar>, ValueType, OtherValueType>
184c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//       CwiseBinaryOp<internal::scalar_sum_op<Scalar>,
185c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//         CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, JacobianType>,
186c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//         CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, OtherJacobianType> > >
187c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//     operator*(const AutoDiffVector<OtherValueType,OtherJacobianType>& other) const
188c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//     {
189c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//       return AutoDiffVector<
190c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//         CwiseBinaryOp<internal::scalar_multiple_op<Scalar>, ValueType, OtherValueType>
191c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//         CwiseBinaryOp<internal::scalar_sum_op<Scalar>,
192c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//           CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, JacobianType>,
193c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//           CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, OtherJacobianType> > >(
194c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//             m_values.cwise() * other.values(),
195c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//             (m_jacobian * other.values()) + (m_values * other.jacobian()));
196c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//     }
197c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
198c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline AutoDiffVector& operator*=(const Scalar& other)
199c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
200c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      m_values *= other;
201c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      m_jacobian *= other;
202c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return *this;
203c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
204c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
205c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    template<typename OtherValueType,typename OtherJacobianType>
206c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline AutoDiffVector& operator*=(const AutoDiffVector<OtherValueType,OtherJacobianType>& other)
207c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
208c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      *this = *this * other;
209c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return *this;
210c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
211c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
212c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  protected:
213c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    ValueType m_values;
214c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    JacobianType m_jacobian;
215c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
216c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath};
217c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
218c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath}
219c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
220c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath#endif // EIGEN_AUTODIFF_VECTOR_H
221