21 #include <gtsam/config.h> 31 #include <type_traits> 36 template<
int T>
struct CallRecord;
43 static const unsigned TraceAlignment = 16;
45 static const unsigned TraceAlignment = 32;
48 typedef std::aligned_storage<1, TraceAlignment>::type ExecutionTraceStorage;
50 template<
bool UseBlock,
typename Derived>
52 static void addToJacobian(
const Eigen::MatrixBase<Derived>& dTdA,
55 jacobians(key).block<Derived::RowsAtCompileTime, Derived::ColsAtCompileTime>(
61 template<
typename Derived>
63 static void addToJacobian(
const Eigen::MatrixBase<Derived>& dTdA,
65 jacobians(key) += dTdA;
70 template<
typename Derived>
74 Derived::RowsAtCompileTime != Eigen::Dynamic
75 && Derived::ColsAtCompileTime != Eigen::Dynamic, Derived>::addToJacobian(
76 dTdA, jacobians, key);
103 typedef Eigen::Matrix<double, Dim, Dim> JacobianTT;
105 Constant, Leaf, Function
128 content.ptr = record;
132 void print(
const std::string& indent =
"")
const {
133 if (kind == Constant) {
134 std::cout << indent <<
"Constant" << std::endl;
135 }
else if (kind == Leaf) {
136 std::cout << indent <<
"Leaf, key = " << content.key << std::endl;
137 }
else if (kind == Function) {
138 content.ptr->print(indent +
" ");
143 template<
class Record>
145 if (kind != Function) {
148 Record* p =
dynamic_cast<Record*
>(content.ptr);
149 return p ? std::optional<Record*>(p) : std::nullopt;
160 static const JacobianTT I = JacobianTT::Identity();
162 }
else if (kind == Function) {
165 content.ptr->startReverseAD2(jacobians);
173 template<
typename DerivedMatrix>
174 void reverseAD1(
const Eigen::MatrixBase<DerivedMatrix> & dTdA,
178 else if (kind == Function)
179 content.ptr->reverseAD2(dTdA, jacobians);
183 if (kind == Function) {
184 content.ptr->~CallRecord<Dim>();
ExecutionTrace< T > type
Define type so we can apply it as a meta-function.
Definition: ExecutionTrace.h:189
ExecutionTrace()
Pointer always starts out as a Constant.
Definition: ExecutionTrace.h:115
JacobianMap for returning derivatives from expressions.
void reverseAD1(const Eigen::MatrixBase< DerivedMatrix > &dTdA, JacobianMap &jacobians) const
Either add to Jacobians (Leaf) or propagate (Function)
Definition: ExecutionTrace.h:174
Definition: JacobianMap.h:32
void handleLeafCase(const Eigen::MatrixBase< Derived > &dTdA, JacobianMap &jacobians, Key key)
Handle Leaf Case: reverse AD ends here, by writing a matrix into Jacobians.
Definition: ExecutionTrace.h:71
void startReverseAD1(JacobianMap &jacobians) const
Definition: ExecutionTrace.h:157
Base class and basic functions for Manifold types.
Definition: chartTesting.h:28
void print(const std::string &indent="") const
Print.
Definition: ExecutionTrace.h:132
void setFunction(CallRecord< Dim > *record)
Take ownership of pointer to a Function Record.
Definition: ExecutionTrace.h:126
void setLeaf(Key key)
Change pointer to a Leaf Record.
Definition: ExecutionTrace.h:120
Definition: Expression.h:39
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
std::optional< Record * > record()
Return record pointer, quite unsafe, used only for testing.
Definition: ExecutionTrace.h:144
Definition: ExecutionTrace.h:51