Drake
Drake C++ Documentation
Loading...
Searching...
No Matches
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.

However, by using a careful representation trick (maintaining a separate scale factor) it runs faster than Eigen::AutoDiffScalar<Eigen::VectorXd>.

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

Public Types

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

Public Member Functions

 AutoDiff ()=default
 Constructs zero.
 AutoDiff (double value)
 Constructs a value with empty derivatives.
 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 (double value, const Eigen::Ref< const Eigen::VectorXd > &derivatives)
 Constructs a value with the given derivatives.
AutoDiffoperator= (double value)
 Assigns a value and clears the derivatives.
 ~AutoDiff ()=default
double value () const
 Returns the value part of this AutoDiff (readonly).
doublevalue ()
 (Advanced) Returns the value part of this AutoDiff (mutable).
DerivativesConstXpr derivatives () const
 Returns a view of the derivatives part of this AutoDiff (readonly).
DerivativesMutableXpr derivatives ()
 (Advanced) Returns a mutable view of the derivatives part of this AutoDiff.
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.
internal::Partials & partials ()
 (Internal use only) Users should call derivatives() instead.

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]

DerivativesMutableXpr 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.

Note
This function name is kept for compatibility with Eigen::AutoDiffScalar but it does NOT run in constant-time even though its name is lowercase. Calling this function often needs to finalize the derivatives prior to returning the reference, so is O(N) in the size of the derivatives.

◆ derivatives() [2/2]

DerivativesConstXpr derivatives ( ) const

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

◆ 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]

internal::Partials & partials ( )

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

◆ partials() [2/2]

const internal::Partials & partials ( ) const

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

◆ value() [1/2]

double & value ( )

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

Operations on this value will NOT alter the derivatives.

◆ value() [2/2]

double value ( ) const

Returns the value part of this AutoDiff (readonly).


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