Drake
Drake C++ Documentation
drake::solvers::test Namespace Reference

Functions

void CheckConstraintEvalNonsymbolic (const Constraint &constraint, const Eigen::Ref< const AutoDiffVecXd > &x_autodiff, double tol)
 Compare the result between Eval<double>() and Eval<AutoDiffXd>(). More...
 
void CheckGradientSparsityPattern (const EvaluatorBase &evaluator, const AutoDiffVecXd &x_ad, bool strict=false)
 Checks the gradient sparsity pattern, by evaluating evaluator at x_ad, and compare whether the gradient matches with evaluator.gradient_sparsity_pattern(). More...
 

Function Documentation

◆ CheckConstraintEvalNonsymbolic()

void drake::solvers::test::CheckConstraintEvalNonsymbolic ( const Constraint constraint,
const Eigen::Ref< const AutoDiffVecXd > &  x_autodiff,
double  tol 
)

Compare the result between Eval<double>() and Eval<AutoDiffXd>().

Also compare the gradient in Eval<AutoDiffXd>() with a finite difference approximation.

Parameters
constraintThe constraint object to test.
x_autodiffThe point at which the Eval() methods are tested.
tolTolerance on the comparison of the results from Eval<double>() and Eval<AutoDiffXd>(). The tolerance on the comparison between the autodiff gradient and the finite difference approximation is sqrt(tolerance) to account for approximation error.

◆ CheckGradientSparsityPattern()

void drake::solvers::test::CheckGradientSparsityPattern ( const EvaluatorBase evaluator,
const AutoDiffVecXd x_ad,
bool  strict = false 
)

Checks the gradient sparsity pattern, by evaluating evaluator at x_ad, and compare whether the gradient matches with evaluator.gradient_sparsity_pattern().

Notice that evaluator.gradients_sparsity_pattern() contains all the (row, col) indices where the gradient might be non-zero, so evaluator.gradients_sparsity_pattern() is a superset of all the non-zero gradient indices. If strict=true, then we check if evaluator.gradients_sparsity_pattern() is exactly the set of all the non-zero gradient_indices.