Drake
Drake C++ Documentation
Loading...
Searching...
No Matches
autodiff_gradient.h File Reference

Detailed Description

Utilities that relate simultaneously to both autodiff matrices and gradient matrices.

#include <algorithm>
#include <optional>
#include <Eigen/Dense>
#include <fmt/format.h>
#include "drake/common/drake_assert.h"
#include "drake/common/unused.h"
#include "drake/math/autodiff.h"
#include "drake/math/gradient.h"
Include dependency graph for autodiff_gradient.h:
This graph shows which files directly or indirectly include this file:

Namespaces

namespace  drake
namespace  drake::math

Functions

template<typename Derived>
void ExtractGradient (const Eigen::MatrixBase< Derived > &auto_diff_matrix, std::optional< int > num_derivatives, Eigen::Matrix< typename Derived::Scalar::Scalar, Derived::SizeAtCompileTime, Eigen::Dynamic > *gradient)
 Extracts the derivatives() portion from an AutoDiffScalar matrix into a pre-existing matrix (resizing if necessary).
template<typename Derived>
Eigen::Matrix< typename Derived::Scalar::Scalar, Derived::SizeAtCompileTime, Eigen::Dynamic > ExtractGradient (const Eigen::MatrixBase< Derived > &auto_diff_matrix, std::optional< int > num_derivatives={})
 Returns the derivatives() portion from a matrix of AutoDiffScalar entries.
template<typename DerivedValue, typename DerivedGradient, typename DerivedAutoDiff>
void InitializeAutoDiff (const Eigen::MatrixBase< DerivedValue > &value, const Eigen::MatrixBase< DerivedGradient > &gradient, Eigen::MatrixBase< DerivedAutoDiff > *auto_diff_matrix)
 Initializes an AutoDiff matrix given a matrix of values and a gradient matrix.
template<typename DerivedValue, typename DerivedGradient>
AutoDiffMatrixType< DerivedValue, DerivedGradient::ColsAtCompileTime > InitializeAutoDiff (const Eigen::MatrixBase< DerivedValue > &value, const Eigen::MatrixBase< DerivedGradient > &gradient)
 Returns an AutoDiff matrix given a matrix of values and a gradient matrix.
template<typename Derived>
decltype(auto) DiscardZeroGradient (const Eigen::MatrixBase< Derived > &auto_diff_matrix, double precision=Eigen::NumTraits< double >::dummy_precision())
 B = DiscardZeroGradient(A, precision) enables casting from a matrix of AutoDiffScalars to AutoDiffScalar::Scalar type, but first checking that the gradient matrix is empty or zero.
template<typename Derived>
std::enable_if<!std::is_same_v< typenameDerived::Scalar, double >, int >::type GetDerivativeSize (const Eigen::MatrixBase< Derived > &A)
 Given a matrix of AutoDiffScalars, returns the size of the derivatives.
bool AreAutoDiffVecXdEqual (const Eigen::Ref< const VectorX< AutoDiffXd > > &a, const Eigen::Ref< const VectorX< AutoDiffXd > > &b)
 Determines if a and b are equal.