You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.1 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2013 Christoph Hertzberg <chtz@informatik.uni-bremen.de>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla
  7. // Public License v. 2.0. If a copy of the MPL was not distributed
  8. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. #include "main.h"
  10. #include <unsupported/Eigen/AutoDiff>
  11. /*
  12. * In this file scalar derivations are tested for correctness.
  13. * TODO add more tests!
  14. */
  15. template<typename Scalar> void check_atan2()
  16. {
  17. typedef Matrix<Scalar, 1, 1> Deriv1;
  18. typedef AutoDiffScalar<Deriv1> AD;
  19. AD x(internal::random<Scalar>(-3.0, 3.0), Deriv1::UnitX());
  20. using std::exp;
  21. Scalar r = exp(internal::random<Scalar>(-10, 10));
  22. AD s = sin(x), c = cos(x);
  23. AD res = atan2(r*s, r*c);
  24. VERIFY_IS_APPROX(res.value(), x.value());
  25. VERIFY_IS_APPROX(res.derivatives(), x.derivatives());
  26. }
  27. void test_autodiff_scalar()
  28. {
  29. for(int i = 0; i < g_repeat; i++) {
  30. CALL_SUBTEST_1( check_atan2<float>() );
  31. CALL_SUBTEST_2( check_atan2<double>() );
  32. }
  33. }