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.
[ad] Add support for arithmetic operations (RobotLocomotion#17622)
- Loading branch information
1 parent
dc7af96
commit d5ce331
Showing
34 changed files
with
502 additions
and
36 deletions.
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
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
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,33 @@ | ||
#include "drake/common/ad/auto_diff.h" | ||
#include "drake/common/ad/test/standard_operations_test.h" | ||
|
||
namespace drake { | ||
namespace test { | ||
namespace { | ||
|
||
TEST_F(StandardOperationsTest, Addition) { | ||
CHECK_BINARY_OP(+, x, y, 1.0); | ||
CHECK_BINARY_OP(+, x, y, -1.0); | ||
CHECK_BINARY_OP(+, y, x, 1.0); | ||
CHECK_BINARY_OP(+, y, x, -1.0); | ||
} | ||
|
||
namespace { | ||
|
||
// We need to wrap the operator under test, to give it a name. | ||
// Eigen doesn't provide unary operator+, so we'll no-op instead. | ||
AutoDiffDut unary_add(const AutoDiffDut& x) { return +x; } | ||
AutoDiff3 unary_add(const AutoDiff3& x) { return x; } | ||
|
||
} // namespace | ||
|
||
TEST_F(StandardOperationsTest, UnaryAddition) { | ||
CHECK_UNARY_FUNCTION(unary_add, x, y, 1.0); | ||
CHECK_UNARY_FUNCTION(unary_add, x, y, -1.0); | ||
CHECK_UNARY_FUNCTION(unary_add, y, x, 1.0); | ||
CHECK_UNARY_FUNCTION(unary_add, y, x, -1.0); | ||
} | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <sstream> | ||
|
||
#include "drake/common/ad/auto_diff.h" | ||
#include "drake/common/ad/test/standard_operations_test.h" | ||
|
||
namespace drake { | ||
namespace test { | ||
namespace { | ||
|
||
TEST_F(StandardOperationsTest, Postdecrement) { | ||
AutoDiffDut x{0.25, 3, 0}; | ||
EXPECT_EQ((x--).value(), 0.25); | ||
EXPECT_EQ(x.value(), -0.75); | ||
EXPECT_EQ(x.derivatives()[0], 1.0); | ||
} | ||
|
||
TEST_F(StandardOperationsTest, Predecrement) { | ||
AutoDiffDut x{0.25, 3, 0}; | ||
EXPECT_EQ((--x).value(), -0.75); | ||
EXPECT_EQ(x.value(), -0.75); | ||
EXPECT_EQ(x.derivatives()[0], 1.0); | ||
} | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "drake/common/ad/auto_diff.h" | ||
#include "drake/common/ad/test/standard_operations_test.h" | ||
|
||
namespace drake { | ||
namespace test { | ||
namespace { | ||
|
||
TEST_F(StandardOperationsTest, Division) { | ||
CHECK_BINARY_OP(/, x, y, 1.0); | ||
CHECK_BINARY_OP(/, x, y, -1.0); | ||
CHECK_BINARY_OP(/, y, x, 1.0); | ||
CHECK_BINARY_OP(/, y, x, -1.0); | ||
} | ||
|
||
} // namespace | ||
} // namespace test | ||
} // namespace drake |
Oops, something went wrong.