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 trig and hyperbolic operations (RobotLocomotion#…
- Loading branch information
1 parent
ff2554b
commit 6fe3aba
Showing
14 changed files
with
394 additions
and
7 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
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, Acos) { | ||
CHECK_UNARY_FUNCTION(acos, x, y, 0.1); | ||
CHECK_UNARY_FUNCTION(acos, x, y, -0.1); | ||
CHECK_UNARY_FUNCTION(acos, y, x, 0.1); | ||
CHECK_UNARY_FUNCTION(acos, y, x, -0.1); | ||
} | ||
|
||
} // 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, Asin) { | ||
CHECK_UNARY_FUNCTION(asin, x, y, 0.1); | ||
CHECK_UNARY_FUNCTION(asin, x, y, -0.1); | ||
CHECK_UNARY_FUNCTION(asin, y, x, 0.1); | ||
CHECK_UNARY_FUNCTION(asin, y, x, -0.1); | ||
} | ||
|
||
} // 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,40 @@ | ||
#include "drake/common/ad/auto_diff.h" | ||
#include "drake/common/ad/test/standard_operations_test.h" | ||
|
||
namespace drake { | ||
namespace test { | ||
namespace { | ||
|
||
// Eigen doesn't provide mixed-scalar atan2() overloads, so we need to do it. | ||
// This assumes the standard_operations_test.h is implemented using AutoDiff3. | ||
AutoDiff3 atan2(const AutoDiff3& y, double x) { | ||
return atan2(y, AutoDiff3{x}); | ||
} | ||
AutoDiff3 atan2(double y, const AutoDiff3& x) { | ||
return atan2(AutoDiff3{y}, x); | ||
} | ||
|
||
TEST_F(StandardOperationsTest, Atan2AdsAds) { | ||
CHECK_BINARY_FUNCTION_ADS_ADS(atan2, x, y, 0.1); | ||
CHECK_BINARY_FUNCTION_ADS_ADS(atan2, x, y, -0.1); | ||
CHECK_BINARY_FUNCTION_ADS_ADS(atan2, y, x, 0.4); | ||
CHECK_BINARY_FUNCTION_ADS_ADS(atan2, y, x, -0.4); | ||
} | ||
|
||
TEST_F(StandardOperationsTest, Atan2AdsDouble) { | ||
CHECK_BINARY_FUNCTION_ADS_SCALAR(atan2, x, y, 0.1); | ||
CHECK_BINARY_FUNCTION_ADS_SCALAR(atan2, x, y, -0.1); | ||
CHECK_BINARY_FUNCTION_ADS_SCALAR(atan2, y, x, 0.4); | ||
CHECK_BINARY_FUNCTION_ADS_SCALAR(atan2, y, x, -0.4); | ||
} | ||
|
||
TEST_F(StandardOperationsTest, Atan2DoubleAds) { | ||
CHECK_BINARY_FUNCTION_SCALAR_ADS(atan2, x, y, 0.1); | ||
CHECK_BINARY_FUNCTION_SCALAR_ADS(atan2, x, y, -0.1); | ||
CHECK_BINARY_FUNCTION_SCALAR_ADS(atan2, y, x, 0.4); | ||
CHECK_BINARY_FUNCTION_SCALAR_ADS(atan2, y, x, -0.4); | ||
} | ||
|
||
} // 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 "drake/common/ad/auto_diff.h" | ||
#include "drake/common/ad/test/standard_operations_test.h" | ||
|
||
namespace drake { | ||
namespace test { | ||
namespace { | ||
|
||
// Eigen doesn't provide an atan() overload, so we need to do it. | ||
// This assumes the standard_operations_test.h is implemented using AutoDiff3. | ||
AutoDiff3 atan(const AutoDiff3& x) { | ||
// ∂/∂x atan(x) = 1 / (1 + x²) | ||
return AutoDiff3{ | ||
std::atan(x.value()), | ||
x.derivatives() / (1 + x.value() * x.value())}; | ||
} | ||
|
||
TEST_F(StandardOperationsTest, Atan) { | ||
CHECK_UNARY_FUNCTION(atan, x, y, 0.1); | ||
CHECK_UNARY_FUNCTION(atan, x, y, -0.1); | ||
CHECK_UNARY_FUNCTION(atan, y, x, 0.1); | ||
CHECK_UNARY_FUNCTION(atan, y, x, -0.1); | ||
} | ||
|
||
} // 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, Cos) { | ||
CHECK_UNARY_FUNCTION(cos, x, y, 0.1); | ||
CHECK_UNARY_FUNCTION(cos, x, y, -0.1); | ||
CHECK_UNARY_FUNCTION(cos, y, x, 0.1); | ||
CHECK_UNARY_FUNCTION(cos, y, x, -0.1); | ||
} | ||
|
||
} // 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, Cosh) { | ||
CHECK_UNARY_FUNCTION(cosh, x, y, 0.1); | ||
CHECK_UNARY_FUNCTION(cosh, x, y, -0.1); | ||
CHECK_UNARY_FUNCTION(cosh, y, x, 0.1); | ||
CHECK_UNARY_FUNCTION(cosh, y, x, -0.1); | ||
} | ||
|
||
} // 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, Sin) { | ||
CHECK_UNARY_FUNCTION(sin, x, y, 0.1); | ||
CHECK_UNARY_FUNCTION(sin, x, y, -0.1); | ||
CHECK_UNARY_FUNCTION(sin, y, x, 0.1); | ||
CHECK_UNARY_FUNCTION(sin, y, x, -0.1); | ||
} | ||
|
||
} // 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, Sinh) { | ||
CHECK_UNARY_FUNCTION(sinh, x, y, 0.1); | ||
CHECK_UNARY_FUNCTION(sinh, x, y, -0.1); | ||
CHECK_UNARY_FUNCTION(sinh, y, x, 0.1); | ||
CHECK_UNARY_FUNCTION(sinh, y, x, -0.1); | ||
} | ||
|
||
} // namespace | ||
} // namespace test | ||
} // namespace drake |
Oops, something went wrong.