Drake
autodiffxd_make_coherent.h
Go to the documentation of this file.
1 #pragma once
2
5
6 namespace drake {
7
8 /// Makes the derviatives of the recipient coherent with respect to those of the
9 /// donor variable (see drake/common/autodiffxd.h). If the recipient's
10 /// derivatives are already populated with a vector of the same size as that of
11 /// the donor, variables pass through unchanged. An exception is thrown when
12 /// there are nonempty vectors of different sizes.
13 inline void autodiffxd_make_coherent(const AutoDiffXd& donor,
14  AutoDiffXd* recipient) {
15  DRAKE_ASSERT(recipient != nullptr);
16  if (recipient->derivatives().size() == 0) {
17  recipient->derivatives() =
18  Eigen::VectorXd::Zero(donor.derivatives().size());
19  } else if (recipient->derivatives().size() != donor.derivatives().size()) {
20  throw std::runtime_error("Nonempty recipient derivatives must match the "
21  "size of the donor derivatives.");
22  }
23 }
24
25 inline void autodiffxd_make_coherent(const double&, double*) {}
26
29
30 } // namespace drake
Eigen::AutoDiffScalar< Eigen::VectorXd > AutoDiffXd
An autodiff variable with a dynamic number of partials.
Definition: eigen_autodiff_types.h:22
Definition: automotive_demo.cc:105
void autodiffxd_make_coherent(const AutoDiffXd &donor, AutoDiffXd *recipient)
Makes the derviatives of the recipient coherent with respect to those of the donor variable (see drak...
Definition: autodiffxd_make_coherent.h:13
#define DRAKE_ASSERT(condition)
DRAKE_ASSERT(condition) is similar to the built-in assert(condition) from the C++ system header <cas...
Definition: drake_assert.h:37
Represents a symbolic form of an expression.
Definition: symbolic_expression.h:172
Provides public header files of Drake&#39;s symbolic library.