22 #include <gtsam/nonlinear/internal/ExpressionNode.h> 24 #include <boost/tuple/tuple.hpp> 25 #include <boost/range/adaptor/map.hpp> 26 #include <boost/range/algorithm.hpp> 32 root_(new internal::ConstantExpression<T>(value)) {
37 root_(new internal::LeafExpression<T>(key)) {
42 root_(new internal::LeafExpression<T>(symbol)) {
47 root_(new internal::LeafExpression<T>(
Symbol(c, j))) {
55 root_(new internal::UnaryExpression<T, A>(function, expression)) {
60 template<
typename A1,
typename A2>
64 new internal::BinaryExpression<T, A1, A2>(function, expression1,
70 template<
typename A1,
typename A2,
typename A3>
75 new internal::TernaryExpression<T, A1, A2, A3>(function, expression1,
76 expression2, expression3)) {
85 new internal::UnaryExpression<T, A>(
boost::bind(method, _1, _2),
91 template<
typename A1,
typename A2>
97 new internal::BinaryExpression<T, A1, A2>(
98 boost::bind(method, _1, _2, _3, _4), expression1, expression2)) {
103 template<
typename A1,
typename A2,
typename A3>
105 T (A1::*method)(
const A2&,
const A3&,
111 new internal::TernaryExpression<T, A1, A2, A3>(
112 boost::bind(method, _1, _2, _3, _4, _5, _6), expression1,
113 expression2, expression3)) {
118 return root_->keys();
133 boost::optional<std::vector<Matrix>&> H)
const {
141 return root_->value(values);
151 return root_->traceSize();
159 std::vector<Matrix>& H)
const {
162 assert(H.size()==keys.size());
168 internal::JacobianMap jacobianMap(keys, Ab);
174 for (
DenseIndex i = 0; i < static_cast<DenseIndex>(keys.size()); i++)
183 return root_->traceExecution(values, trace,
184 static_cast<internal::ExecutionTraceStorage*>(traceStorage));
189 internal::JacobianMap& jacobians)
const {
201 internal::ExecutionTraceStorage* traceStorage =
new internal::ExecutionTraceStorage[size];
203 internal::ExecutionTraceStorage traceStorage[size];
208 trace.startReverseAD1(jacobians);
211 delete[] traceStorage;
219 std::map<Key, int> map;
221 size_t n = map.size();
223 boost::copy(map | boost::adaptors::map_keys, pair.first.begin());
224 boost::copy(map | boost::adaptors::map_values, pair.second.begin());
232 typedef T result_type;
236 return x.compose(y, H1, H2);
255 std::vector<Expression<T> > unknowns;
257 for (
size_t i = start; i < start + n; i++)
262 template <
typename T>
264 :
Expression<T>(boost::make_shared<internal::ScalarMultiplyNode<T>>(s, e)) {}
267 template <
typename T>
269 :
Expression<T>(boost::make_shared<internal::BinarySumNode<T>>(e1, e2)) {}
271 template <
typename T>
273 root_ = boost::make_shared<internal::BinarySumNode<T>>(*
this, e);
Expression class that supports automatic differentiation.
Definition: Expression.h:49
Definition: Expression.h:41
void print(const std::string &s) const
Print.
Definition: Expression-inl.h:127
Character and index key used in VectorValues, GaussianFactorGraph, GaussianFactor, etc.
Definition: Symbol.h:34
std::pair< KeyVector, FastVector< int > > KeysAndDims
Keys and dimensions in same order.
Definition: Expression.h:186
std::vector< Expression< T > > createUnknowns(size_t n, char c, size_t start)
Construct an array of leaves.
Definition: Expression-inl.h:254
T valueAndDerivatives(const Values &values, const KeyVector &keys, const FastVector< int > &dims, std::vector< Matrix > &H) const
private version that takes keys and dimensions, returns derivatives
Definition: Expression-inl.h:157
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition: OptionalJacobian.h:39
Definition: VerticalBlockMatrix.h:41
size_t traceSize() const
Return size needed for memory buffer in traceExecution.
Definition: Expression-inl.h:150
T valueAndJacobianMap(const Values &values, internal::JacobianMap &jacobians) const
brief Return value and derivatives, reverse AD version
Definition: Expression-inl.h:188
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:70
const Matrix & matrix() const
Access to full matrix (including any portions excluded by rowStart(), rowEnd(), and firstBlock()) ...
Definition: VerticalBlockMatrix.h:187
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:60
FastVector< Key > KeyVector
Useful typedef for operations with Values - allows for matlab interface.
Definition: Key.h:56
T value(const Values &values, boost::optional< std::vector< Matrix > & > H=boost::none) const
Return value and optional derivatives, reverse AD version Notes: this is not terribly efficient...
Definition: Expression-inl.h:132
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Definition: Expression-inl.h:231
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:170
Expression< T > & operator+=(const Expression< T > &e)
Add another expression to this expression.
Definition: Expression-inl.h:272
A BinarySumExpression is a specialization of Expression that adds two expressions together It optimiz...
Definition: Expression.h:227
std::set< Key > keys() const
Return keys that play in this expression.
Definition: Expression-inl.h:117
A ScalarMultiplyExpression is a specialization of Expression that multiplies with a scalar It optimiz...
Definition: Expression.h:214
T traceExecution(const Values &values, internal::ExecutionTrace< T > &trace, void *traceStorage) const
trace execution, very unsafe
Definition: Expression-inl.h:181
const boost::shared_ptr< internal::ExpressionNode< T > > & root() const
Return root.
Definition: Expression-inl.h:145
void dims(std::map< Key, int > &map) const
Return dimensions for each argument, as a map.
Definition: Expression-inl.h:122
Key symbol(unsigned char c, std::uint64_t j)
Create a symbol key from a character and index, i.e.
Definition: Symbol.h:128
Expression()
Default constructor, for serialization.
Definition: Expression.h:183
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
Global functions in a separate testing namespace.
Definition: chartTesting.h:28