forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Try reproducing with AutoDiffXd
- Loading branch information
1 parent
3c424d0
commit bd45494
Showing
4 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include "drake/common/autodiff.h" | ||
#include "drake/math/autodiff_gradient.h" | ||
#include "drake/common/eigen_types.h" | ||
|
||
namespace drake { | ||
namespace test { | ||
namespace { | ||
|
||
GTEST_TEST(AutoDiffXdLdltTest, derivatives) { | ||
using Eigen::VectorXd; | ||
using std::cout; | ||
using std::endl; | ||
|
||
constexpr int kDerivatives = 5; | ||
constexpr int kNumDofs = 2; | ||
VectorX<AutoDiffXd> b(kNumDofs); | ||
b << 0, -6.00689e-17; | ||
|
||
VectorXd db0(kDerivatives); | ||
db0 << 0, 0, 11, -0.5, 0.1; | ||
VectorXd db1(kDerivatives); | ||
db1 << 0, 0.4905, -0.5, 0.25, 0; | ||
b[0].derivatives() = db0; | ||
b[1].derivatives() = db1; | ||
|
||
cout << "db: " << endl; | ||
cout << math::ExtractGradient(b) << endl; | ||
cout << endl; | ||
|
||
Matrix2<AutoDiffXd> A; | ||
A << 11, -0.5, -0.5, 0.25; | ||
|
||
VectorXd dA10(kDerivatives); | ||
dA10 << 0, -6.12323e-17, 0, 0, 0; | ||
VectorXd dA01 = dA10; | ||
A(0, 0).derivatives() = VectorXd::Zero(5); | ||
A(1, 1).derivatives() = VectorXd::Zero(5); | ||
A(0, 1).derivatives() = dA01; | ||
A(1, 0).derivatives() = dA10; | ||
Vector2<AutoDiffXd> x = A.ldlt().solve(b); | ||
Vector2<AutoDiffXd> Ax = A * x; | ||
cout << "d(A*x): " << endl; | ||
cout << math::ExtractGradient(A* x) << endl; | ||
cout << endl; | ||
|
||
cout << "dx: " << endl; | ||
cout << math::ExtractGradient(x) << endl; | ||
cout << endl; | ||
EXPECT_TRUE(false); | ||
} | ||
|
||
} // namespace | ||
} // namespace test | ||
} // namespace drake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters