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 {
138 FastVector<int> dims;
139 boost::tie(keys, dims) = keysAndDims();
140 return valueAndDerivatives(values, keys, dims, *H);
143 return root_->value(values);
160 const KeyVector& keys,
const FastVector<int>& dims,
161 std::vector<Matrix>& H)
const {
164 assert(H.size()==keys.size());
170 internal::JacobianMap jacobianMap(keys, Ab);
173 T result = valueAndJacobianMap(values, jacobianMap);
176 for (
DenseIndex i = 0; i < static_cast<DenseIndex>(keys.size()); i++)
186 static_cast<internal::ExecutionTraceStorage*>(traceStorage));
191 internal::JacobianMap& jacobians)
const {
197 size_t size = traceSize();
203 auto traceStorage = static_cast<internal::ExecutionTraceStorage*>(_aligned_malloc(size, internal::TraceAlignment));
205 internal::ExecutionTraceStorage traceStorage[size];
209 T value(this->traceExecution(values, trace, traceStorage));
210 trace.startReverseAD1(jacobians);
213 _aligned_free(traceStorage);
221 std::map<Key, int> map;
223 size_t n = map.size();
224 KeysAndDims pair = std::make_pair(
KeyVector(n), FastVector<int>(n));
225 boost::copy(map | boost::adaptors::map_keys, pair.first.begin());
226 boost::copy(map | boost::adaptors::map_values, pair.second.begin());
234 typedef T result_type;
238 return x.compose(y, H1, H2);
257 std::vector<Expression<T> > unknowns;
259 for (
size_t i = start; i < start + n; i++)
264 template <
typename T>
265 ScalarMultiplyExpression<T>::ScalarMultiplyExpression(
double s,
const Expression<T>& e)
266 : Expression<T>(boost::make_shared<internal::ScalarMultiplyNode<T>>(s, e)) {}
269 template <
typename T>
270 BinarySumExpression<T>::BinarySumExpression(
const Expression<T>& e1,
const Expression<T>& e2)
271 : Expression<T>(boost::make_shared<internal::BinarySumNode<T>>(e1, e2)) {}
273 template <
typename T>
275 root_ = boost::make_shared<internal::BinarySumNode<T>>(*
this, e);
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:70
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:63
Character and index key used to refer to variables.
Definition: Symbol.h:33
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:141
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
size_t traceSize() const
Return size needed for memory buffer in traceExecution.
Definition: Expression-inl.h:152
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition: OptionalJacobian.h:39
Definition: Expression-inl.h:233
Definition: VerticalBlockMatrix.h:41
void dims(std::map< Key, int > &map) const
Return dimensions for each argument, as a map.
Definition: Expression-inl.h:122
std::vector< Expression< T > > createUnknowns(size_t n, char c, size_t start)
Construct an array of leaves.
Definition: Expression-inl.h:256
Definition: Expression.h:41
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:56
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Expression class that supports automatic differentiation.
Definition: Expression.h:49
Expression< T > operator *(const Expression< T > &expression1, const Expression< T > &expression2)
Construct a product expression, assumes T::compose(T) -> T.
Definition: Expression-inl.h:247
const Matrix & matrix() const
Access to full matrix (including any portions excluded by rowStart(), rowEnd(), and firstBlock())
Definition: VerticalBlockMatrix.h:187
T traceExecution(const Values &values, internal::ExecutionTrace< T > &trace, void *traceStorage) const
trace execution, very unsafe
Definition: Expression-inl.h:183
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
Key symbol(unsigned char c, std::uint64_t j)
Create a symbol key from a character and index, i.e.
Definition: Symbol.h:127
Expression()
Default constructor, for serialization.
Definition: Expression.h:183
std::set< Key > keys() const
Return keys that play in this expression.
Definition: Expression-inl.h:117
std::pair< KeyVector, FastVector< int > > KeysAndDims
Keys and dimensions in same order.
Definition: Expression.h:186