Drake
Drake C++ Documentation
AutoDiff Class Reference

Detailed Description

A scalar type that performs automatic differentiation, similar to Eigen::AutoDiffScalar<Eigen::VectorXd>.

Unlike Eigen::AutoDiffScalar, Drake's AutoDiff is not templated; it only supports dynamically-sized derivatives using floating-point doubles.

At the moment, the features of this class are similar to Eigen::AutoDiffScalar, but in the future Drake will further customize this class to optimize its runtime performance and better integrate it with our optimization tools.

#include <drake/common/ad/auto_diff.h>

Public Types

using DerType = Eigen::VectorXd
 Compatibility alias to mimic Eigen::AutoDiffScalar. More...
 
using Scalar = double
 Compatibility alias to mimic Eigen::AutoDiffScalar. More...
 

Public Member Functions

 AutoDiff ()=default
 Constructs zero. More...
 
 AutoDiff (double value)
 Constructs a value with empty derivatives. More...
 
 AutoDiff (double value, Eigen::Index size, Eigen::Index offset)
 Constructs a value with a single partial derivative of 1.0 at the given offset in a vector of size otherwise-zero derivatives. More...
 
 AutoDiff (double value, const Eigen::Ref< const Eigen::VectorXd > &derivatives)
 Constructs a value with the given derivatives. More...
 
AutoDiffoperator= (double value)
 Assigns a value and clears the derivatives. More...
 
 ~AutoDiff ()=default
 
double value () const
 Returns the value part of this AutoDiff (readonly). More...
 
doublevalue ()
 (Advanced) Returns the value part of this AutoDiff (mutable). More...
 
const Eigen::VectorXd & derivatives () const
 Returns a view of the derivatives part of this AutoDiff (readonly). More...
 
Eigen::VectorXd & derivatives ()
 (Advanced) Returns a mutable view of the derivatives part of this AutoDiff. More...
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 AutoDiff (const AutoDiff &)=default
 
AutoDiffoperator= (const AutoDiff &)=default
 
 AutoDiff (AutoDiff &&)=default
 
AutoDiffoperator= (AutoDiff &&)=default
 
Internal use only
const internal::Partials & partials () const
 (Internal use only) Users should call derivatives() instead. More...
 
internal::Partials & partials ()
 (Internal use only) Users should call derivatives() instead. More...
 

Member Typedef Documentation

◆ DerType

using DerType = Eigen::VectorXd

Compatibility alias to mimic Eigen::AutoDiffScalar.

◆ Scalar

using Scalar = double

Compatibility alias to mimic Eigen::AutoDiffScalar.

Constructor & Destructor Documentation

◆ AutoDiff() [1/6]

AutoDiff ( const AutoDiff )
default

◆ AutoDiff() [2/6]

AutoDiff ( AutoDiff &&  )
default

◆ AutoDiff() [3/6]

AutoDiff ( )
default

Constructs zero.

◆ AutoDiff() [4/6]

AutoDiff ( double  value)

Constructs a value with empty derivatives.

◆ AutoDiff() [5/6]

AutoDiff ( double  value,
Eigen::Index  size,
Eigen::Index  offset 
)

Constructs a value with a single partial derivative of 1.0 at the given offset in a vector of size otherwise-zero derivatives.

◆ AutoDiff() [6/6]

AutoDiff ( double  value,
const Eigen::Ref< const Eigen::VectorXd > &  derivatives 
)

Constructs a value with the given derivatives.

◆ ~AutoDiff()

~AutoDiff ( )
default

Member Function Documentation

◆ derivatives() [1/2]

const Eigen::VectorXd& derivatives ( ) const

Returns a view of the derivatives part of this AutoDiff (readonly).

Do not presume any specific C++ type for the the return value. It will act like an Eigen column-vector expression (e.g., Eigen::Block<const VectorXd>), but we reserve the right to change the return type for efficiency down the road.

◆ derivatives() [2/2]

Eigen::VectorXd& derivatives ( )

(Advanced) Returns a mutable view of the derivatives part of this AutoDiff.

Instead of mutating the derivatives after construction, it's generally preferable to set them directly in the constructor if possible.

Do not presume any specific C++ type for the the return value. It will act like a mutable Eigen column-vector expression (e.g., Eigen::Block<VectorXd>) that also allows for assignment and resizing, but we reserve the right to change the return type for efficiency down the road.

◆ operator=() [1/3]

AutoDiff& operator= ( AutoDiff &&  )
default

◆ operator=() [2/3]

AutoDiff& operator= ( const AutoDiff )
default

◆ operator=() [3/3]

AutoDiff& operator= ( double  value)

Assigns a value and clears the derivatives.

◆ partials() [1/2]

const internal::Partials& partials ( ) const

(Internal use only) Users should call derivatives() instead.

◆ partials() [2/2]

internal::Partials& partials ( )

(Internal use only) Users should call derivatives() instead.

◆ value() [1/2]

double value ( ) const

Returns the value part of this AutoDiff (readonly).

◆ value() [2/2]

double& value ( )

(Advanced) Returns the value part of this AutoDiff (mutable).

Operations on this value will NOT alter the derivatives.


The documentation for this class was generated from the following file: