11 #include <unsupported/Eigen/AutoDiff> 20 typedef Matrix<Scalar, 1, 1> Deriv1;
21 typedef AutoDiffScalar<Deriv1> AD;
23 AD x(internal::random<Scalar>(-3.0, 3.0), Deriv1::UnitX());
26 Scalar r =
exp(internal::random<Scalar>(-10, 10));
29 AD res =
atan2(r*s, r*c);
31 VERIFY_IS_APPROX(res.value(), x.value());
32 VERIFY_IS_APPROX(res.derivatives(), x.derivatives());
34 res =
atan2(r*s+0, r*c+0);
35 VERIFY_IS_APPROX(res.value(), x.value());
36 VERIFY_IS_APPROX(res.derivatives(), x.derivatives());
44 typedef Matrix<Scalar, 1, 1> Deriv1;
45 typedef AutoDiffScalar<Deriv1> AD;
46 Deriv1 p = Deriv1::Random();
47 AD val(p.x(),Deriv1::UnitX());
51 VERIFY_IS_APPROX(res1.value(),
std::tanh(p.x()));
52 VERIFY_IS_APPROX(res1.derivatives().x(), Scalar(1.0) / (cosh_px * cosh_px));
55 VERIFY_IS_APPROX(res2.value(),
std::sinh(p.x()));
56 VERIFY_IS_APPROX(res2.derivatives().x(), cosh_px);
59 VERIFY_IS_APPROX(res3.value(), cosh_px);
60 VERIFY_IS_APPROX(res3.derivatives().x(),
std::sinh(p.x()));
63 const Scalar sample_point = Scalar(1) / Scalar(3);
64 val = AD(sample_point,Deriv1::UnitX());
66 VERIFY_IS_APPROX(res1.derivatives().x(), Scalar(0.896629559604914));
69 VERIFY_IS_APPROX(res2.derivatives().x(), Scalar(1.056071867829939));
72 VERIFY_IS_APPROX(res3.derivatives().x(), Scalar(0.339540557256150));
75 template <
typename Scalar>
81 typedef std::numeric_limits<AD>
A;
82 typedef std::numeric_limits<Scalar> B;
85 VERIFY(
bool(std::is_base_of<B, A>::value));
91 for(
int i = 0; i < g_repeat; i++) {
92 CALL_SUBTEST_1( check_atan2<float>() );
93 CALL_SUBTEST_2( check_atan2<double>() );
94 CALL_SUBTEST_3( check_hyperbolic_functions<float>() );
95 CALL_SUBTEST_4( check_hyperbolic_functions<double>() );
96 CALL_SUBTEST_5( check_limits_specialization<double>());
A scalar type replacement with automatic differentation capability.
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
void check_hyperbolic_functions()
EIGEN_DEVICE_FUNC const TanhReturnType tanh() const
EIGEN_DEVICE_FUNC const CoshReturnType cosh() const
EIGEN_DEVICE_FUNC const CosReturnType cos() const
EIGEN_DEVICE_FUNC const SinhReturnType sinh() const
void check_limits_specialization()
void test_autodiff_scalar()
const AutoDiffScalar< Matrix< typename internal::traits< typename internal::remove_all< DerTypeA >::type >::Scalar, Dynamic, 1 > > atan2(const AutoDiffScalar< DerTypeA > &a, const AutoDiffScalar< DerTypeB > &b)
EIGEN_DEVICE_FUNC const SinReturnType sin() const
The matrix class, also used for vectors and row-vectors.