36template<
typename T_Tape>
43 static Tape globalTape;
64#define OPERATOR(OP, rhs) \
65 ActiveType& OP(ActiveType const& value) { \
106template<
typename Tape>
107Tape ActiveType<Tape>::globalTape;
109#define BINARY_OPERATOR(OP, VAL, JAC1, JAC2) \
110template<typename Tape> \
111ActiveType<Tape> OP(ActiveType<Tape> const& arg1, ActiveType<Tape> const& arg2) { \
112 using Real = typename Tape::Real; \
114 Real val1 = arg1.value(); \
115 Real val2 = arg2.value(); \
116 ActiveType<Tape> lhs; \
117 ActiveType<Tape>::getTape().store(lhs, VAL, arg1, JAC1, arg2, JAC2); \
122template<typename Tape> \
123ActiveType<Tape> OP(typename Tape::Real const& val1, ActiveType<Tape> const& arg2) { \
124 using Real = typename Tape::Real; \
126 Real val2 = arg2.value(); \
127 ActiveType<Tape> lhs; \
128 ActiveType<Tape>::getTape().store(lhs, VAL, arg2, JAC2); \
133template<typename Tape> \
134ActiveType<Tape> OP(ActiveType<Tape> const& arg1, typename Tape::Real const& val2) { \
135 using Real = typename Tape::Real; \
137 Real val1 = arg1.value(); \
138 ActiveType<Tape> lhs; \
139 ActiveType<Tape>::getTape().store(lhs, VAL, arg1, JAC1); \
153BINARY_OPERATOR(operator/, val1 / val2, 1.0 / val2, -val1 / val2 / val2)
154BINARY_OPERATOR(atan2, atan2(val1, val2), val2 / (val1 * val1 + val2 * val2), -val1 / (val1 * val1 + val2 * val2))
155BINARY_OPERATOR(hypot, hypot(val1, val2), val1 / hypot(val1, val2), val2 / hypot(val1, val2))
156BINARY_OPERATOR(max, max(val1, val2), val1 > val2 ? 1.0 : 0.0, val1 > val2 ? 0.0 : 1.0)
157BINARY_OPERATOR(min, min(val1, val2), val1 < val2 ? 1.0 : 0.0, val1 < val2 ? 0.0 : 1.0)
159#undef BINARY_OPERATOR
161#define UNARY_OPERATOR(OP, VAL, JAC) \
162template<typename Tape> \
163ActiveType<Tape> OP(ActiveType<Tape> const& arg) { \
164 using Real = typename Tape::Real; \
166 Real val = arg.value(); \
167 ActiveType<Tape> lhs; \
168 ActiveType<Tape>::getTape().store(lhs, VAL, arg, JAC); \
210#define CONDITION_OPERATOR(OP) \
211template<typename Tape> \
212bool operator OP(ActiveType<Tape> const& arg1, ActiveType<Tape> const& arg2) { \
213 return arg1.value() OP arg2.value(); \
225#undef CONDITION_OPERATOR
227#define CONDITION_OPERATOR(OP) \
228template<typename Tape> \
229bool operator OP(ActiveType<Tape> const& arg) { \
230 return OP arg.value(); \
235template<
typename Tape>
242#undef CONDITION_OPERATOR
244template<
typename T_Real>
259 void pushJacobian(
int const&
id,
Real const& jacobi) {
264 void pushStmt(
OpType const& opType) {
268 void assignValue(ActiveType<Tape>& lhs,
Real const& lhsValue) {
271 lhs.value() = lhsValue;
275 void resizeAdjointVector() {
286 assignValue(lhs, lhsValue);
293 assignValue(lhs, lhsValue);
303 assignValue(lhs, lhsValue);
308 resizeAdjointVector();
312 int stmtPos = (size_t)
opVector.size();
322 for(
OpType i = 0; i < nArgs; i += 1) {
342 store(value, value.value());
346 store(value, value.value(), value,
Real(1.0));
351 resizeAdjointVector();
void store(ActiveType< Tape > &lhs, Real const &lhsValue, ActiveType< Tape > const &rhs1, Real const &rhs1Jac, ActiveType< Tape > const &rhs2, Real const &rhs2Jac)