10#ifndef EIGEN_AUTODIFF_VECTOR_H
11#define EIGEN_AUTODIFF_VECTOR_H
14#include "./InternalHeaderCheck.h"
35template <
typename ValueType,
typename JacobianType>
39 typedef typename internal::traits<ValueType>::Scalar BaseScalar;
40 typedef AutoDiffScalar<Matrix<BaseScalar, JacobianType::RowsAtCompileTime, 1> > ActiveScalar;
41 typedef ActiveScalar Scalar;
42 typedef AutoDiffScalar<typename JacobianType::ColXpr> CoeffType;
43 typedef typename JacobianType::Index Index;
45 inline AutoDiffVector() {}
47 inline AutoDiffVector(
const ValueType& values) : m_values(values) { m_jacobian.setZero(); }
49 CoeffType operator[](Index i) {
return CoeffType(m_values[i], m_jacobian.col(i)); }
50 const CoeffType operator[](Index i)
const {
return CoeffType(m_values[i], m_jacobian.col(i)); }
52 CoeffType operator()(Index i) {
return CoeffType(m_values[i], m_jacobian.col(i)); }
53 const CoeffType operator()(Index i)
const {
return CoeffType(m_values[i], m_jacobian.col(i)); }
55 CoeffType coeffRef(Index i) {
return CoeffType(m_values[i], m_jacobian.col(i)); }
56 const CoeffType coeffRef(Index i)
const {
return CoeffType(m_values[i], m_jacobian.col(i)); }
58 Index size()
const {
return m_values.size(); }
62 return Scalar(m_values.sum(), m_jacobian.rowwise().sum());
65 inline AutoDiffVector(
const ValueType& values,
const JacobianType& jac) : m_values(values), m_jacobian(jac) {}
67 template <
typename OtherValueType,
typename OtherJacobianType>
68 inline AutoDiffVector(
const AutoDiffVector<OtherValueType, OtherJacobianType>& other)
69 : m_values(other.values()), m_jacobian(other.jacobian()) {}
71 inline AutoDiffVector(
const AutoDiffVector& other) : m_values(other.values()), m_jacobian(other.jacobian()) {}
73 template <
typename OtherValueType,
typename OtherJacobianType>
74 inline AutoDiffVector& operator=(
const AutoDiffVector<OtherValueType, OtherJacobianType>& other) {
75 m_values = other.values();
76 m_jacobian = other.jacobian();
80 inline AutoDiffVector& operator=(
const AutoDiffVector& other) {
81 m_values = other.values();
82 m_jacobian = other.jacobian();
86 inline const ValueType& values()
const {
return m_values; }
87 inline ValueType& values() {
return m_values; }
89 inline const JacobianType& jacobian()
const {
return m_jacobian; }
90 inline JacobianType& jacobian() {
return m_jacobian; }
92 template <
typename OtherValueType,
typename OtherJacobianType>
93 inline const AutoDiffVector<
94 typename MakeCwiseBinaryOp<internal::scalar_sum_op<BaseScalar>, ValueType, OtherValueType>::Type,
95 typename MakeCwiseBinaryOp<internal::scalar_sum_op<BaseScalar>, JacobianType, OtherJacobianType>::Type>
96 operator+(
const AutoDiffVector<OtherValueType, OtherJacobianType>& other)
const {
97 return AutoDiffVector<
98 typename MakeCwiseBinaryOp<internal::scalar_sum_op<BaseScalar>, ValueType, OtherValueType>::Type,
99 typename MakeCwiseBinaryOp<internal::scalar_sum_op<BaseScalar>, JacobianType, OtherJacobianType>::Type>(
100 m_values + other.values(), m_jacobian + other.jacobian());
103 template <
typename OtherValueType,
typename OtherJacobianType>
104 inline AutoDiffVector& operator+=(
const AutoDiffVector<OtherValueType, OtherJacobianType>& other) {
105 m_values += other.values();
106 m_jacobian += other.jacobian();
110 template <
typename OtherValueType,
typename OtherJacobianType>
111 inline const AutoDiffVector<
112 typename MakeCwiseBinaryOp<internal::scalar_difference_op<Scalar>, ValueType, OtherValueType>::Type,
113 typename MakeCwiseBinaryOp<internal::scalar_difference_op<Scalar>, JacobianType, OtherJacobianType>::Type>
114 operator-(
const AutoDiffVector<OtherValueType, OtherJacobianType>& other)
const {
115 return AutoDiffVector<
116 typename MakeCwiseBinaryOp<internal::scalar_difference_op<Scalar>, ValueType, OtherValueType>::Type,
117 typename MakeCwiseBinaryOp<internal::scalar_difference_op<Scalar>, JacobianType, OtherJacobianType>::Type>(
118 m_values - other.values(), m_jacobian - other.jacobian());
121 template <
typename OtherValueType,
typename OtherJacobianType>
122 inline AutoDiffVector& operator-=(
const AutoDiffVector<OtherValueType, OtherJacobianType>& other) {
123 m_values -= other.values();
124 m_jacobian -= other.jacobian();
128 inline const AutoDiffVector<typename MakeCwiseUnaryOp<internal::scalar_opposite_op<Scalar>, ValueType>::Type,
129 typename MakeCwiseUnaryOp<internal::scalar_opposite_op<Scalar>, JacobianType>::Type>
131 return AutoDiffVector<typename MakeCwiseUnaryOp<internal::scalar_opposite_op<Scalar>, ValueType>::Type,
132 typename MakeCwiseUnaryOp<internal::scalar_opposite_op<Scalar>, JacobianType>::Type>(
133 -m_values, -m_jacobian);
136 inline const AutoDiffVector<typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, ValueType>::Type,
137 typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, JacobianType>::Type>
138 operator*(
const BaseScalar& other)
const {
139 return AutoDiffVector<typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, ValueType>::Type,
140 typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, JacobianType>::Type>(
141 m_values * other, m_jacobian * other);
144 friend inline const AutoDiffVector<
145 typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, ValueType>::Type,
146 typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, JacobianType>::Type>
147 operator*(
const Scalar& other,
const AutoDiffVector& v) {
148 return AutoDiffVector<typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, ValueType>::Type,
149 typename MakeCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, JacobianType>::Type>(
150 v.values() * other, v.jacobian() * other);
170 inline AutoDiffVector& operator*=(
const Scalar& other) {
176 template <
typename OtherValueType,
typename OtherJacobianType>
177 inline AutoDiffVector& operator*=(
const AutoDiffVector<OtherValueType, OtherJacobianType>& other) {
178 *
this = *
this * other;
184 JacobianType m_jacobian;
Namespace containing all symbols from the Eigen library.