ExpressionNode.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
20 #pragma once
21 
24 #include <gtsam/nonlinear/Values.h>
25 
26 #include <typeinfo> // operator typeid
27 #include <ostream>
28 #include <map>
29 #include <cassert>
30 
31 class ExpressionFactorBinaryTest;
32 // Forward declare for testing
33 
34 namespace gtsam {
35 namespace internal {
36 
37 template<typename T>
38 T & upAlign(T & value, unsigned requiredAlignment = TraceAlignment) {
39  // right now only word sized types are supported.
40  // Easy to extend if needed,
41  // by somehow inferring the unsigned integer of same size
42  static_assert(sizeof(T) == sizeof(size_t));
43  size_t & uiValue = reinterpret_cast<size_t &>(value);
44  size_t misAlignment = uiValue % requiredAlignment;
45  if (misAlignment) {
46  uiValue += requiredAlignment - misAlignment;
47  }
48  return value;
49 }
50 template<typename T>
51 T upAligned(T value, unsigned requiredAlignment = TraceAlignment) {
52  return upAlign(value, requiredAlignment);
53 }
54 
55 //-----------------------------------------------------------------------------
56 
64 template<class T>
65 class ExpressionNode {
66 
67 protected:
68 
69  size_t traceSize_;
70 
72  ExpressionNode(size_t traceSize = 0) :
74  }
75 
76 public:
77 
79  virtual ~ExpressionNode() {
80  }
81 
83  virtual void print(const std::string& indent = "") const = 0;
84 
86  GTSAM_EXPORT
87  friend std::ostream& operator<<(std::ostream& os, const ExpressionNode& node) {
88  os << "Expression of type " << demangle(typeid(T).name());
89  if (node.traceSize_ > 0) os << ", trace size = " << node.traceSize_;
90  os << "\n";
91  return os;
92  }
93 
95  virtual std::set<Key> keys() const {
96  std::set<Key> keys;
97  return keys;
98  }
99 
101  virtual void dims(std::map<Key, int>& map) const {
102  }
103 
104  // Return size needed for memory buffer in traceExecution
105  size_t traceSize() const {
106  return traceSize_;
107  }
108 
110  virtual T value(const Values& values) const = 0;
111 
113  virtual T traceExecution(const Values& values, ExecutionTrace<T>& trace,
114  char* traceStorage) const = 0;
115 };
116 
117 //-----------------------------------------------------------------------------
119 template<class T>
121 
124 
127  constant_(value) {
128  }
129 
130  friend class Expression<T> ;
131 
132 public:
133 
135  ~ConstantExpression() override {
136  }
137 
139  void print(const std::string& indent = "") const override {
140  std::cout << indent << "Constant" << std::endl;
141  }
142 
144  T value(const Values& values) const override {
145  return constant_;
146  }
147 
150  char* traceStorage) const override {
151  return constant_;
152  }
153 
155 };
156 
157 //-----------------------------------------------------------------------------
159 template<typename T>
160 class LeafExpression: public ExpressionNode<T> {
161  typedef T value_type;
162 
165 
168  key_(key) {
169  }
170 
171  friend class Expression<T>;
172 
173 public:
174 
176  ~LeafExpression() override {
177  }
178 
180  void print(const std::string& indent = "") const override {
181  std::cout << indent << "Leaf, key = " << DefaultKeyFormatter(key_) << std::endl;
182  }
183 
185  std::set<Key> keys() const override {
186  std::set<Key> keys;
187  keys.insert(key_);
188  return keys;
189  }
190 
192  void dims(std::map<Key, int>& map) const override {
193  map[key_] = traits<T>::dimension;
194  }
195 
197  T value(const Values& values) const override {
198  return values.at<T>(key_);
199  }
200 
203  char* traceStorage) const override {
204  trace.setLeaf(key_);
205  return values.at<T>(key_);
206  }
207 
208 };
209 
210 //-----------------------------------------------------------------------------
212 template<class T, class A>
213 struct Jacobian {
215 };
216 
217 // Helper function for printing Jacobians with compact Eigen format, and trace
218 template <class T, class A>
219 static void PrintJacobianAndTrace(const std::string& indent,
220  const typename Jacobian<T, A>::type& dTdA,
221  const ExecutionTrace<A> trace) {
222  static const Eigen::IOFormat kMatlabFormat(0, 1, " ", "; ", "", "", "[", "]");
223  std::cout << indent << "D(" << demangle(typeid(T).name()) << ")/D(" << demangle(typeid(A).name())
224  << ") = " << dTdA.format(kMatlabFormat) << std::endl;
225  trace.print(indent);
226 }
227 
228 //-----------------------------------------------------------------------------
230 template<class T, class A1>
231 class UnaryExpression: public ExpressionNode<T> {
232 
234  std::shared_ptr<ExpressionNode<A1> > expression1_;
236 
239  expression1_(e1.root()), function_(f) {
240  this->traceSize_ = upAligned(sizeof(Record)) + e1.traceSize();
241  }
242 
243  friend class Expression<T>;
244 
245 public:
246 
248  ~UnaryExpression() override {
249  }
250 
252  void print(const std::string& indent = "") const override {
253  std::cout << indent << "UnaryExpression" << std::endl;
254  expression1_->print(indent + " ");
255  }
256 
258  T value(const Values& values) const override {
259  return function_(expression1_->value(values), {});
260  }
261 
263  std::set<Key> keys() const override {
264  return expression1_->keys();
265  }
266 
268  void dims(std::map<Key, int>& map) const override {
269  expression1_->dims(map);
270  }
271 
272  // Inner Record Class
273  struct Record: public CallRecordImplementor<Record, traits<T>::dimension> {
274 
278 
280  Record(const Values& values, const ExpressionNode<A1>& expression1, char* ptr)
281  : value1(expression1.traceExecution(values, trace1, ptr + upAligned(sizeof(Record)))) {}
282 
284  void print(const std::string& indent) const {
285  std::cout << indent << "UnaryExpression::Record {" << std::endl;
286  PrintJacobianAndTrace<T,A1>(indent, dTdA1, trace1);
287  std::cout << indent << "}" << std::endl;
288  }
289 
291  void startReverseAD4(JacobianMap& jacobians) const {
292  // This is the crucial point where the size of the AD pipeline is selected.
293  // One pipeline is started for each argument, but the number of rows in each
294  // pipeline is the same, namely the dimension of the output argument T.
295  // For example, if the entire expression is rooted by a binary function
296  // yielding a 2D result, then the matrix dTdA will have 2 rows.
297  // ExecutionTrace::reverseAD1 just passes this on to CallRecord::reverseAD2
298  // which calls the correctly sized CallRecord::reverseAD3, which in turn
299  // calls reverseAD4 below.
300  trace1.reverseAD1(dTdA1, jacobians);
301  }
302 
304  template<typename MatrixType>
305  void reverseAD4(const MatrixType & dFdT, JacobianMap& jacobians) const {
306  trace1.reverseAD1(dFdT * dTdA1, jacobians);
307  }
308  };
309 
312  char* ptr) const override {
313  assert(reinterpret_cast<size_t>(ptr) % TraceAlignment == 0);
314 
315  // Create a Record in the memory pointed to by ptr
316  // Calling the constructor will record the traces for all arguments
317  // Write an Expression<A> execution trace in record->trace
318  // Iff Constant or Leaf, this will not write to traceStorage, only to trace.
319  // Iff the expression is functional, write all Records in traceStorage buffer
320  // Return value of type T is recorded in record->value
321  // NOTE(frank, abe): The destructor on this record is never called due to this placement new
322  // Records must only contain statically sized objects!
323  Record* record = new (ptr) Record(values, *expression1_, ptr);
324 
325  // Our trace parameter is set to point to the Record
326  trace.setFunction(record);
327 
328  // Finally, the function call fills in the Jacobian dTdA1
329  return function_(record->value1, record->dTdA1);
330  }
331 };
332 
333 //-----------------------------------------------------------------------------
335 template<class T, class A1, class A2>
337 
339  std::shared_ptr<ExpressionNode<A1> > expression1_;
340  std::shared_ptr<ExpressionNode<A2> > expression2_;
342 
345  const Expression<A2>& e2) :
346  expression1_(e1.root()), expression2_(e2.root()), function_(f) {
347  this->traceSize_ = //
348  upAligned(sizeof(Record)) + e1.traceSize() + e2.traceSize();
349  }
350 
351  friend class Expression<T>;
352  friend class ::ExpressionFactorBinaryTest;
353 
354 public:
355 
357  ~BinaryExpression() override {
358  }
359 
361  void print(const std::string& indent = "") const override {
362  std::cout << indent << "BinaryExpression" << std::endl;
363  expression1_->print(indent + " ");
364  expression2_->print(indent + " ");
365  }
366 
368  T value(const Values& values) const override {
369  using std::nullopt;
370  return function_(expression1_->value(values), expression2_->value(values),
371  {}, {});
372  }
373 
375  std::set<Key> keys() const override {
376  std::set<Key> keys = expression1_->keys();
377  std::set<Key> myKeys = expression2_->keys();
378  keys.insert(myKeys.begin(), myKeys.end());
379  return keys;
380  }
381 
383  void dims(std::map<Key, int>& map) const override {
384  expression1_->dims(map);
385  expression2_->dims(map);
386  }
387 
388  // Inner Record Class
389  struct Record: public CallRecordImplementor<Record, traits<T>::dimension> {
390 
393 
396 
397  // TODO(frank): These aren't needed kill them!
400 
402  Record(const Values& values, const ExpressionNode<A1>& expression1,
403  const ExpressionNode<A2>& expression2, char* ptr)
404  : value1(expression1.traceExecution(values, trace1, ptr += upAligned(sizeof(Record)))),
405  value2(expression2.traceExecution(values, trace2, ptr += expression1.traceSize())) {}
406 
408  void print(const std::string& indent) const {
409  std::cout << indent << "BinaryExpression::Record {" << std::endl;
410  PrintJacobianAndTrace<T,A1>(indent, dTdA1, trace1);
411  PrintJacobianAndTrace<T,A2>(indent, dTdA2, trace2);
412  std::cout << indent << "}" << std::endl;
413  }
414 
416  void startReverseAD4(JacobianMap& jacobians) const {
417  trace1.reverseAD1(dTdA1, jacobians);
418  trace2.reverseAD1(dTdA2, jacobians);
419  }
420 
422  template<typename MatrixType>
423  void reverseAD4(const MatrixType & dFdT, JacobianMap& jacobians) const {
424  trace1.reverseAD1(dFdT * dTdA1, jacobians);
425  trace2.reverseAD1(dFdT * dTdA2, jacobians);
426  }
427  };
428 
431  char* ptr) const override {
432  assert(reinterpret_cast<size_t>(ptr) % TraceAlignment == 0);
433  Record* record = new (ptr) Record(values, *expression1_, *expression2_, ptr);
434  trace.setFunction(record);
435  return function_(record->value1, record->value2, record->dTdA1, record->dTdA2);
436  }
437 };
438 
439 //-----------------------------------------------------------------------------
441 template<class T, class A1, class A2, class A3>
443 
445  std::shared_ptr<ExpressionNode<A1> > expression1_;
446  std::shared_ptr<ExpressionNode<A2> > expression2_;
447  std::shared_ptr<ExpressionNode<A3> > expression3_;
449 
452  const Expression<A2>& e2, const Expression<A3>& e3) :
453  expression1_(e1.root()), expression2_(e2.root()), expression3_(e3.root()), //
454  function_(f) {
455  this->traceSize_ = upAligned(sizeof(Record)) + //
456  e1.traceSize() + e2.traceSize() + e3.traceSize();
457  }
458 
459  friend class Expression<T>;
460 
461 public:
462 
464  ~TernaryExpression() override {
465  }
466 
468  void print(const std::string& indent = "") const override {
469  std::cout << indent << "TernaryExpression" << std::endl;
470  expression1_->print(indent + " ");
471  expression2_->print(indent + " ");
472  expression3_->print(indent + " ");
473  }
474 
476  T value(const Values& values) const override {
477  using std::nullopt;
478  return function_(expression1_->value(values), expression2_->value(values),
479  expression3_->value(values), {}, {}, {});
480  }
481 
483  std::set<Key> keys() const override {
484  std::set<Key> keys = expression1_->keys();
485  std::set<Key> myKeys = expression2_->keys();
486  keys.insert(myKeys.begin(), myKeys.end());
487  myKeys = expression3_->keys();
488  keys.insert(myKeys.begin(), myKeys.end());
489  return keys;
490  }
491 
493  void dims(std::map<Key, int>& map) const override {
494  expression1_->dims(map);
495  expression2_->dims(map);
496  expression3_->dims(map);
497  }
498 
499  // Inner Record Class
500  struct Record: public CallRecordImplementor<Record, traits<T>::dimension> {
501 
503 
507 
511 
515 
517  Record(const Values& values, const ExpressionNode<A1>& expression1,
518  const ExpressionNode<A2>& expression2,
519  const ExpressionNode<A3>& expression3, char* ptr)
520  : value1(expression1.traceExecution(values, trace1, ptr += upAligned(sizeof(Record)))),
521  value2(expression2.traceExecution(values, trace2, ptr += expression1.traceSize())),
522  value3(expression3.traceExecution(values, trace3, ptr += expression2.traceSize())) {}
523 
525  void print(const std::string& indent) const {
526  std::cout << indent << "TernaryExpression::Record {" << std::endl;
527  PrintJacobianAndTrace<T,A1>(indent, dTdA1, trace1);
528  PrintJacobianAndTrace<T,A2>(indent, dTdA2, trace2);
529  PrintJacobianAndTrace<T,A3>(indent, dTdA3, trace3);
530  std::cout << indent << "}" << std::endl;
531  }
532 
534  void startReverseAD4(JacobianMap& jacobians) const {
535  trace1.reverseAD1(dTdA1, jacobians);
536  trace2.reverseAD1(dTdA2, jacobians);
537  trace3.reverseAD1(dTdA3, jacobians);
538  }
539 
541  template<typename MatrixType>
542  void reverseAD4(const MatrixType & dFdT, JacobianMap& jacobians) const {
543  trace1.reverseAD1(dFdT * dTdA1, jacobians);
544  trace2.reverseAD1(dFdT * dTdA2, jacobians);
545  trace3.reverseAD1(dFdT * dTdA3, jacobians);
546  }
547  };
548 
551  char* ptr) const override {
552  assert(reinterpret_cast<size_t>(ptr) % TraceAlignment == 0);
553  Record* record = new (ptr) Record(values, *expression1_, *expression2_, *expression3_, ptr);
554  trace.setFunction(record);
555  return function_(record->value1, record->value2, record->value3,
556  record->dTdA1, record->dTdA2, record->dTdA3);
557  }
558 };
559 
560 //-----------------------------------------------------------------------------
562 template <class T>
564  // Check that T is a vector space
566 
567  double scalar_;
568  std::shared_ptr<ExpressionNode<T> > expression_;
569 
570  public:
572  ScalarMultiplyNode(double s, const Expression<T>& e) : scalar_(s), expression_(e.root()) {
573  this->traceSize_ = upAligned(sizeof(Record)) + e.traceSize();
574  }
575 
577  ~ScalarMultiplyNode() override {}
578 
580  void print(const std::string& indent = "") const override {
581  std::cout << indent << "ScalarMultiplyNode" << std::endl;
582  expression_->print(indent + " ");
583  }
584 
586  T value(const Values& values) const override {
587  return scalar_ * expression_->value(values);
588  }
589 
591  std::set<Key> keys() const override {
592  return expression_->keys();
593  }
594 
596  void dims(std::map<Key, int>& map) const override {
597  expression_->dims(map);
598  }
599 
600  // Inner Record Class
601  struct Record : public CallRecordImplementor<Record, traits<T>::dimension> {
602  static const int Dim = traits<T>::dimension;
604 
605  double scalar_dTdA;
607 
609  void print(const std::string& indent) const {
610  std::cout << indent << "ScalarMultiplyNode::Record {" << std::endl;
611  std::cout << indent << "D(" << demangle(typeid(T).name()) << ")/D(" << demangle(typeid(T).name())
612  << ") = " << scalar_dTdA << std::endl;
613  trace.print();
614  std::cout << indent << "}" << std::endl;
615  }
616 
618  void startReverseAD4(JacobianMap& jacobians) const {
619  trace.reverseAD1(scalar_dTdA * JacobianTT::Identity(), jacobians);
620  }
621 
623  template <typename MatrixType>
624  void reverseAD4(const MatrixType& dFdT, JacobianMap& jacobians) const {
625  trace.reverseAD1(dFdT * scalar_dTdA, jacobians);
626  }
627  };
628 
631  char* ptr) const override {
632  assert(reinterpret_cast<size_t>(ptr) % TraceAlignment == 0);
633  Record* record = new (ptr) Record();
634  ptr += upAligned(sizeof(Record));
635  T value = expression_->traceExecution(values, record->trace, ptr);
636  ptr += expression_->traceSize();
637  trace.setFunction(record);
638  record->scalar_dTdA = scalar_;
639  return scalar_ * value;
640  }
641 };
642 
643 
644 //-----------------------------------------------------------------------------
646 template <class T>
647 class BinarySumNode : public ExpressionNode<T> {
649  std::shared_ptr<ExpressionNode<T> > expression1_;
650  std::shared_ptr<ExpressionNode<T> > expression2_;
651 
652  public:
653  explicit BinarySumNode() {
654  this->traceSize_ = upAligned(sizeof(Record));
655  }
656 
659  : expression1_(e1.root()), expression2_(e2.root()) {
660  this->traceSize_ = //
661  upAligned(sizeof(Record)) + e1.traceSize() + e2.traceSize();
662  }
663 
665  ~BinarySumNode() override {}
666 
668  void print(const std::string& indent = "") const override {
669  std::cout << indent << "BinarySumNode" << std::endl;
670  expression1_->print(indent + " ");
671  expression2_->print(indent + " ");
672  }
673 
675  T value(const Values& values) const override {
676  return expression1_->value(values) + expression2_->value(values);
677  }
678 
680  std::set<Key> keys() const override {
681  std::set<Key> keys = expression1_->keys();
682  std::set<Key> myKeys = expression2_->keys();
683  keys.insert(myKeys.begin(), myKeys.end());
684  return keys;
685  }
686 
688  void dims(std::map<Key, int>& map) const override {
689  expression1_->dims(map);
690  expression2_->dims(map);
691  }
692 
693  // Inner Record Class
694  struct Record : public CallRecordImplementor<Record, traits<T>::dimension> {
697 
699  void print(const std::string& indent) const {
700  std::cout << indent << "BinarySumNode::Record {" << std::endl;
701  trace1.print(indent);
702  trace2.print(indent);
703  std::cout << indent << "}" << std::endl;
704  }
705 
707  void startReverseAD4(JacobianMap& jacobians) const {
708  // NOTE(frank): equivalent to trace.reverseAD1(dTdA, jacobians) with dTdA=Identity
709  trace1.startReverseAD1(jacobians);
710  trace2.startReverseAD1(jacobians);
711  }
712 
714  template <typename MatrixType>
715  void reverseAD4(const MatrixType& dFdT, JacobianMap& jacobians) const {
716  // NOTE(frank): equivalent to trace.reverseAD1(dFdT * dTdA, jacobians) with dTdA=Identity
717  trace1.reverseAD1(dFdT, jacobians);
718  trace2.reverseAD1(dFdT, jacobians);
719  }
720  };
721 
724  char* ptr) const override {
725  assert(reinterpret_cast<size_t>(ptr) % TraceAlignment == 0);
726  Record *record = new (ptr) Record();
727  trace.setFunction(record);
728 
729  auto ptr1 = ptr + upAligned(sizeof(Record));
730  auto ptr2 = ptr1 + expression1_->traceSize();
731  return expression1_->traceExecution(values, record->trace1, ptr1) +
732  expression2_->traceExecution(values, record->trace2, ptr2);
733  }
734 };
735 
736 } // namespace internal
737 } // namespace gtsam
gtsam::internal::UnaryExpression::Record::trace1
ExecutionTrace< A1 > trace1
Definition: ExpressionNode.h:276
gtsam::internal::BinarySumNode::Record::trace1
ExecutionTrace< T > trace1
Definition: ExpressionNode.h:695
gtsam::internal::UnaryExpression::UnaryExpression
UnaryExpression(Function f, const Expression< A1 > &e1)
Constructor with a unary function f, and input argument e1.
Definition: ExpressionNode.h:238
gtsam::internal::ExpressionNode::traceSize
size_t traceSize() const
Definition: ExpressionNode.h:105
gtsam::internal::LeafExpression::keys
std::set< Key > keys() const override
Return keys that play in this expression.
Definition: ExpressionNode.h:185
gtsam::internal::BinarySumNode::Record
Definition: ExpressionNode.h:694
gtsam::internal::ConstantExpression
Constant Expression.
Definition: ExpressionNode.h:120
gtsam::internal::ExecutionTrace
Definition: Expression.h:39
gtsam::internal::ExecutionTrace::setLeaf
void setLeaf(Key key)
Change pointer to a Leaf Record.
Definition: ExecutionTrace.h:120
gtsam::internal::BinarySumNode::Record::startReverseAD4
void startReverseAD4(JacobianMap &jacobians) const
If the BinarySumExpression is the root, we just start as many pipelines as there are terms.
Definition: ExpressionNode.h:707
Eigen::IOFormat
Stores a set of parameters controlling the way matrices are printed.
Definition: IO.h:51
gtsam::internal::BinaryExpression::Record::dTdA1
Jacobian< T, A1 >::type dTdA1
Definition: ExpressionNode.h:391
gtsam::internal::TernaryExpression::Record::reverseAD4
void reverseAD4(const MatrixType &dFdT, JacobianMap &jacobians) const
Given df/dT, multiply in dT/dA and continue reverse AD process.
Definition: ExpressionNode.h:542
A3
static const double A3[]
Definition: expn.h:8
gtsam::internal::ExpressionNode::dims
virtual void dims(std::map< Key, int > &map) const
Return dimensions for each argument, as a map.
Definition: ExpressionNode.h:101
gtsam.examples.DogLegOptimizerExample.type
type
Definition: DogLegOptimizerExample.py:111
gtsam::internal::ExpressionNode::~ExpressionNode
virtual ~ExpressionNode()
Destructor.
Definition: ExpressionNode.h:79
gtsam::internal::Jacobian::type
Eigen::Matrix< double, traits< T >::dimension, traits< A >::dimension > type
Definition: ExpressionNode.h:214
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::internal::BinaryExpression::Record::trace1
ExecutionTrace< A1 > trace1
Definition: ExpressionNode.h:394
gtsam::internal::ScalarMultiplyNode::expression_
std::shared_ptr< ExpressionNode< T > > expression_
Definition: ExpressionNode.h:568
gtsam::internal::ExpressionNode::traceExecution
virtual T traceExecution(const Values &values, ExecutionTrace< T > &trace, char *traceStorage) const =0
Construct an execution trace for reverse AD.
MatrixType
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
gtsam::internal::TernaryExpression::Record::value3
A3 value3
Definition: ExpressionNode.h:514
gtsam::internal::UnaryExpression::print
void print(const std::string &indent="") const override
Print.
Definition: ExpressionNode.h:252
gtsam::internal::TraceAlignment
static const unsigned TraceAlignment
Definition: ExecutionTrace.h:45
gtsam::internal::ExpressionNode::operator<<
GTSAM_EXPORT friend std::ostream & operator<<(std::ostream &os, const ExpressionNode &node)
Streaming.
Definition: ExpressionNode.h:87
gtsam::internal::BinaryExpression::Record::dTdA2
Jacobian< T, A2 >::type dTdA2
Definition: ExpressionNode.h:392
gtsam::internal::UnaryExpression::dims
void dims(std::map< Key, int > &map) const override
Return dimensions for each argument.
Definition: ExpressionNode.h:268
gtsam::internal::BinaryExpression::keys
std::set< Key > keys() const override
Return keys that play in this expression.
Definition: ExpressionNode.h:375
gtsam::internal::BinarySumNode::dims
void dims(std::map< Key, int > &map) const override
Return dimensions for each argument.
Definition: ExpressionNode.h:688
gtsam::internal::UnaryExpression
Unary Function Expression.
Definition: ExpressionNode.h:231
gtsam::internal::BinarySumNode::expression1_
std::shared_ptr< ExpressionNode< T > > expression1_
Definition: ExpressionNode.h:649
gtsam::internal::TernaryExpression::print
void print(const std::string &indent="") const override
Print.
Definition: ExpressionNode.h:468
gtsam::internal::LeafExpression::print
void print(const std::string &indent="") const override
Print.
Definition: ExpressionNode.h:180
gtsam::internal::upAligned
T upAligned(T value, unsigned requiredAlignment=TraceAlignment)
Definition: ExpressionNode.h:51
gtsam::internal::ScalarMultiplyNode::keys
std::set< Key > keys() const override
Return keys that play in this expression.
Definition: ExpressionNode.h:591
gtsam::internal::BinaryExpression::expression2_
std::shared_ptr< ExpressionNode< A2 > > expression2_
Definition: ExpressionNode.h:340
gtsam::internal::ExpressionNode
Definition: Expression.h:40
gtsam::internal::ConstantExpression::value
T value(const Values &values) const override
Return value.
Definition: ExpressionNode.h:144
gtsam::internal::LeafExpression::value_type
T value_type
Definition: ExpressionNode.h:161
gtsam::internal::ExecutionTrace::reverseAD1
void reverseAD1(const Eigen::MatrixBase< DerivedMatrix > &dTdA, JacobianMap &jacobians) const
Either add to Jacobians (Leaf) or propagate (Function)
Definition: ExecutionTrace.h:174
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
gtsam::internal::LeafExpression::dims
void dims(std::map< Key, int > &map) const override
Return dimensions for each argument.
Definition: ExpressionNode.h:192
gtsam::internal::TernaryExpression::keys
std::set< Key > keys() const override
Return keys that play in this expression.
Definition: ExpressionNode.h:483
gtsam::internal::UnaryExpression::traceExecution
T traceExecution(const Values &values, ExecutionTrace< T > &trace, char *ptr) const override
Construct an execution trace for reverse AD.
Definition: ExpressionNode.h:311
gtsam::internal::ScalarMultiplyNode::Record::startReverseAD4
void startReverseAD4(JacobianMap &jacobians) const
Start the reverse AD process.
Definition: ExpressionNode.h:618
gtsam::internal::BinarySumNode::~BinarySumNode
~BinarySumNode() override
Destructor.
Definition: ExpressionNode.h:665
gtsam::internal::TernaryExpression::Record::trace1
ExecutionTrace< A1 > trace1
Definition: ExpressionNode.h:508
gtsam::internal::ScalarMultiplyNode::Record
Definition: ExpressionNode.h:601
os
ofstream os("timeSchurFactors.csv")
gtsam::internal::LeafExpression::key_
Key key_
The key into values.
Definition: ExpressionNode.h:164
gtsam::internal::BinaryExpression::BinaryExpression
BinaryExpression(Function f, const Expression< A1 > &e1, const Expression< A2 > &e2)
Constructor with a binary function f, and two input arguments.
Definition: ExpressionNode.h:344
gtsam::IsVectorSpace
Vector Space concept.
Definition: VectorSpace.h:470
gtsam::internal::UnaryExpression::~UnaryExpression
~UnaryExpression() override
Destructor.
Definition: ExpressionNode.h:248
gtsam::internal::ScalarMultiplyNode::value
T value(const Values &values) const override
Return value.
Definition: ExpressionNode.h:586
gtsam::internal::TernaryExpression::Record::trace2
ExecutionTrace< A2 > trace2
Definition: ExpressionNode.h:509
ExecutionTrace.h
Execution trace for expressions.
gtsam::internal::BinaryExpression::function_
Function function_
Definition: ExpressionNode.h:341
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
name
static char name[]
Definition: rgamma.c:72
gtsam::internal::BinaryExpression::traceExecution
T traceExecution(const Values &values, ExecutionTrace< T > &trace, char *ptr) const override
Construct an execution trace for reverse AD, see UnaryExpression for explanation.
Definition: ExpressionNode.h:430
gtsam::Expression
Definition: Expression.h:47
gtsam::internal::TernaryExpression::~TernaryExpression
~TernaryExpression() override
Destructor.
Definition: ExpressionNode.h:464
gtsam::internal::UnaryExpression::keys
std::set< Key > keys() const override
Return keys that play in this expression.
Definition: ExpressionNode.h:263
gtsam::internal::ConstantExpression::print
void print(const std::string &indent="") const override
Print.
Definition: ExpressionNode.h:139
gtsam::internal::TernaryExpression::Record::dTdA1
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Jacobian< T, A1 >::type dTdA1
Definition: ExpressionNode.h:504
gtsam::internal::BinarySumNode::BinarySumNode
BinarySumNode()
Definition: ExpressionNode.h:653
gtsam::internal::TernaryExpression::expression2_
std::shared_ptr< ExpressionNode< A2 > > expression2_
Definition: ExpressionNode.h:446
A
Definition: test_numpy_dtypes.cpp:298
gtsam::internal::TernaryExpression::dims
void dims(std::map< Key, int > &map) const override
Return dimensions for each argument.
Definition: ExpressionNode.h:493
gtsam::internal::TernaryExpression::Record::Record
Record(const Values &values, const ExpressionNode< A1 > &expression1, const ExpressionNode< A2 > &expression2, const ExpressionNode< A3 > &expression3, char *ptr)
Construct record by calling 3 argument expressions.
Definition: ExpressionNode.h:517
gtsam::internal::LeafExpression::LeafExpression
LeafExpression(Key key)
Constructor with a single key.
Definition: ExpressionNode.h:167
gtsam::internal::BinaryExpression::Record::startReverseAD4
void startReverseAD4(JacobianMap &jacobians) const
Start the reverse AD process, see comments in UnaryExpression.
Definition: ExpressionNode.h:416
gtsam::internal::BinarySumNode::Record::reverseAD4
void reverseAD4(const MatrixType &dFdT, JacobianMap &jacobians) const
If we are not the root, we simply pass on the adjoint matrix dFdT to all terms.
Definition: ExpressionNode.h:715
gtsam::internal::UnaryExpression::Record::Record
Record(const Values &values, const ExpressionNode< A1 > &expression1, char *ptr)
Construct record by calling argument expression.
Definition: ExpressionNode.h:280
gtsam::internal::PrintJacobianAndTrace
static void PrintJacobianAndTrace(const std::string &indent, const typename Jacobian< T, A >::type &dTdA, const ExecutionTrace< A > trace)
Definition: ExpressionNode.h:219
gtsam::internal::ScalarMultiplyNode
Expression for scalar multiplication.
Definition: ExpressionNode.h:563
gtsam::internal::TernaryExpression::TernaryExpression
TernaryExpression(Function f, const Expression< A1 > &e1, const Expression< A2 > &e2, const Expression< A3 > &e3)
Constructor with a ternary function f, and two input arguments.
Definition: ExpressionNode.h:451
gtsam::internal::ConstantExpression::~ConstantExpression
~ConstantExpression() override
Destructor.
Definition: ExpressionNode.h:135
gtsam::internal::CallRecordImplementor
Definition: CallRecord.h:140
gtsam::internal::JacobianMap
Definition: JacobianMap.h:32
A2
static const double A2[]
Definition: expn.h:7
gtsam::internal::TernaryExpression
Ternary Expression.
Definition: ExpressionNode.h:442
gtsam::internal::BinarySumNode::value
T value(const Values &values) const override
Return value.
Definition: ExpressionNode.h:675
gtsam::internal::BinarySumNode
Binary Sum Expression.
Definition: ExpressionNode.h:647
gtsam::internal::TernaryExpression::Record
Definition: ExpressionNode.h:500
gtsam::internal::TernaryExpression::Record::dTdA3
Jacobian< T, A3 >::type dTdA3
Definition: ExpressionNode.h:506
gtsam::internal::TernaryExpression::Record::dTdA2
Jacobian< T, A2 >::type dTdA2
Definition: ExpressionNode.h:505
gtsam::internal::ScalarMultiplyNode::Record::scalar_dTdA
double scalar_dTdA
Definition: ExpressionNode.h:605
Eigen::Triplet< double >
gtsam::internal::UnaryExpression::Record
Definition: ExpressionNode.h:273
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Definition: Memory.h:841
gtsam::internal::ExecutionTrace::print
void print(const std::string &indent="") const
Print.
Definition: ExecutionTrace.h:132
gtsam::internal::ScalarMultiplyNode::scalar_
double scalar_
Definition: ExpressionNode.h:567
gtsam::internal::BinaryExpression::expression1_
std::shared_ptr< ExpressionNode< A1 > > expression1_
Definition: ExpressionNode.h:339
gtsam::internal::TernaryExpression::Record::value1
A1 value1
Definition: ExpressionNode.h:512
gtsam::internal::BinaryExpression::Record::print
void print(const std::string &indent) const
Print to std::cout.
Definition: ExpressionNode.h:408
gtsam::internal::UnaryExpression::Record::startReverseAD4
void startReverseAD4(JacobianMap &jacobians) const
Start the reverse AD process.
Definition: ExpressionNode.h:291
key
const gtsam::Symbol key('X', 0)
gtsam::internal::BinaryExpression::Record::trace2
ExecutionTrace< A2 > trace2
Definition: ExpressionNode.h:395
gtsam::internal::BinarySumNode::print
void print(const std::string &indent="") const override
Print.
Definition: ExpressionNode.h:668
gtsam::internal::ExpressionNode::print
virtual void print(const std::string &indent="") const =0
Print.
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
gtsam::internal::BinaryExpression::Record
Definition: ExpressionNode.h:389
gtsam::internal::ScalarMultiplyNode::Record::reverseAD4
void reverseAD4(const MatrixType &dFdT, JacobianMap &jacobians) const
Given df/dT, multiply in dT/dA and continue reverse AD process.
Definition: ExpressionNode.h:624
gtsam::internal::BinaryExpression::Record::reverseAD4
void reverseAD4(const MatrixType &dFdT, JacobianMap &jacobians) const
Given df/dT, multiply in dT/dA and continue reverse AD process.
Definition: ExpressionNode.h:423
gtsam::internal::ConstantExpression::traceExecution
T traceExecution(const Values &values, ExecutionTrace< T > &trace, char *traceStorage) const override
Construct an execution trace for reverse AD.
Definition: ExpressionNode.h:149
gtsam
traits
Definition: SFMdata.h:40
gtsam::internal::LeafExpression::value
T value(const Values &values) const override
Return value.
Definition: ExpressionNode.h:197
gtsam::internal::ExpressionNode::value
virtual T value(const Values &values) const =0
Return value.
gtsam::internal::BinarySumNode::BinarySumNode
BinarySumNode(const Expression< T > &e1, const Expression< T > &e2)
Constructor with a binary function f, and two input arguments.
Definition: ExpressionNode.h:658
gtsam::traits
Definition: Group.h:36
gtsam::internal::TernaryExpression::Record::startReverseAD4
void startReverseAD4(JacobianMap &jacobians) const
Start the reverse AD process, see comments in Base.
Definition: ExpressionNode.h:534
gtsam::internal::TernaryExpression::Record::trace3
ExecutionTrace< A3 > trace3
Definition: ExpressionNode.h:510
gtsam::internal::ScalarMultiplyNode::Record::trace
ExecutionTrace< T > trace
Definition: ExpressionNode.h:606
gtsam::internal::UnaryExpression::function_
Function function_
Definition: ExpressionNode.h:235
gtsam::Values
Definition: Values.h:65
gtsam::internal::TernaryExpression::Record::value2
A2 value2
Definition: ExpressionNode.h:513
gtsam::demangle
std::string demangle(const char *name)
Pretty print Value type name.
Definition: types.cpp:37
gtsam::Expression::traceSize
size_t traceSize() const
Return size needed for memory buffer in traceExecution.
Definition: Expression-inl.h:161
gtsam::internal::TernaryExpression::value
T value(const Values &values) const override
Return value.
Definition: ExpressionNode.h:476
gtsam::internal::BinaryExpression
Binary Expression.
Definition: ExpressionNode.h:336
gtsam::internal::ExpressionNode::keys
virtual std::set< Key > keys() const
Return keys that play in this expression as a set.
Definition: ExpressionNode.h:95
gtsam::internal::TernaryExpression::Record::print
void print(const std::string &indent) const
Print to std::cout.
Definition: ExpressionNode.h:525
A1
static const double A1[]
Definition: expn.h:6
gtsam::internal::ExecutionTrace::setFunction
void setFunction(CallRecord< Dim > *record)
Take ownership of pointer to a Function Record.
Definition: ExecutionTrace.h:126
gtsam::internal::UnaryExpression::Function
Expression< T >::template UnaryFunction< A1 >::type Function
Definition: ExpressionNode.h:233
gtsam::internal::BinarySumNode::expression2_
std::shared_ptr< ExpressionNode< T > > expression2_
Definition: ExpressionNode.h:650
gtsam::internal::LeafExpression
Leaf Expression, if no chart is given, assume default chart and value_type is just the plain value.
Definition: ExpressionNode.h:160
gtsam::internal::ScalarMultiplyNode::traceExecution
T traceExecution(const Values &values, ExecutionTrace< T > &trace, char *ptr) const override
Construct an execution trace for reverse AD.
Definition: ExpressionNode.h:630
gtsam::internal::TernaryExpression::expression1_
std::shared_ptr< ExpressionNode< A1 > > expression1_
Definition: ExpressionNode.h:445
gtsam::internal::BinaryExpression::Record::value2
A2 value2
Definition: ExpressionNode.h:399
gtsam::internal::LeafExpression::~LeafExpression
~LeafExpression() override
Destructor.
Definition: ExpressionNode.h:176
gtsam::internal::ScalarMultiplyNode::~ScalarMultiplyNode
~ScalarMultiplyNode() override
Destructor.
Definition: ExpressionNode.h:577
gtsam::internal::UnaryExpression::Record::value1
A1 value1
Definition: ExpressionNode.h:277
gtsam::internal::BinaryExpression::print
void print(const std::string &indent="") const override
Print.
Definition: ExpressionNode.h:361
gtsam::internal::ConstantExpression::ConstantExpression
ConstantExpression(const T &value)
Constructor with a value, yielding a constant.
Definition: ExpressionNode.h:126
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
gtsam::internal::ScalarMultiplyNode::Record::Dim
static const int Dim
Definition: ExpressionNode.h:602
gtsam::internal::upAlign
T & upAlign(T &value, unsigned requiredAlignment=TraceAlignment)
Definition: ExpressionNode.h:38
gtsam::internal::ScalarMultiplyNode::Record::JacobianTT
Eigen::Matrix< double, Dim, Dim > JacobianTT
Definition: ExpressionNode.h:603
internal
Definition: BandTriangularSolver.h:13
gtsam::internal::BinaryExpression::Function
Expression< T >::template BinaryFunction< A1, A2 >::type Function
Definition: ExpressionNode.h:338
gtsam::internal::BinarySumNode::NodeT
ExpressionNode< T > NodeT
Definition: ExpressionNode.h:648
gtsam::internal::Jacobian
meta-function to generate fixed-size JacobianTA type
Definition: ExpressionNode.h:213
gtsam::internal::UnaryExpression::Record::dTdA1
Jacobian< T, A1 >::type dTdA1
Definition: ExpressionNode.h:275
gtsam::internal::LeafExpression::traceExecution
T traceExecution(const Values &values, ExecutionTrace< T > &trace, char *traceStorage) const override
Construct an execution trace for reverse AD.
Definition: ExpressionNode.h:202
gtsam::internal::BinaryExpression::value
T value(const Values &values) const override
Return value.
Definition: ExpressionNode.h:368
gtsam::internal::ScalarMultiplyNode::Record::print
void print(const std::string &indent) const
Print to std::cout.
Definition: ExpressionNode.h:609
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::internal::BinaryExpression::dims
void dims(std::map< Key, int > &map) const override
Return dimensions for each argument.
Definition: ExpressionNode.h:383
gtsam::internal::ExpressionNode::traceSize_
size_t traceSize_
Definition: ExpressionNode.h:69
gtsam::internal::TernaryExpression::Function
Expression< T >::template TernaryFunction< A1, A2, A3 >::type Function
Definition: ExpressionNode.h:444
gtsam::internal::ScalarMultiplyNode::ScalarMultiplyNode
ScalarMultiplyNode(double s, const Expression< T > &e)
Constructor with a unary function f, and input argument e1.
Definition: ExpressionNode.h:572
gtsam::internal::BinaryExpression::Record::Record
Record(const Values &values, const ExpressionNode< A1 > &expression1, const ExpressionNode< A2 > &expression2, char *ptr)
Construct record by calling argument expressions.
Definition: ExpressionNode.h:402
gtsam::internal::TernaryExpression::traceExecution
T traceExecution(const Values &values, ExecutionTrace< T > &trace, char *ptr) const override
Construct an execution trace for reverse AD, see UnaryExpression for explanation.
Definition: ExpressionNode.h:550
gtsam::internal::BinarySumNode::keys
std::set< Key > keys() const override
Return keys that play in this expression.
Definition: ExpressionNode.h:680
GTSAM_MAKE_ALIGNED_OPERATOR_NEW
#define GTSAM_MAKE_ALIGNED_OPERATOR_NEW
Definition: types.h:279
test_callbacks.value
value
Definition: test_callbacks.py:160
gtsam::internal::UnaryExpression::Record::reverseAD4
void reverseAD4(const MatrixType &dFdT, JacobianMap &jacobians) const
Given df/dT, multiply in dT/dA and continue reverse AD process.
Definition: ExpressionNode.h:305
gtsam::internal::BinarySumNode::Record::trace2
ExecutionTrace< T > trace2
Definition: ExpressionNode.h:696
gtsam::internal::BinaryExpression::~BinaryExpression
~BinaryExpression() override
Destructor.
Definition: ExpressionNode.h:357
gtsam::internal::ConstantExpression::constant_
T constant_
The constant value.
Definition: ExpressionNode.h:123
gtsam::internal::BinarySumNode::Record::print
void print(const std::string &indent) const
Print to std::cout.
Definition: ExpressionNode.h:699
gtsam::internal::UnaryExpression::value
T value(const Values &values) const override
Return value.
Definition: ExpressionNode.h:258
gtsam::internal::ScalarMultiplyNode::GTSAM_CONCEPT_ASSERT
GTSAM_CONCEPT_ASSERT(IsVectorSpace< T >)
gtsam::internal::ExpressionNode::ExpressionNode
ExpressionNode(size_t traceSize=0)
Constructor, traceSize is size of the execution trace of expression rooted here.
Definition: ExpressionNode.h:72
gtsam::internal::BinarySumNode::traceExecution
T traceExecution(const Values &values, ExecutionTrace< T > &trace, char *ptr) const override
Construct an execution trace for reverse AD.
Definition: ExpressionNode.h:723
gtsam::internal::UnaryExpression::Record::print
void print(const std::string &indent) const
Print to std::cout.
Definition: ExpressionNode.h:284
Values.h
A non-templated config holding any types of Manifold-group elements.
gtsam::internal::ScalarMultiplyNode::dims
void dims(std::map< Key, int > &map) const override
Return dimensions for each argument.
Definition: ExpressionNode.h:596
gtsam::internal::UnaryExpression::expression1_
std::shared_ptr< ExpressionNode< A1 > > expression1_
Definition: ExpressionNode.h:234
gtsam::internal::BinaryExpression::Record::value1
A1 value1
Definition: ExpressionNode.h:398
gtsam::internal::ScalarMultiplyNode::print
void print(const std::string &indent="") const override
Print.
Definition: ExpressionNode.h:580
gtsam::internal::TernaryExpression::function_
Function function_
Definition: ExpressionNode.h:448
gtsam::internal::TernaryExpression::expression3_
std::shared_ptr< ExpressionNode< A3 > > expression3_
Definition: ExpressionNode.h:447
CallRecord.h
Internals for Expression.h, not for general consumption.


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:32